nam_sparse_merkle_tree/
sha256.rs1use crate::{traits::Hasher, H256};
2use core::convert::TryInto;
3use sha2::{Digest, Sha256};
4
5#[derive(Default)]
6pub struct Sha256Hasher(Sha256);
7
8impl Hasher for Sha256Hasher {
9 fn write_bytes(&mut self, h: &[u8]) {
10 self.0.update(h);
11 }
12
13 fn finish(self) -> H256 {
14 let hash = self.0.finalize();
15 let bytes: [u8; 32] = hash
16 .as_slice()
17 .try_into()
18 .expect("Sha256 output conversion to fixed array shouldn't fail");
19 bytes.into()
20 }
21
22 fn hash_op() -> ics23::HashOp {
23 ics23::HashOp::Sha256
24 }
25}