WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 8bb7b93

Browse files
authored
password-hash: relax FromStr error bounds (#2120)
Changes the bound on `CustomizedPasswordHasher::Params` to remove the `Err = Error` bound on `FromStr`. Instead, the blanket impl of `PasswordVerifier` has been updated to require `Error: From<E>` where `E` is `FromStr::Err`. This allows crates to still use custom error types for params, which may be more expressive for a specific algorithm.
1 parent e7b9861 commit 8bb7b93

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

password-hash/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ pub enum Error {
1818
/// Encoding errors (e.g. Base64).
1919
EncodingInvalid,
2020

21+
/// Internal error within a password hashing library.
22+
Internal,
23+
2124
/// Out of memory (heap allocation failure).
2225
OutOfMemory,
2326

@@ -49,6 +52,7 @@ impl fmt::Display for Error {
4952
Self::Algorithm => write!(f, "unsupported algorithm"),
5053
Self::Crypto => write!(f, "cryptographic error"),
5154
Self::EncodingInvalid => write!(f, "invalid encoding"),
55+
Self::Internal => write!(f, "internal password hashing algorithm error"),
5256
Self::OutOfMemory => write!(f, "out of memory"),
5357
Self::OutputSize => write!(f, "password hash output size invalid"),
5458
Self::ParamInvalid { name } => write!(f, "invalid parameter: {name:?}"),

password-hash/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub trait PasswordHasher<H> {
7777
/// Generic around a password hash to be returned (typically [`PasswordHash`])
7878
pub trait CustomizedPasswordHasher<H> {
7979
/// Algorithm-specific parameters.
80-
type Params: Clone + Debug + Default + Display + FromStr<Err = Error>;
80+
type Params: Clone + Debug + Default + Display + FromStr;
8181

8282
/// Compute a [`PasswordHash`] from the provided password using an
8383
/// explicit set of customized algorithm parameters as opposed to the
@@ -110,7 +110,11 @@ pub trait PasswordVerifier<H> {
110110
}
111111

112112
#[cfg(feature = "phc")]
113-
impl<T: CustomizedPasswordHasher<phc::PasswordHash>> PasswordVerifier<phc::PasswordHash> for T {
113+
impl<T: CustomizedPasswordHasher<phc::PasswordHash>, E> PasswordVerifier<phc::PasswordHash> for T
114+
where
115+
T::Params: FromStr<Err = E>,
116+
Error: From<E>,
117+
{
114118
fn verify_password(&self, password: &[u8], hash: &phc::PasswordHash) -> Result<()> {
115119
#[allow(clippy::single_match)]
116120
match (&hash.salt, &hash.hash) {

0 commit comments

Comments
 (0)