pakery_core/crypto/hash.rs
1//! Hash function trait.
2
3use alloc::vec::Vec;
4
5/// A cryptographic hash function.
6pub trait Hash: Sized + Clone {
7 /// Output size in bytes (e.g. 32 for SHA-256, 64 for SHA-512).
8 const OUTPUT_SIZE: usize;
9
10 /// Create a new hasher.
11 fn new() -> Self;
12
13 /// Feed data into the hasher.
14 fn update(&mut self, data: &[u8]);
15
16 /// Finalize and return the hash digest.
17 fn finalize(self) -> Vec<u8>;
18
19 /// One-shot: hash data and return the digest.
20 fn digest(data: &[u8]) -> Vec<u8> {
21 let mut h = Self::new();
22 h.update(data);
23 h.finalize()
24 }
25}