Skip to main content

Hmac

Struct Hmac 

Source
pub struct Hmac<Variant, const KEY_LENGTH: usize, const MAC_LENGTH: usize>
where Variant: HmacVariant<KEY_LENGTH, MAC_LENGTH>,
{ /* private fields */ }
Expand description

Rustaceous HMAC authenticator for a specific HmacVariant.

Implementations§

Source§

impl<Variant, const KEY_LENGTH: usize, const MAC_LENGTH: usize> Hmac<Variant, KEY_LENGTH, MAC_LENGTH>
where Variant: HmacVariant<KEY_LENGTH, MAC_LENGTH>,

Source

pub fn compute<Key: ByteArray<KEY_LENGTH>, Input: Bytes + ?Sized, Output: NewByteArray<MAC_LENGTH>>( key: Key, input: &Input, ) -> Output

Computes and returns the message authentication code for input using key.

This function takes ownership of key, but HMAC keys may authenticate multiple messages. Clone the key first when it is needed again.

Source

pub fn compute_to_vec<Key: ByteArray<KEY_LENGTH>, Input: Bytes + ?Sized>( key: Key, input: &Input, ) -> Vec<u8>

Convenience wrapper around Self::compute that returns a Vec.

Source

pub fn compute_and_verify<OtherMac: ByteArray<MAC_LENGTH>, Key: ByteArray<KEY_LENGTH>, Input: Bytes + ?Sized>( other_mac: &OtherMac, key: Key, input: &Input, ) -> Result<(), Error>

Verifies other_mac against input using key.

§Errors

Returns an error if other_mac does not authenticate input under key.

Source

pub fn new<Key: ByteArray<KEY_LENGTH>>(key: Key) -> Self

Returns a new incremental authenticator for key.

This function takes ownership of key, but HMAC keys may authenticate multiple messages. Clone the key first when it is needed again.

Source

pub fn update<Input: Bytes + ?Sized>(&mut self, input: &Input)

Updates the authenticator with input.

Source

pub fn finalize<Output: NewByteArray<MAC_LENGTH>>(self) -> Output

Finalizes this authenticator, returning the message authentication code.

Source

pub fn finalize_to_vec(self) -> Vec<u8>

Finalizes this authenticator, returning the message authentication code as a Vec.

Source

pub fn verify<OtherMac: ByteArray<MAC_LENGTH>>( self, other_mac: &OtherMac, ) -> Result<(), Error>

Finalizes this authenticator and verifies that the computed code matches other_mac using a constant-time comparison.

§Errors

Returns an error if other_mac does not match the authentication code computed from the data passed to Hmac::update.

Auto Trait Implementations§

§

impl<Variant, const KEY_LENGTH: usize, const MAC_LENGTH: usize> Freeze for Hmac<Variant, KEY_LENGTH, MAC_LENGTH>
where <Variant as HmacVariant<KEY_LENGTH, MAC_LENGTH>>::State: Freeze,

§

impl<Variant, const KEY_LENGTH: usize, const MAC_LENGTH: usize> RefUnwindSafe for Hmac<Variant, KEY_LENGTH, MAC_LENGTH>
where <Variant as HmacVariant<KEY_LENGTH, MAC_LENGTH>>::State: RefUnwindSafe, Variant: RefUnwindSafe,

§

impl<Variant, const KEY_LENGTH: usize, const MAC_LENGTH: usize> Send for Hmac<Variant, KEY_LENGTH, MAC_LENGTH>
where <Variant as HmacVariant<KEY_LENGTH, MAC_LENGTH>>::State: Send, Variant: Send,

§

impl<Variant, const KEY_LENGTH: usize, const MAC_LENGTH: usize> Sync for Hmac<Variant, KEY_LENGTH, MAC_LENGTH>
where <Variant as HmacVariant<KEY_LENGTH, MAC_LENGTH>>::State: Sync, Variant: Sync,

§

impl<Variant, const KEY_LENGTH: usize, const MAC_LENGTH: usize> Unpin for Hmac<Variant, KEY_LENGTH, MAC_LENGTH>
where <Variant as HmacVariant<KEY_LENGTH, MAC_LENGTH>>::State: Unpin, Variant: Unpin,

§

impl<Variant, const KEY_LENGTH: usize, const MAC_LENGTH: usize> UnsafeUnpin for Hmac<Variant, KEY_LENGTH, MAC_LENGTH>
where <Variant as HmacVariant<KEY_LENGTH, MAC_LENGTH>>::State: UnsafeUnpin,

§

impl<Variant, const KEY_LENGTH: usize, const MAC_LENGTH: usize> UnwindSafe for Hmac<Variant, KEY_LENGTH, MAC_LENGTH>
where <Variant as HmacVariant<KEY_LENGTH, MAC_LENGTH>>::State: UnwindSafe, Variant: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.