use sha2::{Digest, Sha256};
pub fn sha256_hex(bytes: &[u8]) -> String {
let result = Sha256::digest(bytes);
hex::encode(result)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn empty_hash_is_expected() {
let hash = sha256_hex(b"");
assert_eq!(
hash,
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
);
}
#[test]
fn hash_is_deterministic() {
let h1 = sha256_hex(b"hello world");
let h2 = sha256_hex(b"hello world");
assert_eq!(h1, h2);
assert_eq!(h1.len(), 64);
}
}