Trait digest::Digest[][src]

pub trait Digest: Input + BlockInput + FixedOutput + Default {
    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> { ... }
fn digest_reader(
        source: &mut Read
    ) -> Result<GenericArray<u8, Self::OutputSize>> { ... } }

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

Create new hasher instance

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

Retrieve the digest result. This method consumes digest instance.

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

Example:

This example is not tested
println!("{:x}", sha2::Sha256::digest(b"Hello world"));

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

Convenience function which takes std::io::Read as a source and computes value of digest function D, e.g. SHA-2, SHA-3, BLAKE2, etc. using 1 KB blocks.

Usage example:

This example is not tested
use std::fs;
use sha2::{Sha256, Digest};

let mut file = fs::File::open("Cargo.toml")?;
let result = Sha256::digest_reader(&mut file)?;
println!("{:x}", result);

Implementors