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
password-hash: add version param to PasswordHasher
This makes the `hash_password` method reflect all of the potential
parameters to a `PasswordHash`.
  • Loading branch information
tarcieri committed Aug 27, 2021
commit 1d55175b6ccb91e92ab08466c367e52a80348709
5 changes: 4 additions & 1 deletion password-hash/src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Trait definitions.

use crate::{Error, Ident, ParamsString, PasswordHash, Result, Salt};
use crate::{Decimal, Error, Ident, ParamsString, PasswordHash, Result, Salt};
use core::{
convert::{TryFrom, TryInto},
fmt::Debug,
Expand All @@ -26,6 +26,7 @@ pub trait PasswordHasher {
self.hash_password(
password,
None,
None,
Self::Params::default(),
Salt::try_from(salt.as_ref())?,
)
Expand All @@ -38,6 +39,7 @@ pub trait PasswordHasher {
&self,
password: &[u8],
algorithm: Option<Ident<'a>>,
version: Option<Decimal>,
params: Self::Params,
salt: impl Into<Salt<'a>>,
) -> Result<PasswordHash<'a>>;
Expand All @@ -63,6 +65,7 @@ impl<T: PasswordHasher> PasswordVerifier for T {
let computed_hash = self.hash_password(
password,
Some(hash.algorithm),
hash.version,
T::Params::try_from(&hash)?,
*salt,
)?;
Expand Down
3 changes: 2 additions & 1 deletion password-hash/tests/hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ impl PasswordHasher for StubPasswordHasher {
&self,
password: &[u8],
algorithm: Option<Ident<'a>>,
version: Option<Decimal>,
params: StubParams,
salt: impl Into<Salt<'a>>,
) -> Result<PasswordHash<'a>> {
Expand All @@ -37,7 +38,7 @@ impl PasswordHasher for StubPasswordHasher {

Ok(PasswordHash {
algorithm: ALG,
version: None,
version,
params: params.try_into()?,
salt: Some(salt),
hash: Some(hash),
Expand Down