1.11 <GHmac>

Structure: <GHmac>

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, and support for SHA-512 in GLib 2.42. Support for SHA-384 was added in GLib 2.52.

To create a new <GHmac>, use hmac:new. To free a <GHmac>, use hmac:unref.

Procedures

Method: hmac:copy self ⇒ %return
Method: copy self ⇒ %return

Copies a <GHmac>. If self has been closed, by calling hmac:get-string or hmac:get-digest, the copied HMAC will be closed as well.

self

Passed: a <GHmac>.

the <GHmac> to copy

%return

Returned: a <GHmac>.

the copy of the passed <GHmac>. Use hmac:unref when finished using it.

Method: hmac:get-digest self buffer
Method: get-digest self 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 checksum:update.

self

Passed: a <GHmac>.

a <GHmac>

buffer

Passed: a bytevector, or a list or vector, each an unsigned 8-bit integer.

output buffer

digest-len

Not passed: guile-gi gives the length of buffer.

an inout parameter. The caller initializes it to the size of buffer. After the call it contains the length of the digest

Method: hmac:get-string self ⇒ %return
Method: get-string self ⇒ %return

Gets the HMAC as a hexadecimal string.

Once this function has been called the <GHmac> can no longer be updated with hmac:update.

The hexadecimal characters will be lower case.

self

Passed: a <GHmac>.

a <GHmac>

%return

Returned: a string.

the hexadecimal representation of the HMAC. The returned string is owned by the HMAC and should not be modified or freed.

Procedure: hmac:new digest-type key ⇒ %return

Creates a new <GHmac>, using the digest algorithm digest-type. If the digest-type is not known, #f 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 hmac:update until the data is complete; the digest can then be extracted using hmac:get-string, which will return the checksum as a hexadecimal string; or hmac:get-digest, which will return a array of raw bytes. Once either hmac:get-string or hmac:get-digest have been called on a <GHmac>, the HMAC will be closed and it won’t be possible to call hmac:update on it anymore.

Support for digests of type sha512 has been added in GLib 2.42. Support for sha384 was added in GLib 2.52.

digest-type

Passed: a <%GChecksumType>, or one of its symbols.

the desired type of digest

key

Passed: a bytevector, or a list or vector, each an unsigned 8-bit integer.

the key for the HMAC

%return

Returned: a <GHmac>, or #f.

the newly created <GHmac>, or #f. Use hmac:unref to free the memory allocated by it.

key-len

Not passed: guile-gi gives the length of key.

the length of the keys

Method: hmac:ref self ⇒ %return
Method: ref self ⇒ %return

Atomically increments the reference count of self by one.

This function is MT-safe and may be called from any thread.

self

Passed: a <GHmac>.

a valid <GHmac>

%return

Returned: a <GHmac>.

the passed in <GHmac>.

Method: hmac:unref self
Method: unref self

Atomically decrements the reference count of self 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 self.

self

Passed: a <GHmac>.

a <GHmac>

Method: hmac:update self data
Method: update self data

Feeds data into an existing <GHmac>.

The HMAC must still be open, that is hmac:get-string or hmac:get-digest must not have been called on self.

self

Passed: a <GHmac>.

a <GHmac>

data

Passed: a bytevector, or a list or vector, each an unsigned 8-bit integer.

buffer used to compute the checksum

length

Not passed: guile-gi gives the length of data.

size of the buffer, or -1 if it is a nul-terminated string