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
use digest::typenum::U32;
use digest::{Digest, FixedOutput, FixedOutputReset, OutputSizeUser, Reset, Update};

/// A [`digest::Digest`] implementation which always returns the digest
/// `[0;32]`.
pub struct NoOpHasher;

impl OutputSizeUser for NoOpHasher {
    type OutputSize = U32;
}

impl Update for NoOpHasher {
    fn update(&mut self, _data: &[u8]) {}
}

impl Reset for NoOpHasher {
    fn reset(&mut self) {}
}

impl FixedOutput for NoOpHasher {
    fn finalize_into(self, out: &mut digest::Output<Self>) {
        *out = [0u8; 32].into();
    }
}

impl FixedOutputReset for NoOpHasher {
    fn finalize_into_reset(&mut self, out: &mut digest::Output<Self>) {
        *out = [0u8; 32].into();
    }
}

impl Digest for NoOpHasher {
    fn new() -> Self {
        Self
    }

    fn new_with_prefix(_data: impl AsRef<[u8]>) -> Self {
        Self
    }

    fn update(&mut self, _data: impl AsRef<[u8]>) {}

    fn chain_update(self, _data: impl AsRef<[u8]>) -> Self {
        Self
    }

    fn finalize(self) -> digest::Output<Self> {
        [0u8; 32].into()
    }

    fn finalize_into(self, out: &mut digest::Output<Self>) {
        <Self as FixedOutput>::finalize_into(self, out)
    }

    fn finalize_reset(&mut self) -> digest::Output<Self>
    where
        Self: digest::FixedOutputReset,
    {
        [0u8; 32].into()
    }

    fn finalize_into_reset(&mut self, out: &mut digest::Output<Self>)
    where
        Self: digest::FixedOutputReset,
    {
        <Self as FixedOutputReset>::finalize_into_reset(self, out)
    }

    fn reset(&mut self)
    where
        Self: digest::Reset,
    {
        <Self as Reset>::reset(self)
    }

    fn output_size() -> usize {
        32
    }

    fn digest(_data: impl AsRef<[u8]>) -> digest::Output<Self> {
        [0u8; 32].into()
    }
}