From 9dca1906176c7ad45b81a7d32ec46256d3817ed0 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sat, 6 Dec 2025 20:25:25 -0700 Subject: [PATCH] Add generic `H` param to traits Companion PR to RustCrypto/traits#2110 --- Cargo.lock | 2 +- README.md | 6 +++--- argon2/src/lib.rs | 4 ++-- balloon-hash/src/lib.rs | 4 ++-- password-auth/src/lib.rs | 2 +- pbkdf2/src/simple.rs | 4 ++-- scrypt/src/simple.rs | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cd95fe1c..9577ac6a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -305,7 +305,7 @@ dependencies = [ [[package]] name = "password-hash" version = "0.6.0-rc.2" -source = "git+https://github.com/RustCrypto/traits#cc1362e87192a0ae9649e6fadf1bce37e8b21c98" +source = "git+https://github.com/RustCrypto/traits#9c5a7f6b3c7dddfe1360c0245fb188697fe9e084" dependencies = [ "base64ct", "getrandom", diff --git a/README.md b/README.md index ec09593b..42fb8f58 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ The following code example shows how to verify a password when stored using one of many possible password hashing algorithms implemented in this repository. ```rust -use password_hash::{PasswordHash, PasswordVerifier}; +use password_hash::{phc, PasswordVerifier}; use argon2::Argon2; use pbkdf2::Pbkdf2; @@ -35,10 +35,10 @@ use scrypt::Scrypt; let hash_string = "$argon2i$v=19$m=65536,t=1,p=1$c29tZXNhbHQAAAAAAAAAAA$+r0d29hqEB0yasKr55ZgICsQGSkl0v0kgwhd+U3wyRo"; let input_password = "password"; -let password_hash = PasswordHash::new(&hash_string).expect("invalid password hash"); +let password_hash = phc::PasswordHash::new(&hash_string).expect("invalid password hash"); // Trait objects for algorithms to support -let algs: &[&dyn PasswordVerifier] = &[&Argon2::default(), &Pbkdf2, &Scrypt]; +let algs: &[&dyn PasswordVerifier] = &[&Argon2::default(), &Pbkdf2, &Scrypt]; password_hash.verify_password(algs, input_password).expect("invalid password"); ``` diff --git a/argon2/src/lib.rs b/argon2/src/lib.rs index 39a6aeb7..1493bd28 100644 --- a/argon2/src/lib.rs +++ b/argon2/src/lib.rs @@ -620,7 +620,7 @@ impl<'key> Argon2<'key> { } #[cfg(all(feature = "alloc", feature = "password-hash"))] -impl CustomizedPasswordHasher for Argon2<'_> { +impl CustomizedPasswordHasher for Argon2<'_> { type Params = Params; fn hash_password_customized( @@ -654,7 +654,7 @@ impl CustomizedPasswordHasher for Argon2<'_> { } #[cfg(all(feature = "alloc", feature = "password-hash"))] -impl PasswordHasher for Argon2<'_> { +impl PasswordHasher for Argon2<'_> { fn hash_password(&self, password: &[u8], salt: &[u8]) -> password_hash::Result { let salt = Salt::new(salt)?; diff --git a/balloon-hash/src/lib.rs b/balloon-hash/src/lib.rs index 09e335fd..8762d2f2 100644 --- a/balloon-hash/src/lib.rs +++ b/balloon-hash/src/lib.rs @@ -212,7 +212,7 @@ where } #[cfg(all(feature = "alloc", feature = "password-hash"))] -impl CustomizedPasswordHasher for Balloon<'_, D> +impl CustomizedPasswordHasher for Balloon<'_, D> where D: Digest + FixedOutputReset, Array: ArrayDecoding, @@ -243,7 +243,7 @@ where } #[cfg(all(feature = "alloc", feature = "password-hash"))] -impl PasswordHasher for Balloon<'_, D> +impl PasswordHasher for Balloon<'_, D> where D: Digest + FixedOutputReset, Array: ArrayDecoding, diff --git a/password-auth/src/lib.rs b/password-auth/src/lib.rs index 99282485..cf87ae1f 100644 --- a/password-auth/src/lib.rs +++ b/password-auth/src/lib.rs @@ -80,7 +80,7 @@ fn generate_phc_hash(password: &[u8], salt: &[u8]) -> password_hash::Result, hash: &str) -> Result<(), VerifyError> { let hash = PasswordHash::new(hash).map_err(ParseError::new)?; - let algs: &[&dyn PasswordVerifier] = &[ + let algs: &[&dyn PasswordVerifier] = &[ #[cfg(feature = "argon2")] &Argon2::default(), #[cfg(feature = "pbkdf2")] diff --git a/pbkdf2/src/simple.rs b/pbkdf2/src/simple.rs index 64e0e201..e1d89921 100644 --- a/pbkdf2/src/simple.rs +++ b/pbkdf2/src/simple.rs @@ -20,7 +20,7 @@ use sha1::Sha1; #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct Pbkdf2; -impl CustomizedPasswordHasher for Pbkdf2 { +impl CustomizedPasswordHasher for Pbkdf2 { type Params = Params; fn hash_password_customized( @@ -65,7 +65,7 @@ impl CustomizedPasswordHasher for Pbkdf2 { } } -impl PasswordHasher for Pbkdf2 { +impl PasswordHasher for Pbkdf2 { fn hash_password(&self, password: &[u8], salt: &[u8]) -> Result { self.hash_password_customized(password, salt, None, None, Params::default()) } diff --git a/scrypt/src/simple.rs b/scrypt/src/simple.rs index 18337b4f..8fd7291c 100644 --- a/scrypt/src/simple.rs +++ b/scrypt/src/simple.rs @@ -19,7 +19,7 @@ pub const ALG_ID: Ident = Ident::new_unwrap(ALG_NAME); #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct Scrypt; -impl CustomizedPasswordHasher for Scrypt { +impl CustomizedPasswordHasher for Scrypt { type Params = Params; fn hash_password_customized( @@ -68,7 +68,7 @@ impl CustomizedPasswordHasher for Scrypt { } } -impl PasswordHasher for Scrypt { +impl PasswordHasher for Scrypt { fn hash_password(&self, password: &[u8], salt: &[u8]) -> Result { self.hash_password_customized(password, salt, None, None, Params::default()) }