wasmsign2/signature/
hash.rs

1use std::io::{self, Write};
2
3#[derive(Clone, Copy)]
4pub(crate) struct Hash {
5    hash: hmac_sha256::Hash,
6}
7
8impl Hash {
9    pub fn new() -> Self {
10        Hash {
11            hash: hmac_sha256::Hash::new(),
12        }
13    }
14
15    pub fn update<T: AsRef<[u8]>>(&mut self, data: T) {
16        self.hash.update(data);
17    }
18
19    pub fn finalize(&self) -> [u8; 32] {
20        self.hash.finalize()
21    }
22}
23
24impl Write for Hash {
25    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
26        self.hash.update(buf);
27        Ok(buf.len())
28    }
29
30    fn flush(&mut self) -> io::Result<()> {
31        Ok(())
32    }
33}