diff options
| author | Santo Cariotti <santo@dcariotti.me> | 2025-06-16 14:36:40 +0000 |
|---|---|---|
| committer | Santo Cariotti <santo@dcariotti.me> | 2025-06-16 14:36:40 +0000 |
| commit | bd88ce87928d31d0e569e82eaf760c32aa88dd38 (patch) | |
| tree | da2741385b3a7dd55be059fe0d7749229e1562f3 /src | |
| parent | c97f558c45b4f40b352cb6a0edf3aa9f4b0474f2 (diff) | |
Remove feature
Diffstat (limited to 'src')
| -rw-r--r-- | src/hasher.rs | 77 | ||||
| -rw-r--r-- | src/merkletree.rs | 3 | ||||
| -rw-r--r-- | src/proof.rs | 1 |
3 files changed, 38 insertions, 43 deletions
diff --git a/src/hasher.rs b/src/hasher.rs index d27a7e5..088b16a 100644 --- a/src/hasher.rs +++ b/src/hasher.rs @@ -1,5 +1,7 @@ //! Provides hashing abstractions and implementations including SHA256 and a default dummy hasher. +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. @@ -21,52 +23,49 @@ impl Hasher for DummyHasher { } } -#[cfg(feature = "sha256")] -mod hasher_sha256 { - use super::*; - use sha2::{Digest, Sha256}; +#[derive(Clone)] +/// A hasher implementation using the SHA-256 cryptographic hash function. +pub struct SHA256Hasher; - #[derive(Clone)] - /// A hasher implementation using the SHA-256 cryptographic hash function. - pub struct SHA256Hasher; +impl Default for SHA256Hasher { + fn default() -> Self { + Self::new() + } +} - impl SHA256Hasher { - pub fn new() -> Self { - Self {} - } +impl SHA256Hasher { + pub fn new() -> Self { + Self {} } +} - impl Hasher for SHA256Hasher { - fn hash(&self, input: &[u8]) -> String { - let mut hasher = Sha256::new(); - hasher.update(input); - hex::encode(hasher.finalize()) - } +impl Hasher for SHA256Hasher { + fn hash(&self, input: &[u8]) -> String { + let mut hasher = Sha256::new(); + hasher.update(input); + hex::encode(hasher.finalize()) } +} - #[cfg(test)] - mod tests { - use super::*; +#[cfg(test)] +mod tests { + use super::*; - #[test] - fn test_sha256_hasher_with_known_input() { - let hasher = SHA256Hasher; - let input = "hello".as_bytes(); - let expected_hash = "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"; - let actual_hash = hasher.hash(input); - assert_eq!(actual_hash, expected_hash); - } + #[test] + fn test_sha256_hasher_with_known_input() { + let hasher = SHA256Hasher; + let input = "hello".as_bytes(); + let expected_hash = "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"; + let actual_hash = hasher.hash(input); + assert_eq!(actual_hash, expected_hash); + } - #[test] - fn test_sha256_hasher_empty_string() { - let hasher = SHA256Hasher; - let input = &[]; - let expected_hash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; - let actual_hash = hasher.hash(input); - assert_eq!(actual_hash, expected_hash); - } + #[test] + fn test_sha256_hasher_empty_string() { + let hasher = SHA256Hasher; + let input = &[]; + let expected_hash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; + let actual_hash = hasher.hash(input); + assert_eq!(actual_hash, expected_hash); } } - -#[cfg(feature = "sha256")] -pub use hasher_sha256::*; diff --git a/src/merkletree.rs b/src/merkletree.rs index 0d5186b..84d59d2 100644 --- a/src/merkletree.rs +++ b/src/merkletree.rs @@ -137,7 +137,6 @@ mod tests { } #[test] - #[cfg(feature = "sha256")] fn test_merkle_tree_hashing() { let data = &["hello".as_bytes(), "world".as_bytes()]; let tree = MerkleTree::new(SHA256Hasher::new(), data); @@ -150,7 +149,6 @@ mod tests { } #[test] - #[cfg(feature = "sha256")] fn test_merkle_tree_single_leaf() { let data = &["hello".as_bytes()]; let tree = MerkleTree::new(SHA256Hasher::new(), data); @@ -164,7 +162,6 @@ mod tests { } #[test] - #[cfg(feature = "sha256")] fn test_merkle_tree_with_10_elements() { let inputs = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; let data: Vec<&[u8]> = inputs.iter().map(|s| s.as_bytes()).collect(); diff --git a/src/proof.rs b/src/proof.rs index d2d1c0f..10eb825 100644 --- a/src/proof.rs +++ b/src/proof.rs @@ -167,7 +167,6 @@ mod tests { } #[test] - #[cfg(feature = "sha256")] fn test_proof_generation_and_verification_sha256() { let hasher = SHA256Hasher::new(); let data = vec!["a", "b", "c", "d"]; |
