HMAC

Overload of HMAC to be used if H doesn't provide information about its block size.

@safe
struct HMAC (
H
size_t hashBlockSize
) if (
hashBlockSize % 8 == 0
) {
enum blockSize;
}

Constructors

this
this(const(ubyte)[] secret)

Constructs the HMAC digest using the specified secret.

Members

Functions

finish
DigestType!H finish()

Resets the digest and returns the finished hash.

put
HMAC!(H, blockSize) put(ubyte[] data)

Feeds a piece of data into the hash computation. This method allows the type to be used as an std.range.OutputRange.

start
HMAC!(H, blockSize) start()

Reinitializes the digest, making it ready for reuse.

Examples

import std.digest.sha : SHA1;
import std.string : representation;
string data1 = "Hello, world", data2 = "Hola mundo";
auto hmac = HMAC!SHA1("My s3cR3T keY".representation);
auto digest = hmac.put(data1.representation)
                  .put(data2.representation)
                  .finish();
static immutable expected = [
    197, 57, 52, 3, 13, 194, 13,
    36, 117, 228, 8, 11, 111, 51,
    165, 3, 123, 31, 251, 113];
assert(digest == expected);

Meta