Struct botan::MsgAuthCode[][src]

pub struct MsgAuthCode { /* fields omitted */ }

Message authentication code

Implementations

impl MsgAuthCode[src]

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

Create a new message authentication code

Examples

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

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

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)");

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

Return information about the key lengths supported by this object

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

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);

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

Set the key for the authentication code object

Examples

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

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

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

Examples

let 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();

pub fn finish(&self) -> Result<Vec<u8>>[src]

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

Examples

let 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();

pub fn clear(&self) -> Result<()>[src]

Clear the MAC key

Examples

let 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

impl Debug for MsgAuthCode[src]

impl Drop for MsgAuthCode[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.