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
use crate::Reset;
use generic_array::{ArrayLength, GenericArray};
pub trait FixedOutput {
type OutputSize: ArrayLength<u8>;
fn finalize_into(self, out: &mut GenericArray<u8, Self::OutputSize>);
fn finalize_into_reset(&mut self, out: &mut GenericArray<u8, Self::OutputSize>);
#[inline]
fn finalize_fixed(self) -> GenericArray<u8, Self::OutputSize>
where
Self: Sized,
{
let mut out = Default::default();
self.finalize_into(&mut out);
out
}
#[inline]
fn finalize_fixed_reset(&mut self) -> GenericArray<u8, Self::OutputSize> {
let mut out = Default::default();
self.finalize_into_reset(&mut out);
out
}
}
pub trait FixedOutputDirty {
type OutputSize: ArrayLength<u8>;
fn finalize_into_dirty(&mut self, out: &mut GenericArray<u8, Self::OutputSize>);
}
impl<D: FixedOutputDirty + Reset> FixedOutput for D {
type OutputSize = D::OutputSize;
#[inline]
fn finalize_into(mut self, out: &mut GenericArray<u8, Self::OutputSize>) {
self.finalize_into_dirty(out);
}
#[inline]
fn finalize_into_reset(&mut self, out: &mut GenericArray<u8, Self::OutputSize>) {
self.finalize_into_dirty(out);
self.reset();
}
}