Synopsis#include <glib.h> enum GChecksumType; gssize g_checksum_type_get_length (GChecksumType checksum_type); GChecksum; GChecksum* g_checksum_new (GChecksumType checksum_type); GChecksum* g_checksum_copy (const GChecksum *checksum); void g_checksum_free (GChecksum *checksum); void g_checksum_reset (GChecksum *checksum); void g_checksum_update (GChecksum *checksum, const guchar *data, gssize length); const gchar* g_checksum_get_string (GChecksum *checksum); void g_checksum_get_digest (GChecksum *checksum, guint8 *buffer, gsize *digest_len); gchar* g_compute_checksum_for_data (GChecksumType checksum_type, const guchar *data, gsize length); gchar* g_compute_checksum_for_string (GChecksumType checksum_type, const gchar *str, gssize length); DescriptionGLib 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.
GLib supports incremental checksums using the GChecksum data structure, by
calling Support for checksums has been added in GLib 2.16 Detailsenum GChecksumTypetypedef enum {
G_CHECKSUM_MD5,
G_CHECKSUM_SHA1,
G_CHECKSUM_SHA256
} GChecksumType;
The hashing algorithm to be used by GChecksum when performing the digest of some data. Note that the GChecksumType enumeration may be extended at a later date to include new hashing algorithm types.
Since 2.16 g_checksum_type_get_length ()gssize g_checksum_type_get_length (GChecksumType checksum_type);
Gets the length in bytes of digests of type
Since 2.16 GChecksumtypedef struct _GChecksum GChecksum;
An opaque structure representing a checksumming operation.
To create a new GChecksum, use
Since 2.16 g_checksum_new ()GChecksum* g_checksum_new (GChecksumType checksum_type);
Creates a new GChecksum, using the checksum algorithm
A GChecksum works by feeding a binary blob through
Since 2.16 g_checksum_copy ()GChecksum* g_checksum_copy (const GChecksum *checksum);
Copies a GChecksum. If
Since 2.16 g_checksum_free ()void g_checksum_free (GChecksum *checksum);
Frees the memory allocated for
Since 2.16 g_checksum_reset ()void g_checksum_reset (GChecksum *checksum);
Resets the state of the
Since 2.18 g_checksum_update ()void g_checksum_update (GChecksum *checksum, const guchar *data, gssize length);
Feeds
Since 2.16 g_checksum_get_string ()const gchar* g_checksum_get_string (GChecksum *checksum); Gets the digest as an hexadecimal string.
Once this function has been called the GChecksum can no longer be
updated with
Since 2.16 g_checksum_get_digest ()void g_checksum_get_digest (GChecksum *checksum, guint8 *buffer, gsize *digest_len);
Gets the digest from
Once this function has been called, the GChecksum is closed and can
no longer be updated with
Since 2.16 g_compute_checksum_for_data ()gchar* g_compute_checksum_for_data (GChecksumType checksum_type, const guchar *data, gsize length);
Computes the checksum for a binary
Since 2.16 g_compute_checksum_for_string ()gchar* g_compute_checksum_for_string (GChecksumType checksum_type, const gchar *str, gssize length); Computes the checksum of a string.
Since 2.16 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||