Enum nuts_container::Kdf
source · pub enum Kdf {
None,
Pbkdf2 {
digest: Digest,
iterations: u32,
salt: Vec<u8>,
},
}Expand description
Supported key derivation functions.
Defines data used to calculate a wrapping key.
The wrapping key is created used by an algorithm defined as a variant of this enum. The variants holds fields to customize the algorithm.
Based on a password provided by the user one of the algorithms are used to calculate a wrapping key. The wrapping key then is used for encryption of the secret in the header of the container.
Variants§
Implementations§
source§impl Kdf
impl Kdf
sourcepub fn pbkdf2(digest: Digest, iterations: u32, salt: &[u8]) -> Kdf
pub fn pbkdf2(digest: Digest, iterations: u32, salt: &[u8]) -> Kdf
Creates a Kdf instance for the PBKDF2 algorithm.
The digest, iterations and the salt values are used to customize
the PBKDF2 algorithm.
§Examples
use nuts_container::*;
let pbkdf2 = Kdf::pbkdf2(Digest::Sha1, 5, &[1, 2, 3]);
match pbkdf2 {
Kdf::Pbkdf2 {
digest,
iterations,
salt,
} => {
assert_eq!(digest, Digest::Sha1);
assert_eq!(iterations, 5);
assert_eq!(salt, [1, 2, 3]);
}
_ => panic!("invalid kdf"),
}sourcepub fn generate_pbkdf2(
digest: Digest,
iterations: u32,
salt_len: u32,
) -> Result<Kdf, KdfError>
pub fn generate_pbkdf2( digest: Digest, iterations: u32, salt_len: u32, ) -> Result<Kdf, KdfError>
Generates a Kdf instance for the PBKDF2 algorithm.
The digestand iterations value is used to customize the PBKDF2
algorithm. For the salt salt_len bytes of random data are
generated.
§Errors
This method will return an Error::OpenSSL error if there was an
error generating the random data.
§Examples
use nuts_container::*;
let kdf = Kdf::generate_pbkdf2(Digest::Sha1, 5, 3).unwrap();
match kdf {
Kdf::Pbkdf2 {
digest,
iterations,
salt,
} => {
assert_eq!(digest, Digest::Sha1);
assert_eq!(iterations, 5);
assert_eq!(salt.len(), 3); // salt filled with random data
}
_ => panic!("invalid kdf"),
}Trait Implementations§
impl StructuralPartialEq for Kdf
Auto Trait Implementations§
impl Freeze for Kdf
impl RefUnwindSafe for Kdf
impl Send for Kdf
impl Sync for Kdf
impl Unpin for Kdf
impl UnwindSafe for Kdf
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,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)