glibmm 2.80.0
|
Computes the checksum for data. More...
#include <glibmm/checksum.h>
Public Types | |
enum class | Type { MD5 , SHA1 , SHA256 , SHA512 , SHA384 } |
Public Member Functions | |
Checksum () | |
Checksum (GChecksum *gobject, bool make_a_copy=true) | |
Checksum (const Checksum &other) | |
Checksum & | operator= (const Checksum &other) |
Checksum (Checksum &&other) noexcept | |
Checksum & | operator= (Checksum &&other) noexcept |
~Checksum () noexcept | |
void | swap (Checksum &other) noexcept |
GChecksum * | gobj () |
Provides access to the underlying C instance. | |
const GChecksum * | gobj () const |
Provides access to the underlying C instance. | |
GChecksum * | gobj_copy () const |
Provides access to the underlying C instance. The caller is responsible for freeing it. Use when directly setting fields in structs. | |
Checksum (Type checksum_type) | |
Creates a new Checksum, using the checksum algorithm checksum_type. | |
operator bool () const | |
Returns true if the Checksum object is valid. | |
void | reset () |
Resets the state of the checksum back to its initial state. | |
void | update (const guchar *data, gssize length) |
Feeds data into an existing Checksum. | |
void | update (const std::string &data) |
Feeds data into an existing Checksum. | |
void | get_digest (guint8 *buffer, gsize *digest_len) const |
Gets the digest from checksum as a raw binary vector and places it into buffer. | |
std::string | get_string () const |
Gets the digest as a hexadecimal string. | |
Static Public Member Functions | |
static GType | get_type () |
Get the GType for this class, for use with the underlying GObject type system. | |
static std::string | compute_checksum (Type checksum_type, const guchar *data, gsize length) |
Computes the checksum for a binary data of length. | |
static std::string | compute_checksum (Type checksum_type, const std::string & str) |
Computes the checksum of a string. | |
static gssize | get_length (Type checksum_type) |
Gets the length in bytes of digests of type checksum_type. | |
Protected Attributes | |
GChecksum * | gobject_ |
Related Symbols | |
(Note that these are not member symbols.) | |
void | swap (Checksum &lhs, Checksum &rhs) noexcept |
Glib::Checksum | wrap (GChecksum *object, bool take_copy=false) |
A Glib::wrap() method for this object. | |
Computes the checksum for data.
This is 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.
glibmm supports incremental checksums by calling update() as long as there's data available and then using get_string() or 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 NULL-terminated strings in one go, use the static compute_checksum() convenience functions().
|
strong |
Glib::Checksum::Checksum | ( | ) |
|
noexcept |
|
noexcept |
|
explicit |
|
static |
Computes the checksum for a binary data of length.
This is a convenience wrapper for g_checksum_new(), g_checksum_get_string() and g_checksum_free().
The hexadecimal string returned will be in lower case.
checksum_type | A Glib::Checksum::Type. |
data | Binary blob to compute the digest of. |
length | Length of data. |
nullptr
if g_checksum_new() fails for checksum_type.
|
static |
Computes the checksum of a string.
checksum_type | A Type |
str | The string to compute the checksum of. |
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 Checksum is closed and can no longer be updated with g_checksum_update().
buffer | Output buffer. |
digest_len | An inout parameter. The caller initializes it to the size of buffer. After the call it contains the length of the digest. |
Gets the length in bytes of digests of type checksum_type.
checksum_type | A Type. |
std::string Glib::Checksum::get_string | ( | ) | const |
Gets the digest as a hexadecimal string.
Once this function has been called the Checksum can no longer be updated with g_checksum_update().
The hexadecimal characters will be lower case.
Get the GType for this class, for use with the underlying GObject type system.
|
inline |
Provides access to the underlying C instance.
Provides access to the underlying C instance.
GChecksum * Glib::Checksum::gobj_copy | ( | ) | const |
Provides access to the underlying C instance. The caller is responsible for freeing it. Use when directly setting fields in structs.
|
explicit |
Returns true if the Checksum object is valid.
This will return false, for instance, if an unsupported checksum type was provided to the constructor.
void Glib::Checksum::reset | ( | ) |
Resets the state of the checksum back to its initial state.
Feeds data into an existing Checksum.
The checksum must still be open, that is g_checksum_get_string() or g_checksum_get_digest() must not have been called on checksum.
data | Buffer used to compute the checksum. |
length | Size of the buffer, or -1 if it is a null-terminated string. |
void Glib::Checksum::update | ( | const std::string & | data | ) |
Feeds data into an existing Checksum.
The checksum must still be open, that is get_string() or get_digest() must not have been called on the checksum.
data | Buffer used to compute the checksum |
lhs | The left-hand side |
rhs | The right-hand side |
|
related |
A Glib::wrap() method for this object.
object | The C instance. |
take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref. |
|
protected |