working sha1
This commit is contained in:
@@ -1,20 +1,28 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
use ::sha1::digest::core_api::CoreWrapper;
|
||||||
|
use ::sha1::{Digest, Sha1, Sha1Core};
|
||||||
|
|
||||||
pub struct SHA1 {
|
pub struct SHA1 {
|
||||||
hash: BITS160,
|
hash: BITS160,
|
||||||
|
hasher: CoreWrapper<Sha1Core>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hasher for SHA1 {
|
impl Hasher for SHA1 {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
SHA1 { hash: [0; 20] }
|
SHA1 {
|
||||||
|
hash: [0; 20],
|
||||||
|
hasher: Sha1::new(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn digest(&mut self, bytes: impl AsRef<[u8]>) {
|
fn digest(&mut self, bytes: impl AsRef<[u8]>) {
|
||||||
todo!()
|
self.hasher.update(bytes.as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete(self) -> HashReturn {
|
fn complete(mut self) -> HashReturn {
|
||||||
todo!()
|
let res = self.hasher.finalize();
|
||||||
|
self.hash.copy_from_slice(&res);
|
||||||
|
HashReturn::SHA1(self.hash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,6 +32,17 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_sha1_hash() {
|
fn test_sha1_hash() {
|
||||||
todo!();
|
let input = "HelloWorld";
|
||||||
|
let expected_output = "db8ac1c259eb89d4a131b253bacfca5f319d54f2";
|
||||||
|
|
||||||
|
let mut sha1 = SHA1::new();
|
||||||
|
|
||||||
|
sha1.digest(input);
|
||||||
|
|
||||||
|
let result = sha1.complete().into_bytes();
|
||||||
|
|
||||||
|
let hash_out = crate::hex_table::u8_array_to_lower_hex_string(&result).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(hash_out, expected_output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user