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
checksum:new. To free a
<GChecksum>, use checksum:free.
GLib supports incremental checksums using the
<GChecksum> data structure, by calling
checksum:update as long as there’s data
available and then using checksum:get-string or 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
compute-checksum-for-data and
compute-checksum-for-string,
respectively.
Copies a <GChecksum>. If self has been
closed, by calling checksum:get-string
or g_checksum_get_digest(), the copied checksum will be closed as
well.
Passed: a <GChecksum>.
the <GChecksum> to copy
Returned: a <GChecksum>.
the copy of the passed <GChecksum>. Use
checksum:free when finished using it.
Frees the memory allocated for self.
Passed: a <GChecksum>.
Gets the digest as a hexadecimal string.
Once this function has been called the
<GChecksum> can no longer be updated with
checksum:update.
The hexadecimal characters will be lower case.
Passed: a <GChecksum>.
Returned: a string.
the hexadecimal representation of the checksum. The returned string is owned by the checksum and should not be modified or freed.
Creates a new <GChecksum>, using the checksum
algorithm checksum-type. If the checksum-type is not known,
#f 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 checksum:update until there is
data to be checked; the digest can then be extracted using
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
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 checksum:update
on it anymore.
Passed: a <%GChecksumType>, or one of its
symbols.
the desired type of checksum
Returned: a <GChecksum>, or #f.
the newly created <GChecksum>, or #f. Use
checksum:free to free the memory allocated
by it.
Resets the state of the self back to its initial state.
Passed: a <GChecksum>.
the <GChecksum> to reset
Gets the length in bytes of digests of type checksum-type
Passed: a <%GChecksumType>, or one of its
symbols.
Returned: a 64-bit integer.
the checksum length, or -1 if checksum-type is not supported.
Feeds data into an existing <GChecksum>.
The checksum must still be open, that is checksum:get-string or g_checksum_get_digest() must
not have been called on self.
Passed: a <GChecksum>.
Passed: a bytevector, or a list or vector, each an unsigned 8-bit integer.
buffer used to compute the checksum
Not passed: guile-gi gives the length of data.
size of the buffer, or -1 if it is a null-terminated string.