diff --git a/sasl/Cargo.toml b/sasl/Cargo.toml index 225e9f7d..8fc9bfc5 100644 --- a/sasl/Cargo.toml +++ b/sasl/Cargo.toml @@ -20,6 +20,8 @@ scram = ["openssl"] [dependencies] base64 = "0.10" +sha-1 = "0.8" +sha2 = "0.8" [dependencies.openssl] version = "0.10.7" diff --git a/sasl/src/common/scram.rs b/sasl/src/common/scram.rs index 94d8bd62..e087fb39 100644 --- a/sasl/src/common/scram.rs +++ b/sasl/src/common/scram.rs @@ -1,10 +1,11 @@ use openssl::pkcs5::pbkdf2_hmac; -use openssl::hash::hash; use openssl::hash::MessageDigest; use openssl::sign::Signer; use openssl::pkey::PKey; use openssl::rand::rand_bytes; use openssl::error::ErrorStack; +use sha1::{Sha1 as Sha1_hash, Digest}; +use sha2::Sha256 as Sha256_hash; use crate::common::Password; @@ -46,7 +47,10 @@ impl ScramProvider for Sha1 { // TODO: look at all these unwraps fn name() -> &'static str { "SHA-1" } fn hash(data: &[u8]) -> Vec { - hash(MessageDigest::sha1(), data).unwrap().to_vec() + let hash = Sha1_hash::digest(data); + let mut vec = Vec::with_capacity(Sha1_hash::output_size()); + vec.extend_from_slice(hash.as_slice()); + vec } fn hmac(data: &[u8], key: &[u8]) -> Vec { @@ -90,7 +94,10 @@ impl ScramProvider for Sha256 { // TODO: look at all these unwraps fn name() -> &'static str { "SHA-256" } fn hash(data: &[u8]) -> Vec { - hash(MessageDigest::sha256(), data).unwrap().to_vec() + let hash = Sha256_hash::digest(data); + let mut vec = Vec::with_capacity(Sha256_hash::output_size()); + vec.extend_from_slice(hash.as_slice()); + vec } fn hmac(data: &[u8], key: &[u8]) -> Vec {