1.1--- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2+++ b/rust/lib/hash/src/tests.rs Tue Oct 17 20:36:37 2023 -0400
1.3@@ -0,0 +1,21 @@
1.4+use crate::{Hasher, OutputReader};
1.5+use hex::decode;
1.6+use std::convert::TryInto;
1.7+
1.8+#[test]
1.9+fn hex_hash() -> Result<(), Box<dyn std::error::Error>> {
1.10+ let mut hasher1 = crate::Hasher::new();
1.11+ hasher1.update(b"foo");
1.12+ hasher1.update(b"bar");
1.13+ hasher1.update(b"baz");
1.14+ let out1 = hasher1.finalize();
1.15+ let mut xof1 = [0; 301];
1.16+ hasher1.finalize_xof().fill(&mut xof1);
1.17+ assert_eq!(out1.as_bytes(), &xof1[..32]);
1.18+
1.19+ let hash_hex = "d74981efa70a0c880b8d8c1985d075dbcbf679b99a5f9914e5aaf96b831a9e24";
1.20+ let hash_bytes = decode(hash_hex).unwrap();
1.21+ let hash_array: [u8; blake3::OUT_LEN] = hash_bytes[..].try_into().unwrap();
1.22+ let hash: blake3::Hash = hash_array.into();
1.23+ Ok(())
1.24+}