pub trait Hasher:
Clone
+ Send
+ Sync
+ 'static {
// Required methods
fn new() -> Self;
fn update(&mut self, message: &[u8]);
fn finalize(&mut self) -> Digest;
fn reset(&mut self);
fn validate(digest: &Digest) -> bool;
fn len() -> usize;
fn random<R: Rng + CryptoRng>(rng: &mut R) -> Digest;
}
Expand description
Interface that commonware crates rely on for hashing.
Hash functions in commonware primitives are not typically hardcoded to a specific algorithm (e.g. SHA-256) because different hash functions may work better with different cryptographic schemes, may be more efficient to use in STARK/SNARK proofs, or provide different levels of security (with some performance/size penalty).
This trait is required to implement the Clone
trait because it is often
part of a struct that is cloned. In practice, implementations do not actually
clone the hasher state but users should not rely on this behavior and call reset
after cloning.
Required Methods§
Sourcefn finalize(&mut self) -> Digest
fn finalize(&mut self) -> Digest
Hash all recorded data and reset the hasher to the initial state.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.