Skip to content

Commit

Permalink
Version 1.6.6: No changes, just applied clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Racum committed Apr 22, 2023
1 parent 8b8813b commit 282f346
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 23 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [1.6.6] - 2023-04-22

### Changed

- No changes, just applied clippy fixes.

## [1.6.5] - 2023-04-03

### Changed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "djangohashers"
version = "1.6.5"
version = "1.6.6"
authors = ["Ronaldo Racum <[email protected]>"]
documentation = "https://docs.rs/djangohashers/"
license = "BSD-3-Clause"
Expand Down
16 changes: 8 additions & 8 deletions src/crypto_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ pub fn hash_pbkdf2_sha256(password: &str, salt: &str, iterations: u32) -> String
use core::num::NonZeroU32;
ring::pbkdf2::derive(
ring::pbkdf2::PBKDF2_HMAC_SHA256,
NonZeroU32::new(iterations as u32).unwrap(),
&salt.as_bytes(),
NonZeroU32::new(iterations).unwrap(),
salt.as_bytes(),
password.as_bytes(),
&mut result,
);
general_purpose::STANDARD.encode(&result)
general_purpose::STANDARD.encode(result)
}

#[cfg(feature = "with_pbkdf2")]
Expand All @@ -60,12 +60,12 @@ pub fn hash_pbkdf2_sha1(password: &str, salt: &str, iterations: u32) -> String {
use core::num::NonZeroU32;
ring::pbkdf2::derive(
ring::pbkdf2::PBKDF2_HMAC_SHA1,
NonZeroU32::new(iterations as u32).unwrap(),
&salt.as_bytes(),
NonZeroU32::new(iterations).unwrap(),
salt.as_bytes(),
password.as_bytes(),
&mut result,
);
general_purpose::STANDARD.encode(&result)
general_purpose::STANDARD.encode(result)
}

#[cfg(feature = "with_pbkdf2")]
Expand Down Expand Up @@ -138,7 +138,7 @@ pub fn hash_argon2(
};
let salt_bytes = general_purpose::URL_SAFE_NO_PAD.decode(salt).unwrap();
let result = argon2::hash_raw(password.as_bytes(), &salt_bytes, &config).unwrap();
general_purpose::URL_SAFE_NO_PAD.encode(&result)
general_purpose::URL_SAFE_NO_PAD.encode(result)
}

#[cfg(feature = "with_scrypt")]
Expand All @@ -156,5 +156,5 @@ pub fn hash_scrypt(
let mut buf = [0u8; KEY_SIZE];
let params = Params::new(work_factor, block_size, parallelism, KEY_SIZE).unwrap();
scrypt(password.as_bytes(), salt.as_bytes(), &params, &mut buf).unwrap();
general_purpose::STANDARD.encode(&buf)
general_purpose::STANDARD.encode(buf)
}
4 changes: 2 additions & 2 deletions src/hashers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,12 @@ impl Hasher for BCryptSHA256Hasher {
}
let hash = bcrypt_encoded_part[1];
let hashed_password = crypto_utils::hash_sha256(password);
Ok(bcrypt::verify(&hashed_password, hash).unwrap_or(false))
Ok(bcrypt::verify(hashed_password, hash).unwrap_or(false))
}

fn encode(&self, password: &str, _: &str, iterations: u32) -> String {
let hashed_password = crypto_utils::hash_sha256(password);
let hash = bcrypt::hash(&hashed_password, iterations).unwrap();
let hash = bcrypt::hash(hashed_password, iterations).unwrap();
format!("{}${}", "bcrypt_sha256", hash)
}
}
Expand Down
12 changes: 6 additions & 6 deletions tests/django19.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ fn test_bcrypt() {
fn test_unusable() {
let encoded = "!Q24gQu9Sy3X1PJPCaEMTRrw5eLFWY8htI2FsqCbC"; // From make_password(None)
assert!(encoded.len() == 41);
assert!(!is_password_usable(&encoded));
assert!(check_password(&encoded, &encoded).is_err());
assert!(check_password("!", &encoded).is_err());
assert!(check_password("", &encoded).is_err());
assert!(check_password("lètmein", &encoded).is_err());
assert!(check_password("lètmeinz", &encoded).is_err());
assert!(!is_password_usable(encoded));
assert!(check_password(encoded, encoded).is_err());
assert!(check_password("!", encoded).is_err());
assert!(check_password("", encoded).is_err());
assert!(check_password("lètmein", encoded).is_err());
assert!(check_password("lètmeinz", encoded).is_err());
}

// Scenario not possible during run time:
Expand Down
8 changes: 4 additions & 4 deletions tests/django32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ fn test_argon2() {
assert_eq!(check_password(" ", &blank_encoded), Ok(false));
// Old hashes without version attribute
let encoded = "argon2$argon2i$m=8,t=1,p=1$c29tZXNhbHQ$gwQOXSNhxiOxPOA0+PY10P9QFO4NAYysnqRt1GSQLE55m+2GYDt9FEjPMHhP2Cuf0nOEXXMocVrsJAtNSsKyfg";
assert_eq!(check_password("secret", &encoded), Ok(true));
assert_eq!(check_password("wrong", &encoded), Ok(false));
assert_eq!(check_password("secret", encoded), Ok(true));
assert_eq!(check_password("wrong", encoded), Ok(false));
// Old hashes with version attribute.
let encoded = "argon2$argon2i$v=19$m=8,t=1,p=1$c2FsdHNhbHQ$YC9+jJCrQhs5R6db7LlN8Q";
assert_eq!(check_password("secret", &encoded), Ok(true));
assert_eq!(check_password("wrong", &encoded), Ok(false));
assert_eq!(check_password("secret", encoded), Ok(true));
assert_eq!(check_password("wrong", encoded), Ok(false));
}
4 changes: 2 additions & 2 deletions tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use djangohashers::*;

static PASSWORD: &'static str = "ExjGmyUT73bFoT";
static SALT: &'static str = "KQ8zeK6wKRuR";
static PASSWORD: &str = "ExjGmyUT73bFoT";
static SALT: &str = "KQ8zeK6wKRuR";

#[test]
#[cfg(feature = "with_pbkdf2")]
Expand Down

0 comments on commit 282f346

Please sign in to comment.