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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions password-hash/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub enum Error {
/// Encoding errors (e.g. Base64).
EncodingInvalid,

/// Internal error within a password hashing library.
Internal,

/// Out of memory (heap allocation failure).
OutOfMemory,

Expand Down Expand Up @@ -49,6 +52,7 @@ impl fmt::Display for Error {
Self::Algorithm => write!(f, "unsupported algorithm"),
Self::Crypto => write!(f, "cryptographic error"),
Self::EncodingInvalid => write!(f, "invalid encoding"),
Self::Internal => write!(f, "internal password hashing algorithm error"),
Self::OutOfMemory => write!(f, "out of memory"),
Self::OutputSize => write!(f, "password hash output size invalid"),
Self::ParamInvalid { name } => write!(f, "invalid parameter: {name:?}"),
Expand Down
8 changes: 6 additions & 2 deletions password-hash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub trait PasswordHasher<H> {
/// Generic around a password hash to be returned (typically [`PasswordHash`])
pub trait CustomizedPasswordHasher<H> {
/// Algorithm-specific parameters.
type Params: Clone + Debug + Default + Display + FromStr<Err = Error>;
type Params: Clone + Debug + Default + Display + FromStr;

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

#[cfg(feature = "phc")]
impl<T: CustomizedPasswordHasher<phc::PasswordHash>> PasswordVerifier<phc::PasswordHash> for T {
impl<T: CustomizedPasswordHasher<phc::PasswordHash>, E> PasswordVerifier<phc::PasswordHash> for T
where
T::Params: FromStr<Err = E>,
Error: From<E>,
{
fn verify_password(&self, password: &[u8], hash: &phc::PasswordHash) -> Result<()> {
#[allow(clippy::single_match)]
match (&hash.salt, &hash.hash) {
Expand Down