pub trait PasswordHasher<H> {
// Required method
fn hash_password_with_salt(&self, password: &[u8], salt: &[u8]) -> Result<H>;
// Provided methods
fn hash_password(&self, password: &[u8]) -> Result<H> { ... }
fn hash_password_with_rng<R: TryCryptoRng + ?Sized>(
&self,
rng: &mut R,
password: &[u8],
) -> Result<H> { ... }
}Expand description
High-level trait for password hashing functions.
Generic around a password hash to be returned (typically phc::PasswordHash)
Required Methods§
Sourcefn hash_password_with_salt(&self, password: &[u8], salt: &[u8]) -> Result<H>
fn hash_password_with_salt(&self, password: &[u8], salt: &[u8]) -> Result<H>
Compute the hash H from the given password and salt, potentially using configuration
stored in &self for the parameters, or otherwise the recommended defaults.
The salt should be unique per password. When in doubt, use PasswordHasher::hash_password
which will choose the salt for you.
§Errors
These will vary by algorithm/implementation of this trait, but may be due to:
- length restrictions on the password and/or salt
- algorithm-specific internal error
Provided Methods§
Sourcefn hash_password(&self, password: &[u8]) -> Result<H>
Available on crate feature getrandom only.
fn hash_password(&self, password: &[u8]) -> Result<H>
getrandom only.Compute the hash H from the given password, potentially using configuration stored in
&self for the parameters, or otherwise the recommended defaults.
A large random salt will be generated automatically.
§Errors
These will vary by algorithm/implementation of this trait, but may be due to:
- length restrictions on the password
- algorithm-specific internal error
- RNG internal error
Sourcefn hash_password_with_rng<R: TryCryptoRng + ?Sized>(
&self,
rng: &mut R,
password: &[u8],
) -> Result<H>
Available on crate feature rand_core only.
fn hash_password_with_rng<R: TryCryptoRng + ?Sized>( &self, rng: &mut R, password: &[u8], ) -> Result<H>
rand_core only.Compute the hash H from the given password, potentially using configuration stored in
&self for the parameters, or otherwise the recommended defaults.
A large random salt will be generated automatically from the provided RNG.
§Errors
These will vary by algorithm/implementation of this trait, but may be due to:
- length restrictions on the password
- algorithm-specific internal error
- RNG internal error
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.