Skip to content

Commit f4e582e

Browse files
Make sure HashingAlgorithm#salt_and_hash base64-encoded the result
1 parent da18d15 commit f4e582e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/password_hashing.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn salt() -> Vec<u8> {
2929
Vec::from(&buf)
3030
}
3131

32-
/// Produces a SHA-256 hashed, salted passowrd hash.
32+
/// Produces a SHA-256 hashed, salted password hash.
3333
/// Prefer [`base64_encoded_salted_password_hash_sha256`].
3434
///
3535
/// See the [Credentials and Passwords guide](https://rabbitmq.com/docs/passwords/).
@@ -110,10 +110,12 @@ pub enum HashingError {
110110

111111
impl HashingAlgorithm {
112112
pub fn salt_and_hash(&self, salt: &[u8], password: &str) -> Result<Vec<u8>, HashingError> {
113-
match self {
114-
HashingAlgorithm::SHA256 => Ok(salted_password_hash_sha256(salt, password)),
115-
HashingAlgorithm::SHA512 => Ok(salted_password_hash_sha512(salt, password)),
116-
}
113+
let hash = match self {
114+
HashingAlgorithm::SHA256 => salted_password_hash_sha256(salt, password),
115+
HashingAlgorithm::SHA512 => salted_password_hash_sha512(salt, password),
116+
};
117+
let encoded = rbase64::encode(hash.as_slice());
118+
Ok(encoded.as_bytes().to_vec())
117119
}
118120
}
119121

0 commit comments

Comments
 (0)