twox_hash/
digest_0_10_support.rs1use core::hash::Hasher;
2
3use digest_0_10::{
4 generic_array::typenum::consts::{U16, U4, U8},
5 FixedOutput, HashMarker, Output, OutputSizeUser, Update,
6};
7
8use crate::{xxh3, XxHash32, XxHash64};
9
10impl Update for XxHash32 {
13 fn update(&mut self, data: &[u8]) {
14 self.write(data);
15 }
16}
17
18impl OutputSizeUser for XxHash32 {
19 type OutputSize = U4;
20}
21
22impl FixedOutput for XxHash32 {
23 fn finalize_into(self, out: &mut Output<Self>) {
24 let tmp: &mut [u8; 4] = out.as_mut();
25 *tmp = self.finish().to_be_bytes();
26 }
27}
28
29impl HashMarker for XxHash32 {}
30
31impl Update for XxHash64 {
34 fn update(&mut self, data: &[u8]) {
35 self.write(data);
36 }
37}
38
39impl OutputSizeUser for XxHash64 {
40 type OutputSize = U8;
41}
42
43impl FixedOutput for XxHash64 {
44 fn finalize_into(self, out: &mut Output<Self>) {
45 let tmp: &mut [u8; 8] = out.as_mut();
46 *tmp = self.finish().to_be_bytes();
47 }
48}
49
50impl HashMarker for XxHash64 {}
51
52impl Update for xxh3::Hash64 {
55 fn update(&mut self, data: &[u8]) {
56 self.write(data);
57 }
58}
59
60impl OutputSizeUser for xxh3::Hash64 {
61 type OutputSize = U8;
62}
63
64impl FixedOutput for xxh3::Hash64 {
65 fn finalize_into(self, out: &mut Output<Self>) {
66 let tmp: &mut [u8; 8] = out.as_mut();
67 *tmp = self.finish().to_be_bytes();
68 }
69}
70
71impl HashMarker for xxh3::Hash64 {}
72
73impl Update for xxh3::Hash128 {
76 fn update(&mut self, data: &[u8]) {
77 self.write(data);
78 }
79}
80
81impl OutputSizeUser for xxh3::Hash128 {
82 type OutputSize = U16;
83}
84
85impl FixedOutput for xxh3::Hash128 {
86 fn finalize_into(self, out: &mut Output<Self>) {
87 let tmp: &mut [u8; 16] = out.as_mut();
88 *tmp = xxh3::HasherExt::finish_ext(&self).to_be_bytes();
89 }
90}
91
92impl HashMarker for xxh3::Hash128 {}