Hmac

HMACs should be used when producing a cookie or hash based on data and a key. Simple mechanisms for using SHA1 and other algorithms to digest a key and data together are vulnerable to various security issues. HMAC uses algorithms like SHA1 in a secure way to produce a digest of a key and data.

Both the key and data are arbitrary byte arrays of bytes or characters.

Support for HMAC Digests has been added in GLib 2.30.

Constructors

this
this(GHmac* gHmac)

Sets our main struct and passes it to the parent class

this
this(GChecksumType digestType, char[] key)

Creates a new GHmac, using the digest algorithm digest_type. If the digest_type is not known, NULL is returned. A GHmac can be used to compute the HMAC of a key and an arbitrary binary blob, using different hashing algorithms. A GHmac works by feeding a binary blob through g_hmac_update() until the data is complete; the digest can then be extracted using g_hmac_get_string(), which will return the checksum as a hexadecimal string; or g_hmac_get_digest(), which will return a array of raw bytes. Once either g_hmac_get_string() or g_hmac_get_digest() have been called on a GHmac, the HMAC will be closed and it won't be possible to call g_hmac_update() on it anymore. Since 2.30

Destructor

~this
~this()
Undocumented in source.

Members

Functions

copy
Hmac copy()

Copies a GHmac. If hmac has been closed, by calling g_hmac_get_string() or g_hmac_get_digest(), the copied HMAC will be closed as well. Since 2.30

doref
Hmac doref()

Atomically increments the reference count of hmac by one. This function is MT-safe and may be called from any thread. Since 2.30

getDigest
void getDigest(ubyte[] buffer)

Gets the digest from checksum as a raw binary array and places it into buffer. The size of the digest depends on the type of checksum. Once this function has been called, the GHmac is closed and can no longer be updated with g_checksum_update(). Since 2.30

getHmacStruct
GHmac* getHmacStruct()
Undocumented in source. Be warned that the author may not have intended to support it.
getString
string getString()

Gets the HMAC as an hexadecimal string. Once this function has been called the GHmac can no longer be updated with g_hmac_update(). The hexadecimal characters will be lower case. Since 2.30

getStruct
void* getStruct()

the main Gtk struct as a void*

unref
void unref()

Atomically decrements the reference count of hmac by one. If the reference count drops to 0, all keys and values will be destroyed, and all memory allocated by the hash table is released. This function is MT-safe and may be called from any thread. Frees the memory allocated for hmac. Since 2.30

update
void update(char[] data)

Feeds data into an existing GHmac. The HMAC must still be open, that is g_hmac_get_string() or g_hmac_get_digest() must not have been called on hmac. Since 2.30

Static functions

computeHmacForData
string computeHmacForData(GChecksumType digestType, char[] key, char[] data)

Computes the HMAC for a binary data of length. This is a convenience wrapper for g_hmac_new(), g_hmac_get_string() and g_hmac_unref(). The hexadecimal string returned will be in lower case. Since 2.30

computeHmacForString
string computeHmacForString(GChecksumType digestType, char[] key, string str)

Computes the HMAC for a string. The hexadecimal string returned will be in lower case. Since 2.30

Variables

gHmac
GHmac* gHmac;

the main Gtk struct

Meta