Struct orion::hmac::Hmac [] [src]

pub struct Hmac {
    pub secret_key: Vec<u8>,
    pub message: Vec<u8>,
    pub sha2: usize,
}

HMAC (Hash-based Message Authentication Code) as specified in the RFC 2104.

Fields

Methods

impl Hmac
[src]

HMAC (Hash-based Message Authentication Code) as specified in the RFC 2104.

Usage examples:

Generating HMAC:

use orion::hmac::Hmac;
use orion::util::gen_rand_key;

let key = gen_rand_key(10);
let message = gen_rand_key(10);

let hmac_sha256 = Hmac { secret_key: key, message: message, sha2: 256 };

hmac_sha256.hmac_compute();

Verifying HMAC:

use orion::hmac::Hmac;
use orion::util::gen_rand_key;

let key = "Some key.";
let msg = "Some message.";

let hmac_sha256 = Hmac {
    secret_key: key.as_bytes().to_vec(),
    message: msg.as_bytes().to_vec(),
    sha2: 256
};
let received_hmac = Hmac {
    secret_key: key.as_bytes().to_vec(),
    message: msg.as_bytes().to_vec(),
    sha2: 256
};
assert_eq!(hmac_sha256.hmac_validate(&received_hmac.hmac_compute()), true);

[src]

Returns HMAC from a given key and message.

[src]

Check HMAC validity by computing one from the current struct fields and comparing this to the passed HMAC.

Trait Implementations

impl Drop for Hmac
[src]

[src]

Executes the destructor for this type. Read more

Auto Trait Implementations

impl Send for Hmac

impl Sync for Hmac