Simplify code in HashUtils.

This commit is contained in:
Romain Ruetschi
2016-12-02 16:48:30 +01:00
parent a1968efbfc
commit 5baca83454

View File

@ -1,5 +1,5 @@
use ring::digest::{ Algorithm, Context };
use ring::digest::{ Algorithm, digest };
/// The sole purpose of this trait is to extend the standard
/// `ring::algo::Algorithm` type with a couple utility functions.
@ -15,16 +15,12 @@ pub trait HashUtils {
impl HashUtils for Algorithm {
fn hash_bytes(&'static self, bytes: &[u8]) -> Vec<u8> {
let mut context = Context::new(self);
context.update(bytes);
context.finish().as_ref().into()
digest(self, bytes).as_ref().into()
}
fn combine_hashes(&'static self, left: &[u8], right: &[u8]) -> Vec<u8> {
let mut context = Context::new(self);
let combined = [left, right].concat();
context.update(&combined);
context.finish().as_ref().into()
digest(self, &combined).as_ref().into()
}
}