pub struct Auth { /* private fields */ }Expand description
Secret-key authentication implementation based on libsodium’s
HMAC-SHA512-256 crypto_auth_* functions.
Implementations§
Source§impl Auth
impl Auth
Sourcepub fn compute<Output: NewByteArray<CRYPTO_AUTH_BYTES>, Key: ByteArray<CRYPTO_AUTH_KEYBYTES>, Input: Bytes + ?Sized>(
key: &Key,
input: &Input,
) -> Output
pub fn compute<Output: NewByteArray<CRYPTO_AUTH_BYTES>, Key: ByteArray<CRYPTO_AUTH_KEYBYTES>, Input: Bytes + ?Sized>( key: &Key, input: &Input, ) -> Output
Computes the message authentication code for input using key.
Sourcepub fn compute_to_vec<Key: ByteArray<CRYPTO_AUTH_KEYBYTES>, Input: Bytes + ?Sized>(
key: &Key,
input: &Input,
) -> Vec<u8> ⓘ
Available on crate feature alloc only.
pub fn compute_to_vec<Key: ByteArray<CRYPTO_AUTH_KEYBYTES>, Input: Bytes + ?Sized>( key: &Key, input: &Input, ) -> Vec<u8> ⓘ
alloc only.Computes the message authentication code and returns it as a Vec.
This is a convenience wrapper around Auth::compute.
Sourcepub fn compute_and_verify<OtherMac: ByteArray<CRYPTO_AUTH_BYTES>, Key: ByteArray<CRYPTO_AUTH_KEYBYTES>, Input: Bytes + ?Sized>(
other_mac: &OtherMac,
key: &Key,
input: &Input,
) -> Result<(), Error>
pub fn compute_and_verify<OtherMac: ByteArray<CRYPTO_AUTH_BYTES>, Key: ByteArray<CRYPTO_AUTH_KEYBYTES>, Input: Bytes + ?Sized>( other_mac: &OtherMac, key: &Key, input: &Input, ) -> Result<(), Error>
Verifies that other_mac authenticates input under key.
§Errors
Returns an error if other_mac does not match the authentication code
computed from key and input.
Sourcepub fn new<Key: ByteArray<CRYPTO_AUTH_KEYBYTES>>(key: &Key) -> Self
pub fn new<Key: ByteArray<CRYPTO_AUTH_KEYBYTES>>(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 secret-key authenticator at self with input.
Sourcepub fn finalize<Output: NewByteArray<CRYPTO_AUTH_BYTES>>(self) -> Output
pub fn finalize<Output: NewByteArray<CRYPTO_AUTH_BYTES>>(self) -> Output
Finalizes this secret-key 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 secret-key authenticator, returning the message
authentication code as a Vec. Convenience wrapper around
Auth::finalize.
Sourcepub fn verify<OtherMac: ByteArray<CRYPTO_AUTH_BYTES>>(
self,
other_mac: &OtherMac,
) -> Result<(), Error>
pub fn verify<OtherMac: ByteArray<CRYPTO_AUTH_BYTES>>( 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 Auth::update.