-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
password-auth: add
is_hash_obsolete
(#428)
Adds a method for interrogating whether a given password hash is using the recommended algorithm and parameters. This can be used by password hash upgrade systems to determine whether a particular hash should be upgraded/recomputed. It additionally adds a `ParseError` type which wraps `password_hash::Error`. This is only used by `is_hash_obsolete` for now but it might be good for future versions to use this error type to capture parse errors in `verify_password`. However, that would be a breaking change, which is avoided for now.
- Loading branch information
Showing
3 changed files
with
82 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//! Error types. | ||
|
||
use core::fmt; | ||
|
||
/// Password hash parse errors. | ||
#[derive(Clone, Copy, Debug)] | ||
pub struct ParseError(password_hash::Error); | ||
|
||
impl ParseError { | ||
/// Create a new parse error. | ||
pub(crate) fn new(err: password_hash::Error) -> Self { | ||
Self(err) | ||
} | ||
} | ||
|
||
impl fmt::Display for ParseError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "{}", &self.0) | ||
} | ||
} | ||
|
||
#[cfg(feature = "std")] | ||
impl std::error::Error for ParseError {} | ||
|
||
/// Password hash verification errors. | ||
#[derive(Clone, Copy, Debug)] | ||
pub struct VerifyError; | ||
|
||
impl fmt::Display for VerifyError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.write_str("password verification error") | ||
} | ||
} | ||
|
||
#[cfg(feature = "std")] | ||
impl std::error::Error for VerifyError {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters