Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: GChecksum

[25:7] extends: object

GLib provides a generic API for computing checksums (or ‘digests’) for a sequence of arbitrary bytes, using various hashing algorithms like MD5, SHA-1 and SHA-256. Checksums are commonly used in various environments and specifications. To create a new GChecksum, use [ctor@GLib.Checksum.new]. To free a GChecksum, use [method@GLib.Checksum.free]. GLib supports incremental checksums using the GChecksum data structure, by calling [method@GLib.Checksum.update] as long as there’s data available and then using [method@GLib.Checksum.get_string] or [method@GLib.Checksum.get_digest] to compute the checksum and return it either as a string in hexadecimal form, or as a raw sequence of bytes. To compute the checksum for binary blobs and nul-terminated strings in one go, use the convenience functions [func@GLib.compute_checksum_for_data] and [func@GLib.compute_checksum_for_string], respectively.

Members

  • handleObj
  • lib
  • retainedCallbacks
  • signalHandlerNames
  • signalSetterHandlers

Methods

  • GChecksum (checksum_type = null)

    Creates a new #GChecksum, using the checksum algorithm @checksum_type. If the @checksum_type is not known, %NULL is returned. A #GChecksum can be used to compute the checksum, or digest, of an arbitrary binary blob, using different hashing algorithms. A #GChecksum works by feeding a binary blob through g_checksum_update() until there is data to be checked; the digest can then be extracted using g_checksum_get_string(), which will return the checksum as a hexadecimal string; or g_checksum_get_digest(), which will return a vector of raw bytes. Once either g_checksum_get_string() or g_checksum_get_digest() have been called on a #GChecksum, the checksum will be closed and it won't be possible to call g_checksum_update() on it anymore.

    • @p checksum_type is the desired type of checksum.
  • 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 #GChecksum. If @checksum has been closed, by calling g_checksum_get_string() or g_checksum_get_digest(), the copied checksum will be closed as well.

    • @r the copy of the passed #GChecksum. Use g_checksum_free() when finished using it..
  • free ()

    Frees the memory allocated for @checksum.

    • @r None.
  • get_digest (list buffer, int digest_len)

    Gets the digest from @checksum as a raw binary vector and places it into

    • @buffer. The size of the digest depends on the type of checksum. Once this function has been called, the #GChecksum 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 digest as a hexadecimal string. Once this function has been called the #GChecksum can no longer be updated with g_checksum_update(). The hexadecimal characters will be lower case.

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

    Resets the state of the @checksum back to its initial state.

    • @r None.
  • update (list data)

    Feeds @data into an existing #GChecksum. The checksum must still be open, that is g_checksum_get_string() or g_checksum_get_digest() must not have been called on @checksum.

    • @p data is buffer used to compute the checksum.
    • @p length is size of the buffer, or -1 if it is a null-terminated string..
    • @r None.