Trait HashEngine

Source
pub trait HashEngine: Clone + Default {
    type Digest: Copy + Clone + PartialEq + Eq + PartialOrd + Ord + Hash + AsRef<[u8]>;
    type Midstate;

    const BLOCK_SIZE: usize;

    // Required methods
    fn input(&mut self, data: &[u8]);
    fn n_bytes_hashed(&self) -> usize;
    fn finalize(self) -> Self::Digest;
    fn midstate(&self) -> Self::Midstate;
    fn from_midstate(midstate: Self::Midstate, length: usize) -> Self;

    // Provided methods
    fn new() -> Self { ... }
    fn hash(bytes: &[u8]) -> Self::Digest { ... }
    fn hash_byte_chunks<B, I>(byte_slices: I) -> Self::Digest
       where B: AsRef<[u8]>,
             I: IntoIterator<Item = B> { ... }
}
Expand description

A hashing engine which bytes can be serialized into.

Required Associated Constants§

Source

const BLOCK_SIZE: usize

Length of the hash’s internal block size, in bytes.

Required Associated Types§

Source

type Digest: Copy + Clone + PartialEq + Eq + PartialOrd + Ord + Hash + AsRef<[u8]>

The digest returned by this hash engine.

This is expected to be an array.

Source

type Midstate

Byte array representing the internal state of the hash engine.

Required Methods§

Source

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

Add data to the hash engine.

Source

fn n_bytes_hashed(&self) -> usize

Return the number of bytes already n_bytes_hashed(inputted).

Source

fn finalize(self) -> Self::Digest

Returns the final digest from the current state of the hash engine.

Source

fn midstate(&self) -> Self::Midstate

Outputs the midstate of the hash engine. This function should not be used directly unless you really know what you’re doing.

Source

fn from_midstate(midstate: Self::Midstate, length: usize) -> Self

Create a new HashEngine from a Self::Midstate.

Only use this function if you know what you are doing.

Provided Methods§

Source

fn new() -> Self

Creates a new hash engine.

Source

fn hash(bytes: &[u8]) -> Self::Digest

Creates a default hash engine, adds bytes to it, then finalizes the engine.

§Returns

The digest created by hashing bytes with engine’s hashing algorithm.

Source

fn hash_byte_chunks<B, I>(byte_slices: I) -> Self::Digest
where B: AsRef<[u8]>, I: IntoIterator<Item = B>,

Hashes all the byte slices retrieved from the iterator together.

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 HashEngine for chf::ripemd160::Engine

Source§

const BLOCK_SIZE: usize = 64usize

Source§

type Digest = [u8; 20]

Source§

type Midstate = [u8; 20]

Source§

impl HashEngine for chf::sha1::Engine

Source§

const BLOCK_SIZE: usize = 64usize

Source§

type Digest = [u8; 20]

Source§

type Midstate = [u8; 20]

Source§

impl HashEngine for chf::sha256::Engine

Source§

impl HashEngine for chf::sha384::Engine

Source§

const BLOCK_SIZE: usize = 128usize

Source§

type Digest = [u8; 48]

Source§

type Midstate = [u8; 64]

Source§

impl HashEngine for chf::sha512::Engine

Source§

const BLOCK_SIZE: usize = 128usize

Source§

type Digest = [u8; 64]

Source§

type Midstate = [u8; 64]

Source§

impl HashEngine for chf::sha512_256::Engine

Source§

const BLOCK_SIZE: usize = 128usize

Source§

type Digest = [u8; 32]

Source§

type Midstate = [u8; 64]

Source§

impl HashEngine for chf::siphash24::Engine

Source§

impl<E: HashEngine> HashEngine for chf::hmac::Engine<E>

Source§

const BLOCK_SIZE: usize = E::BLOCK_SIZE

Source§

type Digest = <E as HashEngine>::Digest

Source§

type Midstate = Midstate<E>

Source§

impl<T: Tag> HashEngine for chf::sha256t::Engine<T>