Struct MsgAuthCode

Source
pub struct MsgAuthCode { /* private fields */ }
Expand description

Message authentication code

Implementations§

Source§

impl MsgAuthCode

Source

pub fn new(name: &str) -> Result<MsgAuthCode>

Create a new message authentication code

§Examples
let hmac = botan::MsgAuthCode::new("HMAC(SHA-256)").unwrap();
let poly1305 = botan::MsgAuthCode::new("Poly1305").unwrap();
Source

pub fn algo_name(&self) -> Result<String>

Return the name of this algorithm which may or may not exactly match what was provided to new()

§Examples
let mac = botan::MsgAuthCode::new("HMAC(SHA-384)").unwrap();
assert_eq!(mac.algo_name().unwrap(), "HMAC(SHA-384)");
Source

pub fn key_spec(&self) -> Result<KeySpec>

Return information about the key lengths supported by this object

Source

pub fn output_length(&self) -> Result<usize>

Return the output length of the authentication code, in bytes

§Examples
let hmac = botan::MsgAuthCode::new("HMAC(SHA-256)").unwrap();
assert_eq!(hmac.output_length().unwrap(), 32);
Source

pub fn set_key(&mut self, key: &[u8]) -> Result<()>

Set the key for the authentication code object

§Examples
let mut hmac = botan::MsgAuthCode::new("HMAC(SHA-256)").unwrap();
hmac.set_key(&vec![0; 16]).unwrap();
Source

pub fn set_nonce(&mut self, nonce: &[u8]) -> Result<()>

Set the nonce for the authentication code object

Only a few MACs support this; currently only GMAC

§Examples
let mut gmac = botan::MsgAuthCode::new("GMAC(AES-128)").unwrap();
gmac.set_key(&vec![0; 16]).unwrap();
gmac.set_nonce(&vec![0; 12]);
Source

pub fn update(&mut self, data: &[u8]) -> Result<()>

Add data to a MAC computation, may be called many times

§Examples
let mut hmac = botan::MsgAuthCode::new("HMAC(SHA-256)").unwrap();
assert!(hmac.update(&[23]).is_err()); // key not set yet
hmac.set_key(&vec![0; 16]).unwrap();
hmac.update(&[1,2,3]).unwrap();
hmac.update(&[4,5,6]).unwrap();
Source

pub fn finish(&mut self) -> Result<Vec<u8>>

Complete a MAC computation, after which the object is reset to MAC a new message with the same key.

§Examples
let mut hmac = botan::MsgAuthCode::new("HMAC(SHA-256)").unwrap();
assert!(hmac.update(&[23]).is_err()); // key not set yet
hmac.set_key(&vec![0; 16]).unwrap();
hmac.update(&[1,2,3]).unwrap();
hmac.update(&[4,5,6]).unwrap();
let mac = hmac.finish().unwrap();
Source

pub fn clear(&mut self) -> Result<()>

Clear the MAC key

§Examples
let mut hmac = botan::MsgAuthCode::new("HMAC(SHA-256)").unwrap();
hmac.set_key(&vec![0; 16]).unwrap();
hmac.update(&[1,2,3]).unwrap();
hmac.clear().unwrap();
assert!(hmac.update(&[23]).is_err()); // key not set anymore

Trait Implementations§

Source§

impl Debug for MsgAuthCode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for MsgAuthCode

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for MsgAuthCode

Source§

impl Sync for MsgAuthCode

Auto Trait Implementations§

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, 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.