pub struct BcryptHasher { /* private fields */ }Expand description
A bcrypt password hasher that bundles its own cost parameters.
Implements PasswordHash so it can be
used polymorphically with the crate’s verify_password function.
§Design note — salt requirement
bcrypt requires exactly 16 bytes of salt. The PasswordHash::hash_password
method writes raw hash bytes (23 bytes); for the full $2b$ string, use
bcrypt_hash instead.
Implementations§
Source§impl BcryptHasher
impl BcryptHasher
Sourcepub fn new(params: BcryptParams) -> Self
pub fn new(params: BcryptParams) -> Self
Create a new hasher with explicit parameters.
Sourcepub fn with_cost(cost: u32) -> Result<Self, CryptoError>
pub fn with_cost(cost: u32) -> Result<Self, CryptoError>
Create a new hasher with the given cost factor.
§Errors
Returns CryptoError::BadInput if cost is out of range [4, 31].
Sourcepub fn params(&self) -> &BcryptParams
pub fn params(&self) -> &BcryptParams
Return a reference to the current parameters.
Trait Implementations§
Source§impl Clone for BcryptHasher
impl Clone for BcryptHasher
Source§fn clone(&self) -> BcryptHasher
fn clone(&self) -> BcryptHasher
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BcryptHasher
impl Debug for BcryptHasher
Source§impl PasswordHash for BcryptHasher
impl PasswordHash for BcryptHasher
Source§fn hash_password(
&self,
password: &[u8],
salt: &[u8],
_params: &dyn PasswordHashParams,
out: &mut [u8],
) -> Result<(), CryptoError>
fn hash_password( &self, password: &[u8], salt: &[u8], _params: &dyn PasswordHashParams, out: &mut [u8], ) -> Result<(), CryptoError>
Hash
password with salt using the given params; write output into out.Auto Trait Implementations§
impl Freeze for BcryptHasher
impl RefUnwindSafe for BcryptHasher
impl Send for BcryptHasher
impl Sync for BcryptHasher
impl Unpin for BcryptHasher
impl UnsafeUnpin for BcryptHasher
impl UnwindSafe for BcryptHasher
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
Mutably borrows from an owned value. Read more