summaryrefslogtreecommitdiffstats
path: root/vendor/twox-hash/src/digest_0_10_support.rs
blob: 935c0969235faa84b8ddc9125140faa5081f6d8e (plain)
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
88
89
90
91
92
use core::hash::Hasher;

use digest_0_10::{
    generic_array::typenum::consts::{U16, U4, U8},
    FixedOutput, HashMarker, Output, OutputSizeUser, Update,
};

use crate::{xxh3, XxHash32, XxHash64};

// ----------

impl Update for XxHash32 {
    fn update(&mut self, data: &[u8]) {
        self.write(data);
    }
}

impl OutputSizeUser for XxHash32 {
    type OutputSize = U4;
}

impl FixedOutput for XxHash32 {
    fn finalize_into(self, out: &mut Output<Self>) {
        let tmp: &mut [u8; 4] = out.as_mut();
        *tmp = self.finish().to_be_bytes();
    }
}

impl HashMarker for XxHash32 {}

// ----------

impl Update for XxHash64 {
    fn update(&mut self, data: &[u8]) {
        self.write(data);
    }
}

impl OutputSizeUser for XxHash64 {
    type OutputSize = U8;
}

impl FixedOutput for XxHash64 {
    fn finalize_into(self, out: &mut Output<Self>) {
        let tmp: &mut [u8; 8] = out.as_mut();
        *tmp = self.finish().to_be_bytes();
    }
}

impl HashMarker for XxHash64 {}

// ----------

impl Update for xxh3::Hash64 {
    fn update(&mut self, data: &[u8]) {
        self.write(data);
    }
}

impl OutputSizeUser for xxh3::Hash64 {
    type OutputSize = U8;
}

impl FixedOutput for xxh3::Hash64 {
    fn finalize_into(self, out: &mut Output<Self>) {
        let tmp: &mut [u8; 8] = out.as_mut();
        *tmp = self.finish().to_be_bytes();
    }
}

impl HashMarker for xxh3::Hash64 {}

// ----------

impl Update for xxh3::Hash128 {
    fn update(&mut self, data: &[u8]) {
        self.write(data);
    }
}

impl OutputSizeUser for xxh3::Hash128 {
    type OutputSize = U16;
}

impl FixedOutput for xxh3::Hash128 {
    fn finalize_into(self, out: &mut Output<Self>) {
        let tmp: &mut [u8; 16] = out.as_mut();
        *tmp = xxh3::HasherExt::finish_ext(&self).to_be_bytes();
    }
}

impl HashMarker for xxh3::Hash128 {}