pub trait HashFunction: Sized + Zeroize {
type Algorithm: HashAlgorithm;
type Output: AsRef<[u8]> + AsMut<[u8]> + Clone + Zeroize;
// Required methods
fn new() -> Self;
fn update(&mut self, data: &[u8]) -> Result<&mut Self>;
fn finalize(&mut self) -> Result<Self::Output>;
// Provided methods
fn finalize_reset(&mut self) -> Result<Self::Output> { ... }
fn output_size() -> usize { ... }
fn block_size() -> usize { ... }
fn digest(data: &[u8]) -> Result<Self::Output> { ... }
fn name() -> String { ... }
fn verify(data: &[u8], expected: &Self::Output) -> Result<bool>
where Self::Output: PartialEq { ... }
}Expand description
Trait for cryptographic hash functions with improved type safety.
Example usage of the enhanced hash functions:
use dcrypt_algorithms::hash::{EnhancedSha256, HashFunction};
// One-shot API
let digest = EnhancedSha256::digest(b"hello world").unwrap();
// Incremental API with method chaining
let digest = EnhancedSha256::new()
.update(b"hello ").unwrap()
.update(b"world").unwrap()
.finalize().unwrap();
// Verification
assert!(EnhancedSha256::verify(b"hello world", &digest).unwrap());Required Associated Types§
Sourcetype Algorithm: HashAlgorithm
type Algorithm: HashAlgorithm
The algorithm type that defines constants and properties
Required Methods§
Provided Methods§
Sourcefn finalize_reset(&mut self) -> Result<Self::Output>
fn finalize_reset(&mut self) -> Result<Self::Output>
Finalizes, returns the digest, and resets state.
Sourcefn output_size() -> usize
fn output_size() -> usize
The output size in bytes.
Sourcefn block_size() -> usize
fn block_size() -> usize
The internal block size in bytes.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".