pub struct MsgAuthCode { /* private fields */ }Expand description
Message authentication code
Implementations§
Source§impl MsgAuthCode
impl MsgAuthCode
Sourcepub fn new(name: &str) -> Result<MsgAuthCode>
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();Sourcepub fn algo_name(&self) -> Result<String>
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)");Sourcepub fn key_spec(&self) -> Result<KeySpec>
pub fn key_spec(&self) -> Result<KeySpec>
Return information about the key lengths supported by this object
Sourcepub fn output_length(&self) -> Result<usize>
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);Sourcepub fn set_key(&mut self, key: &[u8]) -> Result<()>
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();Sourcepub fn set_nonce(&mut self, nonce: &[u8]) -> Result<()>
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]);Sourcepub fn update(&mut self, data: &[u8]) -> Result<()>
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();Sourcepub fn finish(&mut self) -> Result<Vec<u8>>
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();Trait Implementations§
Source§impl Debug for MsgAuthCode
impl Debug for MsgAuthCode
Source§impl Drop for MsgAuthCode
impl Drop for MsgAuthCode
impl Send for MsgAuthCode
impl Sync for MsgAuthCode
Auto Trait Implementations§
impl Freeze for MsgAuthCode
impl RefUnwindSafe for MsgAuthCode
impl Unpin for MsgAuthCode
impl UnwindSafe for MsgAuthCode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more