pub trait Hash: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn output_len(&self) -> usize;
fn hash(&self, msg: &[u8], out: &mut [u8]) -> Result<(), CryptoError>;
// Provided methods
fn hash_to_vec(&self, msg: &[u8]) -> Result<Vec<u8>, CryptoError> { ... }
fn hash_to_array<const N: usize>(
&self,
msg: &[u8],
) -> Result<[u8; N], CryptoError>
where Self: Sized { ... }
}Expand description
Stateless hash function (SHA-2, SHA-3, BLAKE3, …).
Required Methods§
Sourcefn output_len(&self) -> usize
fn output_len(&self) -> usize
Byte length of the digest output.
Sourcefn hash(&self, msg: &[u8], out: &mut [u8]) -> Result<(), CryptoError>
fn hash(&self, msg: &[u8], out: &mut [u8]) -> Result<(), CryptoError>
Hash msg and write the digest into out.
Returns CryptoError::BufferTooSmall when out.len() < self.output_len().
Provided Methods§
Sourcefn hash_to_vec(&self, msg: &[u8]) -> Result<Vec<u8>, CryptoError>
fn hash_to_vec(&self, msg: &[u8]) -> Result<Vec<u8>, CryptoError>
Convenience: hash msg and return the digest as a Vec<u8>.
Sourcefn hash_to_array<const N: usize>(
&self,
msg: &[u8],
) -> Result<[u8; N], CryptoError>where
Self: Sized,
fn hash_to_array<const N: usize>(
&self,
msg: &[u8],
) -> Result<[u8; N], CryptoError>where
Self: Sized,
Convenience: hash msg and return the digest as a fixed-size array.
Returns CryptoError::BadInput if N != self.output_len().
This method requires Self: Sized to preserve dyn Hash object safety
(const-generic methods cannot be called on trait objects).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".