Skip to content

Commit e90f599

Browse files
authored
password-hash: improve PHC PasswordVerifier blanket impl (#2182)
Rather than using the `FromStr` impl to parse the associated `Params` type, it instead bounds on a `TryFrom<phc::ParamsString>` impl, which provides a more explicit PHC-specific params conversion.
1 parent 712bb90 commit e90f599

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

password-hash/src/error.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,6 @@ impl fmt::Display for Error {
6666

6767
impl core::error::Error for Error {}
6868

69-
impl From<core::num::ParseIntError> for Error {
70-
fn from(_: core::num::ParseIntError) -> Error {
71-
Error::EncodingInvalid
72-
}
73-
}
74-
7569
#[cfg(feature = "getrandom")]
7670
impl From<getrandom::Error> for Error {
7771
fn from(_: getrandom::Error) -> Self {

password-hash/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,9 @@ pub trait PasswordVerifier<H: ?Sized> {
166166
}
167167

168168
#[cfg(feature = "phc")]
169-
impl<T: CustomizedPasswordHasher<phc::PasswordHash>, E> PasswordVerifier<phc::PasswordHash> for T
169+
impl<T: CustomizedPasswordHasher<phc::PasswordHash>> PasswordVerifier<phc::PasswordHash> for T
170170
where
171-
T::Params: FromStr<Err = E>,
172-
Error: From<E>,
171+
T::Params: for<'a> TryFrom<&'a phc::ParamsString, Error = Error>,
173172
{
174173
fn verify_password(&self, password: &[u8], hash: &phc::PasswordHash) -> Result<()> {
175174
#[allow(clippy::single_match)]
@@ -180,7 +179,7 @@ where
180179
salt,
181180
Some(hash.algorithm.as_str()),
182181
hash.version,
183-
T::Params::from_str(hash.params.as_str())?,
182+
T::Params::try_from(&hash.params)?,
184183
)?;
185184

186185
if let Some(computed_output) = &computed_hash.hash {

0 commit comments

Comments
 (0)