diff options
Diffstat (limited to 'src/hasher.rs')
| -rw-r--r-- | src/hasher.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/hasher.rs b/src/hasher.rs index 898393f..a26dd3c 100644 --- a/src/hasher.rs +++ b/src/hasher.rs @@ -1,10 +1,19 @@ +//! Provides hashing abstractions and implementations including SHA256 and a default dummy hasher. + #[cfg(feature = "sha256")] use sha2::{Digest, Sha256}; +/// A trait representing a generic hash function. +/// +/// This allows the Merkle tree to use any hash function that conforms to this interface. pub trait Hasher { + /// Hashes an input string and returns the resulting hash as a hexadecimal string. fn hash(&self, input: &str) -> String; } +/// A dummy hasher used for testing or demonstration purposes. +/// +/// Always returns a static hash value. pub struct DefaultHasher; impl Hasher for DefaultHasher { @@ -14,6 +23,7 @@ impl Hasher for DefaultHasher { } #[cfg(feature = "sha256")] +/// A hasher implementation using the SHA-256 cryptographic hash function. pub struct SHA256Hasher; #[cfg(feature = "sha256")] @@ -34,9 +44,7 @@ mod tests { let hasher = SHA256Hasher; let input = "hello"; let expected_hash = "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"; - let actual_hash = hasher.hash(input); - assert_eq!(actual_hash, expected_hash); } @@ -45,9 +53,7 @@ mod tests { let hasher = SHA256Hasher; let input = ""; let expected_hash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; - let actual_hash = hasher.hash(input); - assert_eq!(actual_hash, expected_hash); } } |
