Skip to main content

Mac

Trait Mac 

Source
pub trait Mac: Algorithm + Clone {
    type Tag: AsRef<[u8]> + AsMut<[u8]> + Copy;

    const TAG_LEN: usize;

    // Required methods
    fn new(key: &[u8]) -> Result<Self>
       where Self: Sized;
    fn update(&mut self, data: &[u8]);
    fn finalize(self) -> Self::Tag;

    // Provided methods
    fn mac(key: &[u8], data: &[u8]) -> Result<Self::Tag>
       where Self: Sized { ... }
    fn verify(key: &[u8], data: &[u8], tag: &[u8]) -> Result<()>
       where Self: Sized { ... }
}
Expand description

A keyed message authentication code.

Required Associated Constants§

Source

const TAG_LEN: usize

Tag length in bytes.

Required Associated Types§

Source

type Tag: AsRef<[u8]> + AsMut<[u8]> + Copy

The fixed-size tag type.

Required Methods§

Source

fn new(key: &[u8]) -> Result<Self>
where Self: Sized,

Create a MAC instance from a key of any length the algorithm accepts.

Source

fn update(&mut self, data: &[u8])

Absorb more input.

Source

fn finalize(self) -> Self::Tag

Consume the instance and produce the tag.

Provided Methods§

Source

fn mac(key: &[u8], data: &[u8]) -> Result<Self::Tag>
where Self: Sized,

One-shot authentication.

Source

fn verify(key: &[u8], data: &[u8], tag: &[u8]) -> Result<()>
where Self: Sized,

Constant-time tag verification.

Returns crate::ErrorKind::AuthenticationFailed on mismatch and never reveals where the tags diverged.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§