audit_trail/hashers/
blake3.rs1use crate::hash::{Digest, HASH_LEN, Hasher};
5
6#[derive(Clone, Default)]
24pub struct Blake3Hasher(blake3::Hasher);
25
26impl Blake3Hasher {
27 #[inline]
29 pub fn new() -> Self {
30 Self(blake3::Hasher::new())
31 }
32}
33
34impl core::fmt::Debug for Blake3Hasher {
35 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
36 f.debug_struct("Blake3Hasher").finish_non_exhaustive()
37 }
38}
39
40impl Hasher for Blake3Hasher {
41 #[inline]
42 fn reset(&mut self) {
43 let _ = self.0.reset();
44 }
45
46 #[inline]
47 fn update(&mut self, bytes: &[u8]) {
48 let _ = self.0.update(bytes);
49 }
50
51 #[inline]
52 fn finalize(&mut self, out: &mut Digest) {
53 let hash = self.0.finalize();
54 let bytes: [u8; HASH_LEN] = *hash.as_bytes();
55 *out = Digest::from_bytes(bytes);
56 }
57}