pub trait Digest: Clone {
const BLOCK_LEN: usize;
const OUTPUT_LEN: usize;
// Required methods
fn new() -> Self;
fn update(&mut self, data: &[u8]);
fn finalize_into(self, out: &mut [u8]);
fn finalize_reset(&mut self, out: &mut [u8]);
fn zeroize(&mut self);
// Provided method
fn digest(data: &[u8]) -> Vec<u8> ⓘ { ... }
}Expand description
Minimal trait for fixed-output hash functions that can back HMAC.
SHA-1 and SHA-2 implementations behind this trait are Merkle-Damgard style
hashes, so their raw outputs inherit the usual length-extension caveat.
Use Hmac<H> for keyed authentication, or prefer SHA-3 / SHAKE when you
specifically want sponge-based hashing semantics.
Required Associated Constants§
Sourceconst BLOCK_LEN: usize
const BLOCK_LEN: usize
Byte-oriented block size used by the Merkle-Damgard or sponge API.
For SHA-3, this is the Keccak rate in bytes, which is the block size used by HMAC with the SHA-3 family.
Sourceconst OUTPUT_LEN: usize
const OUTPUT_LEN: usize
Digest size in bytes.
Required Methods§
Sourcefn finalize_into(self, out: &mut [u8])
fn finalize_into(self, out: &mut [u8])
Finalize the hash into out.
The default one-shot digest(...) helper below allocates. Prefer the
concrete types’ inherent digest(...) methods when you know the hash at
compile time and want a fixed-size array.
Sourcefn finalize_reset(&mut self, out: &mut [u8])
fn finalize_reset(&mut self, out: &mut [u8])
Finalize in place and wipe the internal state.
This exists primarily so keyed constructions such as Hmac<H> can
consume intermediate hash state without leaving key-derived chaining
values behind in memory.
Provided Methods§
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.