add md5, minor changes to trait

This commit is contained in:
2025-07-12 17:29:51 -04:00
parent 33119c8ec6
commit eb9c6f9475
3 changed files with 9 additions and 9 deletions

View File

@@ -25,4 +25,7 @@ pub struct Args {
/// Blake2b256
#[arg(long)]
pub blake256: bool,
/// MD5
#[arg(long)]
pub md5: bool,
}

View File

@@ -2,6 +2,7 @@ mod null_hash;
use crate::Args;
use md5::digest;
use std::sync::Arc;
type BITS256 = [u8; 32];
@@ -46,12 +47,8 @@ impl HashReturn {
pub trait Hasher {
fn new() -> Self;
fn digest(&mut self, bytes: ArcU8);
fn digest(&mut self, bytes: impl AsRef<[u8]>);
fn complete(self) -> HashReturn;
}
struct HashKeeper {}
pub struct Hashes {
hashes: Args,
}
pub struct Hashes {}

View File

@@ -22,7 +22,7 @@ impl Hasher for NullHash {
fn new() -> Self {
NullHash { hash: [0; 32] }
}
fn digest(&mut self, bytes: ArcU8) {
fn digest(&mut self, bytes: impl AsRef<[u8]>) {
let bytes = bytes.as_ref();
let start_point = if bytes.len() < 32 {
@@ -50,7 +50,7 @@ mod test {
let mut hasher = NullHash::new();
for i in 0..32u8 {
hasher.digest(Arc::new([i; 1]));
hasher.digest([i; 1]);
}
assert_eq!(*hasher.complete().into_bytes().first().unwrap(), 31);
@@ -66,7 +66,7 @@ mod test {
*byte = i;
}
hasher.digest(Arc::new(source_bytes));
hasher.digest(source_bytes);
let result = hasher.complete().into_bytes();