Skip to main content

Hasher

Trait Hasher 

Source
pub trait Hasher {
    const OUTPUT_LEN: usize;
    const BLOCK_LEN: usize;

    // Required methods
    fn new() -> Self;
    fn update(&mut self, data: &[u8]);
    fn finalize(self) -> Vec<u8> ;
    fn finalize_into(self, out: &mut [u8]);

    // Provided method
    fn hash(data: &[u8]) -> Vec<u8> 
       where Self: Sized { ... }
}
Expand description

Trait for hash functions (fixed-output).

Required Associated Constants§

Source

const OUTPUT_LEN: usize

Output size in bytes.

Source

const BLOCK_LEN: usize

Block size in bytes (for HMAC computation).

Required Methods§

Source

fn new() -> Self

Create a new hasher instance.

Source

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

Feed data into the hasher (can be called multiple times).

Source

fn finalize(self) -> Vec<u8>

Finalize and return the digest. Consumes the hasher.

Source

fn finalize_into(self, out: &mut [u8])

Finalize into a caller-provided buffer (no allocation).

Provided Methods§

Source

fn hash(data: &[u8]) -> Vec<u8>
where Self: Sized,

One-shot: hash data and return the digest.

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§