PasswordHashFunction

Trait PasswordHashFunction 

Source
pub trait PasswordHashFunction: KeyDerivationFunction + ParamProvider {
    type Password: AsRef<[u8]> + AsMut<[u8]> + Clone + Zeroize;

    // Required methods
    fn hash_password(&self, password: &Self::Password) -> Result<PasswordHash>;
    fn verify(
        &self,
        password: &Self::Password,
        hash: &PasswordHash,
    ) -> Result<bool>;
    fn benchmark(&self) -> Duration;
    fn recommended_params(target_duration: Duration) -> Self::Params;
}
Expand description

Trait for password hashing functions with type-level guarantees

Required Associated Types§

Source

type Password: AsRef<[u8]> + AsMut<[u8]> + Clone + Zeroize

Password type with zeroizing

Required Methods§

Source

fn hash_password(&self, password: &Self::Password) -> Result<PasswordHash>

Hashes a password with the configured parameters

Source

fn verify(&self, password: &Self::Password, hash: &PasswordHash) -> Result<bool>

Verifies a password against a hash

Source

fn benchmark(&self) -> Duration

Benchmarks the current parameters on this system

Source

fn recommended_params(target_duration: Duration) -> Self::Params

Recommends parameters based on a target duration

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<H: HashFunction + Clone, const S: usize> PasswordHashFunction for Pbkdf2<H, S>

Available on crate feature std only.
Source§

impl<const S: usize> PasswordHashFunction for Argon2<S>
where Salt<S>: Argon2Compatible + Clone + Zeroize + Send + Sync + 'static, Params<S>: Default + Clone + Zeroize + Send + Sync + 'static,