Struct orion::hmac::Hmac
[−]
[src]
pub struct Hmac { pub secret_key: Vec<u8>, pub message: Vec<u8>, pub sha2: ShaVariantOption, }
HMAC (Hash-based Message Authentication Code) as specified in the RFC 2104.
Fields
secret_key: Vec<u8>
message: Vec<u8>
sha2: ShaVariantOption
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; use orion::options::ShaVariantOption; let key = gen_rand_key(16); let message = gen_rand_key(16); let hmac_sha256 = Hmac { secret_key: key, message: message, sha2: ShaVariantOption::SHA256 }; hmac_sha256.hmac_compute();
Verifying HMAC:
use orion::hmac::Hmac; use orion::util::gen_rand_key; use orion::options::ShaVariantOption; 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: ShaVariantOption::SHA256 }; let received_hmac = Hmac { secret_key: key.as_bytes().to_vec(), message: msg.as_bytes().to_vec(), sha2: ShaVariantOption::SHA256 }; assert_eq!(hmac_sha256.hmac_compare(&received_hmac.hmac_compute()), true);
pub fn hmac_compute(&self) -> Vec<u8>
[src]
Returns an HMAC for a given key and message.
pub fn hmac_compare(&self, received_hmac: &[u8]) -> bool
[src]
Check HMAC validity by computing one from the current struct fields and comparing this to the passed HMAC.