/* Copyright (C) 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
_DEFS(glibmm,glib)
#include
#include
#include
#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C" { typedef struct _GChecksum GChecksum; }
#endif
namespace Glib
{
/** 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().
*
* @newin{2,16}
*/
class GLIBMM_API Checksum
{
_CLASS_BOXEDTYPE(Checksum, GChecksum, NONE, g_checksum_copy, g_checksum_free, GLIBMM_API)
_IGNORE(g_checksum_copy, g_checksum_free)
public:
_WRAP_ENUM(Type, GChecksumType, NO_GTYPE, decl_prefix GLIBMM_API)
#m4 _CONVERSION(`Type', `GChecksumType', `(static_cast<$2>($3))')
/** Creates a new Checksum, using the checksum algorithm @a checksum_type.
* If the checksum_type is not known, then operator bool() will return false.
*
* @param checksum_type Checksum type, one of defined above.
*/
explicit Checksum(Type checksum_type);
/** Returns true if the Checksum object is valid.
* This will return false, for instance, if an unsupported checksum type was provided to the constructor.
*/
explicit operator bool() const;
_WRAP_METHOD(void reset(), g_checksum_reset)
_WRAP_METHOD(void update(const guchar* data, gssize length), g_checksum_update)
/** 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.
*
* @param data Buffer used to compute the checksum
*/
void update(const std::string& data);
_WRAP_METHOD(void get_digest(guint8 *buffer, gsize *digest_len) const, g_checksum_get_digest)
_WRAP_METHOD(std::string get_string() const, g_checksum_get_string)
_WRAP_METHOD(static std::string compute_checksum(Type checksum_type, const guchar* data, gsize length), g_compute_checksum_for_data)
/** Computes the checksum of a string.
*
* @param checksum_type A Type
* @param str The string to compute the checksum of.
* @result The checksum as a hexadecimal string.
*/
static std::string compute_checksum(Type checksum_type, const std::string& str);
_IGNORE(g_compute_checksum_for_string)
//We don't use _WRAP_METHOD because this is not really a GCheckSum function:
/** Gets the length in bytes of digests of type @a checksum_type.
*
* @param checksum_type A Type.
* @result The checksum length, or -1 if @a checksum_type is not supported.
*/
static gssize get_length(Type checksum_type);
};
} //namespace Glib