Skip to main content

Mac

Trait Mac 

Source
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§

Source

fn name(&self) -> &'static str

Human-readable algorithm identifier (e.g. "HMAC-SHA-256").

Source

fn key_len(&self) -> usize

Required key length (minimum acceptable length; MACs are often variable).

Source

fn output_len(&self) -> usize

Output tag length in bytes.

Source

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.

Source

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§

Source

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".

Implementors§