Skip to main content

Digest

Trait Digest 

Source
pub trait Digest:
    Algorithm
    + Clone
    + Default {
    type Output: AsRef<[u8]> + AsMut<[u8]> + Copy;

    const OUTPUT_LEN: usize;
    const BLOCK_LEN: usize;

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

    // Provided method
    fn digest(data: &[u8]) -> Result<Self::Output> { ... }
}
Expand description

A cryptographic hash function with a fixed-length output.

Producing output can fail: Digest::finalize and Digest::digest refuse with ErrorKind::ModuleErrorState once the module is in its error state, and, in a build with --cfg ic_approved_only, before ic_fips::initialize has passed the self-tests. Making a hasher and absorbing input produce nothing, and do not refuse.

Implemented for every type that implements [internal::Digest], which is how the hash functions are written.

Required Associated Constants§

Source

const OUTPUT_LEN: usize

Output length in bytes.

Source

const BLOCK_LEN: usize

Internal block (rate) length in bytes — required by HMAC and KMAC.

Required Associated Types§

Source

type Output: AsRef<[u8]> + AsMut<[u8]> + Copy

The fixed-size output buffer type, e.g. [u8; 32].

Required Methods§

Source

fn new() -> Self

Create a fresh, empty hasher.

Source

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

Absorb more input. May be called any number of times.

Source

fn finalize(self) -> Result<Self::Output>

Consume the hasher and produce the digest.

Provided Methods§

Source

fn digest(data: &[u8]) -> Result<Self::Output>

One-shot convenience: hash data in a single call.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: Digest> Digest for T

Source§

const OUTPUT_LEN: usize = <T as internal::Digest>::OUTPUT_LEN

Source§

const BLOCK_LEN: usize = <T as internal::Digest>::BLOCK_LEN

Source§

type Output = <T as Digest>::Output