GLib.Checksum¶
Fields¶
None
Methods¶
class |
|
class |
|
|
|
|
|
|
|
|
|
|
Details¶
- class GLib.Checksum¶
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 aGChecksum
, 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.New in version 2.16.
- classmethod new(checksum_type)[source]¶
- Parameters:
checksum_type (
GLib.ChecksumType
) – the desired type of checksum- Returns:
the newly created
GLib.Checksum
, orNone
. UseGLib.Checksum.free
() to free the memory allocated by it.- Return type:
Creates a new
GLib.Checksum
, using the checksum algorithm checksum_type. If the checksum_type is not known,None
is returned. AGLib.Checksum
can be used to compute the checksum, or digest, of an arbitrary binary blob, using different hashing algorithms.A
GLib.Checksum
works by feeding a binary blob throughGLib.Checksum.update
() until there is data to be checked; the digest can then be extracted usingGLib.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 eitherGLib.Checksum.get_string
() or g_checksum_get_digest() have been called on aGLib.Checksum
, the checksum will be closed and it won’t be possible to callGLib.Checksum.update
() on it anymore.New in version 2.16.
- classmethod type_get_length(checksum_type)[source]¶
- Parameters:
checksum_type (
GLib.ChecksumType
) – aGLib.ChecksumType
- Returns:
the checksum length, or -1 if checksum_type is not supported.
- Return type:
Gets the length in bytes of digests of type checksum_type
New in version 2.16.
- copy()[source]¶
- Returns:
the copy of the passed
GLib.Checksum
. UseGLib.Checksum.free
() when finished using it.- Return type:
Copies a
GLib.Checksum
. If self has been closed, by callingGLib.Checksum.get_string
() or g_checksum_get_digest(), the copied checksum will be closed as well.New in version 2.16.
- get_string()[source]¶
- Returns:
the hexadecimal representation of the checksum. The returned string is owned by the checksum and should not be modified or freed.
- Return type:
Gets the digest as a hexadecimal string.
Once this function has been called the
GLib.Checksum
can no longer be updated withGLib.Checksum.update
().The hexadecimal characters will be lower case.
New in version 2.16.
- update(data)[source]¶
- Parameters:
data (
bytes
) – buffer used to compute the checksum
Feeds data into an existing
GLib.Checksum
. The checksum must still be open, that isGLib.Checksum.get_string
() or g_checksum_get_digest() must not have been called on self.New in version 2.16.