Trait Digest

Source
pub trait Digest:
    Input
    + BlockInput
    + FixedOutput
    + Default {
    // Provided methods
    fn new() -> Self { ... }
    fn input(&mut self, input: &[u8]) { ... }
    fn result(self) -> GenericArray<u8, Self::OutputSize> { ... }
    fn digest(data: &[u8]) -> GenericArray<u8, Self::OutputSize> { ... }
    fn digest_str(str: &str) -> GenericArray<u8, Self::OutputSize> { ... }
}
Expand description

The Digest trait specifies an interface common for digest functions.

It’s a convinience wrapper around Input, FixedOutput, BlockInput and Default traits. It also provides additional convenience methods.

Provided Methods§

Source

fn new() -> Self

Create new hasher instance

Source

fn input(&mut self, input: &[u8])

Digest input data. This method can be called repeatedly for use with streaming messages.

Source

fn result(self) -> GenericArray<u8, Self::OutputSize>

Retrieve the digest result. This method consumes digest instance.

Source

fn digest(data: &[u8]) -> GenericArray<u8, Self::OutputSize>

Convenience function to compute hash of the data. It will handle hasher creation, data feeding and finalization.

Example:

println!("{:x}", sha2::Sha256::digest(b"Hello world"));
Source

fn digest_str(str: &str) -> GenericArray<u8, Self::OutputSize>

Convenience function to compute hash of the string. It’s equivalent to digest(input_string.as_bytes()).

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§

Source§

impl<D> Digest for D