Bump RustCrypto crates
This commit is contained in:
parent
5550148149
commit
af1d3c924a
5 changed files with 25 additions and 29 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use getrandom::{getrandom, Error as RngError};
|
||||
use hmac::{crypto_mac::InvalidKeyLength, Hmac, Mac};
|
||||
use hmac::{crypto_mac::InvalidKeyLength, Hmac, Mac, NewMac};
|
||||
use pbkdf2::pbkdf2;
|
||||
use sha1::{Digest, Sha1 as Sha1_hash};
|
||||
use sha2::Sha256 as Sha256_hash;
|
||||
|
|
@ -21,7 +21,7 @@ pub fn generate_nonce() -> Result<String, RngError> {
|
|||
pub enum DeriveError {
|
||||
IncompatibleHashingMethod(String, String),
|
||||
IncorrectSalt,
|
||||
IncompatibleIterationCount(usize, usize),
|
||||
IncompatibleIterationCount(u32, u32),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for DeriveError {
|
||||
|
|
@ -55,7 +55,7 @@ pub trait ScramProvider {
|
|||
fn hmac(data: &[u8], key: &[u8]) -> Result<Vec<u8>, InvalidKeyLength>;
|
||||
|
||||
/// A function which does PBKDF2 key derivation using the hash function.
|
||||
fn derive(data: &Password, salt: &[u8], iterations: usize) -> Result<Vec<u8>, DeriveError>;
|
||||
fn derive(data: &Password, salt: &[u8], iterations: u32) -> Result<Vec<u8>, DeriveError>;
|
||||
}
|
||||
|
||||
/// A `ScramProvider` which provides SCRAM-SHA-1 and SCRAM-SHA-1-PLUS
|
||||
|
|
@ -78,14 +78,14 @@ impl ScramProvider for Sha1 {
|
|||
fn hmac(data: &[u8], key: &[u8]) -> Result<Vec<u8>, InvalidKeyLength> {
|
||||
type HmacSha1 = Hmac<Sha1_hash>;
|
||||
let mut mac = HmacSha1::new_varkey(key)?;
|
||||
mac.input(data);
|
||||
let result = mac.result();
|
||||
mac.update(data);
|
||||
let result = mac.finalize();
|
||||
let mut vec = Vec::with_capacity(Sha1_hash::output_size());
|
||||
vec.extend_from_slice(result.code().as_slice());
|
||||
vec.extend_from_slice(result.into_bytes().as_slice());
|
||||
Ok(vec)
|
||||
}
|
||||
|
||||
fn derive(password: &Password, salt: &[u8], iterations: usize) -> Result<Vec<u8>, DeriveError> {
|
||||
fn derive(password: &Password, salt: &[u8], iterations: u32) -> Result<Vec<u8>, DeriveError> {
|
||||
match *password {
|
||||
Password::Plain(ref plain) => {
|
||||
let mut result = vec![0; 20];
|
||||
|
|
@ -138,14 +138,14 @@ impl ScramProvider for Sha256 {
|
|||
fn hmac(data: &[u8], key: &[u8]) -> Result<Vec<u8>, InvalidKeyLength> {
|
||||
type HmacSha256 = Hmac<Sha256_hash>;
|
||||
let mut mac = HmacSha256::new_varkey(key)?;
|
||||
mac.input(data);
|
||||
let result = mac.result();
|
||||
mac.update(data);
|
||||
let result = mac.finalize();
|
||||
let mut vec = Vec::with_capacity(Sha256_hash::output_size());
|
||||
vec.extend_from_slice(result.code().as_slice());
|
||||
vec.extend_from_slice(result.into_bytes().as_slice());
|
||||
Ok(vec)
|
||||
}
|
||||
|
||||
fn derive(password: &Password, salt: &[u8], iterations: usize) -> Result<Vec<u8>, DeriveError> {
|
||||
fn derive(password: &Password, salt: &[u8], iterations: u32) -> Result<Vec<u8>, DeriveError> {
|
||||
match *password {
|
||||
Password::Plain(ref plain) => {
|
||||
let mut result = vec![0; 32];
|
||||
|
|
|
|||
Loading…
Reference in a new issue