saa_common/
identity.rs

1use digest::{
2    FixedOutput, HashMarker, Output, OutputSizeUser, Reset, Update,
3    consts::U32, generic_array::GenericArray,
4};
5
6#[derive(Clone, Default)]
7pub struct Identity256 {
8    array: GenericArray<u8, U32>,
9}
10
11impl Update for Identity256 {
12    fn update(&mut self, hash: &[u8]) {
13        assert_eq!(hash.as_ref().len(), 32);
14        self.array = *GenericArray::from_slice(hash);
15    }
16}
17impl OutputSizeUser for Identity256 {
18    type OutputSize = U32;
19}
20
21impl FixedOutput for Identity256 {
22    fn finalize_into(self, out: &mut Output<Self>) {
23        *out = self.array;
24    }
25}
26
27impl HashMarker for Identity256 {}
28
29impl Reset for Identity256 {
30    fn reset(&mut self) {
31        *self = Self::default();
32    }
33}
34