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

pub struct HMAC { /* 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
[src]

Important traits for HMAC

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

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

Trait Implementations

impl Clone for HMAC
[src]

Important traits for HMAC

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Drop for HMAC
[src]

Executes the destructor for this type. Read more

impl Write for HMAC
[src]

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

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

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

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

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

Auto Trait Implementations

impl !Send for HMAC

impl !Sync for HMAC

Blanket Implementations

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Mutably borrows from an owned value. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

🔬 This is a nightly-only experimental API. (get_type_id)

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more