pub trait Mac: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn key_len(&self) -> usize;
fn output_len(&self) -> usize;
fn mac(
&self,
key: &[u8],
msg: &[u8],
out: &mut [u8],
) -> Result<(), CryptoError>;
fn verify(
&self,
key: &[u8],
msg: &[u8],
tag: &[u8],
) -> Result<(), CryptoError>;
// Provided method
fn mac_to_vec(&self, key: &[u8], msg: &[u8]) -> Result<Vec<u8>, CryptoError> { ... }
}Expand description
Message Authentication Code (HMAC, …).
Required Methods§
Sourcefn key_len(&self) -> usize
fn key_len(&self) -> usize
Required key length (minimum acceptable length; MACs are often variable).
Sourcefn output_len(&self) -> usize
fn output_len(&self) -> usize
Output tag length in bytes.
Sourcefn mac(&self, key: &[u8], msg: &[u8], out: &mut [u8]) -> Result<(), CryptoError>
fn mac(&self, key: &[u8], msg: &[u8], out: &mut [u8]) -> Result<(), CryptoError>
Compute a MAC tag for msg under key and write it into out.
Sourcefn verify(&self, key: &[u8], msg: &[u8], tag: &[u8]) -> Result<(), CryptoError>
fn verify(&self, key: &[u8], msg: &[u8], tag: &[u8]) -> Result<(), CryptoError>
Verify a MAC tag in constant time.
Returns CryptoError::InvalidTag on mismatch.
Provided Methods§
Sourcefn mac_to_vec(&self, key: &[u8], msg: &[u8]) -> Result<Vec<u8>, CryptoError>
fn mac_to_vec(&self, key: &[u8], msg: &[u8]) -> Result<Vec<u8>, CryptoError>
Convenience: compute MAC and return the tag as a Vec<u8>.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".