mirror of
https://github.com/mii443/merkle.rs.git
synced 2025-08-22 16:05:30 +00:00
Simplify code in HashUtils.
This commit is contained in:
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user