diff options
Diffstat (limited to 'src/hasher.rs')
| -rw-r--r-- | src/hasher.rs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/hasher.rs b/src/hasher.rs index 028e73a..898393f 100644 --- a/src/hasher.rs +++ b/src/hasher.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "sha256")] use sha2::{Digest, Sha256}; pub trait Hasher { @@ -7,6 +8,16 @@ pub trait Hasher { pub struct DefaultHasher; impl Hasher for DefaultHasher { + fn hash(&self, _input: &str) -> String { + "0xc0ff3".to_string() + } +} + +#[cfg(feature = "sha256")] +pub struct SHA256Hasher; + +#[cfg(feature = "sha256")] +impl Hasher for SHA256Hasher { fn hash(&self, input: &str) -> String { let mut hasher = Sha256::new(); hasher.update(input.as_bytes()); @@ -14,13 +25,13 @@ impl Hasher for DefaultHasher { } } -#[cfg(test)] +#[cfg(all(test, feature = "sha256"))] mod tests { use super::*; #[test] - fn test_default_hasher_with_known_input() { - let hasher = DefaultHasher; + fn test_sha256_hasher_with_known_input() { + let hasher = SHA256Hasher; let input = "hello"; let expected_hash = "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"; @@ -30,8 +41,8 @@ mod tests { } #[test] - fn test_default_hasher_empty_string() { - let hasher = DefaultHasher; + fn test_sha256_hasher_empty_string() { + let hasher = SHA256Hasher; let input = ""; let expected_hash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; |
