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>,
impl<Variant, const KEY_LENGTH: usize, const MAC_LENGTH: usize> Hmac<Variant, KEY_LENGTH, MAC_LENGTH>where
Variant: HmacVariant<KEY_LENGTH, MAC_LENGTH>,
Sourcepub fn compute<Output: NewByteArray<MAC_LENGTH>, Key: ByteArray<KEY_LENGTH>, Input: Bytes + ?Sized>(
key: &Key,
input: &Input,
) -> Output
pub fn compute<Output: NewByteArray<MAC_LENGTH>, Key: ByteArray<KEY_LENGTH>, Input: Bytes + ?Sized>( key: &Key, input: &Input, ) -> Output
Computes and returns the message authentication code for input using
key.
Sourcepub fn compute_to_vec<Key: ByteArray<KEY_LENGTH>, Input: Bytes + ?Sized>(
key: &Key,
input: &Input,
) -> Vec<u8> ⓘ
Available on crate feature alloc only.
pub fn compute_to_vec<Key: ByteArray<KEY_LENGTH>, Input: Bytes + ?Sized>( key: &Key, input: &Input, ) -> Vec<u8> ⓘ
alloc only.Convenience wrapper around Self::compute that returns a Vec.
Sourcepub fn compute_and_verify<OtherMac: ByteArray<MAC_LENGTH>, Key: ByteArray<KEY_LENGTH>, Input: Bytes + ?Sized>(
other_mac: &OtherMac,
key: &Key,
input: &Input,
) -> Result<(), Error>
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.
Sourcepub fn new<Key: ByteArray<KEY_LENGTH>>(key: &Key) -> Self
pub fn new<Key: ByteArray<KEY_LENGTH>>(key: &Key) -> Self
Returns a new incremental authenticator for key.
Sourcepub fn update<Input: Bytes + ?Sized>(&mut self, input: &Input)
pub fn update<Input: Bytes + ?Sized>(&mut self, input: &Input)
Updates the authenticator with input.
Sourcepub fn finalize<Output: NewByteArray<MAC_LENGTH>>(self) -> Output
pub fn finalize<Output: NewByteArray<MAC_LENGTH>>(self) -> Output
Finalizes this authenticator, returning the message authentication code.
Sourcepub fn finalize_to_vec(self) -> Vec<u8> ⓘ
Available on crate feature alloc only.
pub fn finalize_to_vec(self) -> Vec<u8> ⓘ
alloc only.Finalizes this authenticator, returning the message authentication code
as a Vec.
Sourcepub fn verify<OtherMac: ByteArray<MAC_LENGTH>>(
self,
other_mac: &OtherMac,
) -> Result<(), Error>
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.