Struct openssl::crypto::hmac::HMAC [] [src]

pub struct HMAC {
    // some fields omitted
}

Provides HMAC computation.

Requires the hmac feature.

Examples

Calculate a HMAC in one go.

use openssl::crypto::hash::Type;
use openssl::crypto::hmac::hmac;
let key = b"Jefe";
let data = b"what do ya want for nothing?";
let spec = b"\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38";
let res = hmac(Type::MD5, key, data).unwrap();
assert_eq!(res, spec);

Use the Write trait to supply the input in chunks.

use openssl::crypto::hash::Type;
use openssl::crypto::hmac::HMAC;
let key = b"Jefe";
let data: &[&[u8]] = &[b"what do ya ", b"want for nothing?"];
let spec = b"\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38";
let mut h = HMAC::new(Type::MD5, &*key).unwrap();
h.update(data[0]).unwrap();
h.update(data[1]).unwrap();
let res = h.finish().unwrap();
assert_eq!(res, spec);

Methods

impl HMAC
[src]

fn new(ty: Type, key: &[u8]) -> Result<HMACErrorStack>

Creates a new HMAC with the specified hash type using the key.

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

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

Returns the hash of the data written since creation or the last finish and resets the hasher.

Trait Implementations

impl Write for HMAC
[src]

fn write(&mut self, buf: &[u8]) -> Result<usize>

Write a buffer into this object, returning how many bytes were written. Read more

fn flush(&mut self) -> Result<()>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more

fn write_all(&mut self, buf: &[u8]) -> Result<()Error>
1.0.0

Attempts to write an entire buffer into this write. Read more

fn write_fmt(&mut self, fmt: Arguments) -> Result<()Error>
1.0.0

Writes a formatted string into this writer, returning any error encountered. Read more

fn by_ref(&mut self) -> &mut Self
1.0.0

Creates a "by reference" adaptor for this instance of Write. Read more

impl Clone for HMAC
[src]

fn clone(&self) -> HMAC

Requires the hmac_clone feature.

fn clone_from(&mut self, source: &Self)
1.0.0

Performs copy-assignment from source. Read more

impl Drop for HMAC
[src]

fn drop(&mut self)

A method called when the value goes out of scope. Read more