pub struct SecretKey(/* private fields */);
Expand description
Symmetric encryption/decryption secret key.
Note: this implementation tries to prevent certain types of attacks by making sure the
underlying sensitive key material is always stored at most in one place. This is achieved by
putting it on the heap which means it is not moved when the key itself is moved which could
otherwise leave a copy of the data in memory. Additionally, the data is behind a Arc
which
means the key can be cheaply cloned without actually cloning the data. Finally, the data is
scrambled (overwritten with zeros) when the key is dropped to make sure it does not stay in
the memory past its lifetime.
Implementations§
Source§impl SecretKey
impl SecretKey
Sourcepub fn parse_hex(hex_str: &str) -> Result<Self, FromHexError>
pub fn parse_hex(hex_str: &str) -> Result<Self, FromHexError>
Parse secret key from hexadecimal string of size 2*SIZE.
Sourcepub fn generate<R: Rng + CryptoRng + ?Sized>(rng: &mut R) -> Self
pub fn generate<R: Rng + CryptoRng + ?Sized>(rng: &mut R) -> Self
Generate a random secret key using the given cryptographically secure random number generator.
Note: this is purposefully not implemented as impl Distribution<SecretKey> for Standard
to enforce the additional CryptoRng
bound.
Sourcepub fn derive_from_key(master_key: &[u8; 32], nonce: &[u8]) -> Self
pub fn derive_from_key(master_key: &[u8; 32], nonce: &[u8]) -> Self
Derive a secret key from another secret key and a nonce.
pub fn random_salt() -> PasswordSalt
Sourcepub fn derive_from_password(user_password: &str, salt: &PasswordSalt) -> Self
pub fn derive_from_password(user_password: &str, salt: &PasswordSalt) -> Self
Derive a secret key from user’s password and salt.
Trait Implementations§
Source§impl AsRef<[u8]> for SecretKey
impl AsRef<[u8]> for SecretKey
Note this trait is somewhat dangerous because if used carelessly the underlying sensitive data can be copied or revealed.
Source§impl<'de> Deserialize<'de> for SecretKey
impl<'de> Deserialize<'de> for SecretKey
Source§fn deserialize<D>(d: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(d: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl PartialEq for SecretKey
impl PartialEq for SecretKey
Note this impl uses constant-time operations (using subtle) and so provides protection against software side-channel attacks.
impl Eq for SecretKey
Auto Trait Implementations§
impl Freeze for SecretKey
impl RefUnwindSafe for SecretKey
impl Send for SecretKey
impl Sync for SecretKey
impl Unpin for SecretKey
impl UnwindSafe for SecretKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Lower case
letters are used (e.g. f9b4ca
)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Upper case
letters are used (e.g. F9B4CA
)