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§
Sourceconst BLOCK_SIZE: usize
const BLOCK_SIZE: usize
Length of the hash’s internal block size, in bytes.
Required Associated Types§
Required Methods§
Sourcefn n_bytes_hashed(&self) -> usize
fn n_bytes_hashed(&self) -> usize
Return the number of bytes already n_bytes_hashed(inputted).
Sourcefn finalize(self) -> Self::Digest
fn finalize(self) -> Self::Digest
Returns the final digest from the current state of the hash engine.
Sourcefn midstate(&self) -> Self::Midstate
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.
Sourcefn from_midstate(midstate: Self::Midstate, length: usize) -> Self
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§
Sourcefn hash(bytes: &[u8]) -> Self::Digest
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.
Sourcefn hash_byte_chunks<B, I>(byte_slices: I) -> Self::Digest
fn hash_byte_chunks<B, I>(byte_slices: I) -> Self::Digest
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.