Trait Digest

Source
pub trait Digest {
    type OutputSize: ArrayLength<u8>;

    // Required methods
    fn new() -> Self;
    fn input<B>(&mut self, data: B)
       where B: AsRef<[u8]>;
    fn chain<B>(self, data: B) -> Self
       where B: AsRef<[u8]>,
             Self: Sized;
    fn result(self) -> GenericArray<u8, Self::OutputSize>;
    fn result_reset(&mut self) -> GenericArray<u8, Self::OutputSize>;
    fn reset(&mut self);
    fn output_size() -> usize;
    fn digest(data: &[u8]) -> GenericArray<u8, Self::OutputSize>;
}
Expand description

The Digest trait specifies an interface common for digest functions.

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

Required Associated Types§

Required Methods§

Source

fn new() -> Self

Create new hasher instance

Source

fn input<B>(&mut self, data: B)
where B: AsRef<[u8]>,

Digest input data.

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

Source

fn chain<B>(self, data: B) -> Self
where B: AsRef<[u8]>, Self: Sized,

Digest input data in a chained manner.

Source

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

Retrieve result and consume hasher instance.

Source

fn result_reset(&mut self) -> GenericArray<u8, Self::OutputSize>

Retrieve result and reset hasher instance.

This method sometimes can be more efficient compared to hasher re-creation.

Source

fn reset(&mut self)

Reset hasher instance to its initial state.

Source

fn output_size() -> usize

Get output size of the hasher

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"));

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§