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

pub struct HMAC {
    // some fields omitted
}

Provides HMAC computation.

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);
assert_eq!(res, spec);

Use the Write trait to supply the input in chunks.

use std::io::prelude::*;
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);
h.write_all(data[0]);
h.write_all(data[1]);
let res = h.finish();
assert_eq!(res, spec);

Methods

impl HMAC

fn new(ty: Type, key: &[u8]) -> HMAC

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

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

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

Trait Implementations

impl Write for HMAC

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

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

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

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

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

fn broadcast<W>(self, other: W) -> Broadcast<Self, W> where W: Write

impl Clone for HMAC

fn clone(&self) -> HMAC

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

impl Drop for HMAC

fn drop(&mut self)