#[inline]
pub fn hash_hex(data: &[u8]) -> String {
blake3::hash(data).to_hex().to_string()
}
#[inline]
pub fn hash_str(s: &str) -> String {
hash_hex(s.as_bytes())
}
#[inline]
pub fn hash_short(s: &str) -> String {
let full = blake3::hash(s.as_bytes()).to_hex();
full[..16].to_string()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn deterministic() {
let a = hash_hex(b"hello");
let b = hash_hex(b"hello");
assert_eq!(a, b);
assert_eq!(a.len(), 64);
}
#[test]
fn short_hash_length() {
let s = hash_short("test");
assert_eq!(s.len(), 16);
}
#[test]
fn different_inputs_differ() {
assert_ne!(hash_str("foo"), hash_str("bar"));
}
}