Skip to content

Commit

Permalink
Merge bryant#35
Browse files Browse the repository at this point in the history
  • Loading branch information
FauxFaux committed Oct 21, 2018
2 parents b90d749 + 99a6538 commit 9c1c1b4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/argon2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,20 +324,24 @@ impl Argon2 {
/// Convenience wrapper around Argon2i for the majority of use cases where only
/// a password and salt are supplied. Note that a salt between 8 and 2^32 - 1
/// bytes must be provided.
pub fn argon2i_simple(password: &str, salt: &str) -> [u8; defaults::LENGTH] {
pub fn argon2i_simple<P, S>(password: &P, salt: &S) -> [u8; defaults::LENGTH]
where P: AsRef<[u8]> + ?Sized, S: AsRef<[u8]> + ?Sized
{
let mut out = [0; defaults::LENGTH];
let a2 = Argon2::default(Variant::Argon2i);
a2.hash(&mut out, password.as_bytes(), salt.as_bytes(), &[], &[]);
a2.hash(&mut out, password.as_ref(), salt.as_ref(), &[], &[]);
out
}

/// Convenience wrapper around Argon2d for the majority of use cases where only
/// a password and salt are supplied. Note that a salt between 8 and 2^32 - 1
/// bytes must be provided.
pub fn argon2d_simple(password: &str, salt: &str) -> [u8; defaults::LENGTH] {
pub fn argon2d_simple<P, S>(password: &P, salt: &S) -> [u8; defaults::LENGTH]
where P: AsRef<[u8]> + ?Sized, S: AsRef<[u8]> + ?Sized
{
let mut out = [0; defaults::LENGTH];
let a2 = Argon2::default(Variant::Argon2d);
a2.hash(&mut out, password.as_bytes(), salt.as_bytes(), &[], &[]);
a2.hash(&mut out, password.as_ref(), salt.as_ref(), &[], &[]);
out
}

Expand Down

0 comments on commit 9c1c1b4

Please sign in to comment.