ecaps2: Use the digest() facility to simplify hashing.

This commit is contained in:
Emmanuel Gil Peyrot 2017-11-15 23:15:12 +00:00
parent c1ff291c11
commit 702c4d2932

View file

@ -120,27 +120,19 @@ pub fn hash_ecaps2(data: &[u8], algo: Algo) -> Result<Hash, String> {
Ok(Hash { Ok(Hash {
hash: match algo { hash: match algo {
Algo::Sha_256 => { Algo::Sha_256 => {
let mut hasher = Sha256::default(); let hash = Sha256::digest(data);
hasher.input(data);
let hash = hasher.result();
get_hash_vec(hash.as_slice()) get_hash_vec(hash.as_slice())
}, },
Algo::Sha_512 => { Algo::Sha_512 => {
let mut hasher = Sha512::default(); let hash = Sha512::digest(data);
hasher.input(data);
let hash = hasher.result();
get_hash_vec(hash.as_slice()) get_hash_vec(hash.as_slice())
}, },
Algo::Sha3_256 => { Algo::Sha3_256 => {
let mut hasher = Sha3_256::default(); let hash = Sha3_256::digest(data);
hasher.input(data);
let hash = hasher.result();
get_hash_vec(hash.as_slice()) get_hash_vec(hash.as_slice())
}, },
Algo::Sha3_512 => { Algo::Sha3_512 => {
let mut hasher = Sha3_512::default(); let hash = Sha3_512::digest(data);
hasher.input(data);
let hash = hasher.result();
get_hash_vec(hash.as_slice()) get_hash_vec(hash.as_slice())
}, },
Algo::Blake2b_256 => { Algo::Blake2b_256 => {