1.5 <GChecksum>

Structure: <GChecksum>

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.

Procedures

Method: checksum:copy self ⇒ %return
Method: copy self ⇒ %return

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.

self

Passed: a <GChecksum>.

the <GChecksum> to copy

%return

Returned: a <GChecksum>.

the copy of the passed <GChecksum>. Use checksum:free when finished using it.

Method: checksum:free self
Method: free self

Frees the memory allocated for self.

self

Passed: a <GChecksum>.

a <GChecksum>

Method: checksum:get-string self ⇒ %return
Method: get-string self ⇒ %return

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.

self

Passed: a <GChecksum>.

a <GChecksum>

%return

Returned: a string.

the hexadecimal representation of the checksum. The returned string is owned by the checksum and should not be modified or freed.

Procedure: checksum:new checksum-type ⇒ %return

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.

checksum-type

Passed: a <%GChecksumType>, or one of its symbols.

the desired type of checksum

%return

Returned: a <GChecksum>, or #f.

the newly created <GChecksum>, or #f. Use checksum:free to free the memory allocated by it.

Method: checksum:reset self
Method: reset self

Resets the state of the self back to its initial state.

self

Passed: a <GChecksum>.

the <GChecksum> to reset

Procedure: checksum:type-get-length checksum-type ⇒ %return

Gets the length in bytes of digests of type checksum-type

checksum-type

Passed: a <%GChecksumType>, or one of its symbols.

a <%GChecksumType>

%return

Returned: a 64-bit integer.

the checksum length, or -1 if checksum-type is not supported.

Method: checksum:update self data
Method: update self data

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.

self

Passed: a <GChecksum>.

a <GChecksum>

data

Passed: a bytevector, or a list or vector, each an unsigned 8-bit integer.

buffer used to compute the checksum

length

Not passed: guile-gi gives the length of data.

size of the buffer, or -1 if it is a null-terminated string.