1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#![doc(html_root_url = "https://docs.rs/toad-hash/0.1.0")]
#![cfg_attr(any(docsrs, feature = "docs"), feature(doc_cfg))]
#![allow(clippy::unused_unit)]
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
#![deny(missing_copy_implementations)]
#![cfg_attr(not(test), deny(unsafe_code))]
#![cfg_attr(not(test), warn(unreachable_pub))]
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "alloc")]
extern crate alloc as std_alloc;
use core::fmt::Debug;
use core::hash::Hasher;
use blake2::digest::typenum::U8;
use blake2::{Blake2b, Digest};
#[derive(Default, Clone)]
pub struct Blake2Hasher(Blake2b<U8>);
impl Blake2Hasher {
pub fn new() -> Self {
Self::default()
}
}
impl Debug for Blake2Hasher {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_tuple("Blake2Hasher")
.field(&"<Blake2bCore<U8>>")
.finish()
}
}
impl Hasher for Blake2Hasher {
fn finish(&self) -> u64 {
u64::from_be_bytes(self.0.clone().finalize().into())
}
fn write(&mut self, bytes: &[u8]) {
self.0.update(bytes);
}
}