Skip to main content

SimpleHasher

Trait SimpleHasher 

pub trait SimpleHasher: Sized {
    // Required methods
    fn new() -> Self;
    fn update(&mut self, data: &[u8]);
    fn finalize(self) -> [u8; 32];

    // Provided method
    fn hash(data: impl AsRef<[u8]>) -> [u8; 32] { ... }
}
Expand description

A minimal trait representing a hash function. We implement our own rather than relying on Digest for broader compatibility.

Required Methods§

fn new() -> Self

Creates a new hasher with default state.

fn update(&mut self, data: &[u8])

Ingests the provided data, updating the hasher’s state.

fn finalize(self) -> [u8; 32]

Consumes the hasher state to produce a digest.

Provided Methods§

fn hash(data: impl AsRef<[u8]>) -> [u8; 32]

Returns the digest of the provided data.

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.

Implementors§

§

impl SimpleHasher for TransparentHasher

§

impl<T> SimpleHasher for T
where T: Digest, [u8; 32]: From<GenericArray<u8, <T as OutputSizeUser>::OutputSize>>,