pub trait KeyDeriver: Send + Sync {
// Required method
fn derive_with_salt(
&self,
password: &[u8],
salt: &[u8],
) -> Result<MasterKey, KdfError>;
// Provided method
fn derive(
&self,
password: &[u8],
salt: &PHashSalt,
) -> Result<MasterKey, KdfError> { ... }
}Expand description
Stretching of a password into a master key.
The trait exists so that tests can substitute a cheap deriver for the
production one without the layers above knowing which is in use. It is
Send + Sync because the pipeline may hold a deriver behind a shared
reference while worker threads are running.
Required Methods§
Sourcefn derive_with_salt(
&self,
password: &[u8],
salt: &[u8],
) -> Result<MasterKey, KdfError>
fn derive_with_salt( &self, password: &[u8], salt: &[u8], ) -> Result<MasterKey, KdfError>
Derives a master key from password and an arbitrary salt.
The general form, and the only one an implementor has to write. Most of
this crate salts with the container’s perceptual hash and reaches for
KeyDeriver::derive instead; the exception is the passphrase that
protects a private key file, where there is no container and the salt is
read from the file.
§Errors
Returns KdfError::EmptyPassword if password has no bytes, and
KdfError::Argon2Error if the underlying implementation fails.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".