Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: GHmac

[21:7] extends: object

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 [ctor@GLib.Hmac.new]. To free a GHmac, use [method@GLib.Hmac.unref].

Members

  • handleObj
  • lib
  • retainedCallbacks
  • signalHandlerNames
  • signalSetterHandlers

Methods

  • GHmac (digest_type = null, key = null, key_len = null)

    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. Support for digests of type %G_CHECKSUM_SHA512 has been added in GLib 2.42. Support for %G_CHECKSUM_SHA384 was added in GLib 2.52.
    • @p digest_type is the desired type of digest.
    • @p key is the key for the HMAC.
    • @p key_len is the length of the keys.
  • toNativeHandle (Source)

    Normalizes a constructor argument into a raw pointer carrier. Accepts a raw NativeHandle, a raw NativeBuffer returned from fn.call(...), another generated wrapper exposing handle(), or null. Returns null when the argument carries no pointer.

    • @p Source is the raw handle, raw buffer, wrapper, or null.
    • @r A raw pointer carrier or null when no pointer is present.
  • getLib ()

    Returns the opened native library for this generated wrapper.

    • @r The opened native library.
  • handle ()

    Returns the wrapped NativeHandle.

    • @r The wrapped NativeHandle.
  • isNull ()

    Returns true when the wrapped handle is null.

    • @r A bool.
  • describe ()

    Returns a small string for debugging generated wrappers.

    • @r A string.
  • 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.

    • @r the copy of the passed #GHmac. Use g_hmac_unref() when finished using it..
  • get_digest (list buffer, int digest_len)

    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().
    • @p buffer is output buffer.
    • @p digest_len is an inout parameter. The caller initializes it to the size of @buffer. After the call it contains the length of the digest.
    • @r None.
  • get_string ()

    Gets the HMAC as a 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.

    • @r the hexadecimal representation of the HMAC. The returned string is owned by the HMAC and should not be modified or freed..
  • ref ()

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

    • @r the passed in #GHmac..
  • 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. ``
    • @r None.
  • update (list 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. ``
    • @p data is buffer used to compute the checksum.
    • @p length is size of the buffer, or -1 if it is a nul-terminated string.
    • @r None.