1#[inline]
9pub fn hash_hex(data: &[u8]) -> String {
10 blake3::hash(data).to_hex().to_string()
11}
12
13#[inline]
15pub fn hash_str(s: &str) -> String {
16 hash_hex(s.as_bytes())
17}
18
19#[inline]
21pub fn hash_short(s: &str) -> String {
22 let full = blake3::hash(s.as_bytes()).to_hex();
23 full[..16].to_string()
24}
25
26#[cfg(test)]
27mod tests {
28 use super::*;
29
30 #[test]
31 fn deterministic() {
32 let a = hash_hex(b"hello");
33 let b = hash_hex(b"hello");
34 assert_eq!(a, b);
35 assert_eq!(a.len(), 64);
36 }
37
38 #[test]
39 fn short_hash_length() {
40 let s = hash_short("test");
41 assert_eq!(s.len(), 16);
42 }
43
44 #[test]
45 fn different_inputs_differ() {
46 assert_ne!(hash_str("foo"), hash_str("bar"));
47 }
48}