From 9c9ffe70a75d6f5a165a397bc1e4c2918a3ab9d1 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Wed, 15 Nov 2017 23:16:37 +0000 Subject: [PATCH] caps: Do the same fixes, unbreak blake2 and simplify code. --- src/caps.rs | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/src/caps.rs b/src/caps.rs index 27d511c..05f84e1 100644 --- a/src/caps.rs +++ b/src/caps.rs @@ -15,12 +15,11 @@ use error::Error; use ns; use base64; -use digest::Digest; use sha1::Sha1; use sha2::{Sha256, Sha512}; use sha3::{Sha3_256, Sha3_512}; -//use blake2::Blake2b; -//use digest::{Digest, VariableOutput}; +use blake2::Blake2b; +use digest::{Digest, VariableOutput}; #[derive(Debug, Clone)] pub struct Caps { @@ -141,38 +140,25 @@ pub fn hash_caps(data: &[u8], algo: Algo) -> Result { Ok(Hash { hash: match algo { Algo::Sha_1 => { - let mut hasher = Sha1::default(); - hasher.input(data); - let hash = hasher.result(); + let hash = Sha1::digest(data); get_hash_vec(hash.as_slice()) }, Algo::Sha_256 => { - let mut hasher = Sha256::default(); - hasher.input(data); - let hash = hasher.result(); + let hash = Sha256::digest(data); get_hash_vec(hash.as_slice()) }, Algo::Sha_512 => { - let mut hasher = Sha512::default(); - hasher.input(data); - let hash = hasher.result(); + let hash = Sha512::digest(data); get_hash_vec(hash.as_slice()) }, Algo::Sha3_256 => { - let mut hasher = Sha3_256::default(); - hasher.input(data); - let hash = hasher.result(); + let hash = Sha3_256::digest(data); get_hash_vec(hash.as_slice()) }, Algo::Sha3_512 => { - let mut hasher = Sha3_512::default(); - hasher.input(data); - let hash = hasher.result(); + let hash = Sha3_512::digest(data); get_hash_vec(hash.as_slice()) }, - Algo::Blake2b_256 - | Algo::Blake2b_512 => panic!("See https://github.com/RustCrypto/hashes/issues/34"), - /* Algo::Blake2b_256 => { let mut hasher = Blake2b::default(); hasher.input(data); @@ -187,7 +173,6 @@ pub fn hash_caps(data: &[u8], algo: Algo) -> Result { let hash = hasher.variable_result(&mut buf).unwrap(); get_hash_vec(hash) }, - */ Algo::Unknown(algo) => return Err(format!("Unknown algorithm: {}.", algo)), }, algo: algo,