Skip to main content

HmacAlgorithm

Trait HmacAlgorithm 

Source
pub trait HmacAlgorithm:
    Sized
    + PartialEq
    + Eq
    + Debug
    + Clone {
    type MaxLenBuf: AsMut<[u8]> + Sized + Default;

    const MAX_LEN: usize;

    // Required method
    fn len(&self) -> usize;

    // Provided method
    fn from_cose_number(number: impl Into<i128>) -> Option<Self> { ... }
}
Expand description

An HMAC algorithm identifier.

Required Associated Constants§

Source

const MAX_LEN: usize

The maximum output of Self::len().

This can be used by consumers of this trait (e.g. the HMAC trait) to build internal buffers.

Required Associated Types§

Source

type MaxLenBuf: AsMut<[u8]> + Sized + Default

A [u8; MAX_LEN] type.

This is needed as a workaround while limitation inconst generics mean that users (in particular, HKDF implementations) can not create a local variable of type [u8; Self::HmacAlgorithm::MAX_LEN].

The only sensible implementation is [u8; MAX_LEN]. Users of the trait may panic if it is not, but must assume that it is anything for safety and security.

Required Methods§

Source

fn len(&self) -> usize

Output length in bytes.

§Constraints

The returned value must not be greater than Self::MAX_LEN; otherwise, consumers of the trait may panic.

Provided Methods§

Source

fn from_cose_number(number: impl Into<i128>) -> Option<Self>

Selects an HMAC algorithm from its COSE number.

The algorithm number comes from the “COSE Algorithms” registry maintained by IANA.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§