| GSK Reference Manual | ||||
|---|---|---|---|---|
GskHash;
GskHash* gsk_hash_new_md5 (void);
GskHash* gsk_hash_new_sha1 (void);
GskHash* gsk_hash_new_crc32 (gboolean big_endian);
void gsk_hash_feed (GskHash *hash,
gconstpointer data,
guint length);
void gsk_hash_feed_str (GskHash *hash,
const char *str);
void gsk_hash_done (GskHash *hash);
guint gsk_hash_get_size (GskHash *hash);
void gsk_hash_get (GskHash *hash,
guint8 *data_out);
void gsk_hash_get_hex (GskHash *hash,
gchar *hex_out);
void gsk_hash_destroy (GskHash *hash);
These small objects can compute a hash-function
of a stream of data incrementally.
Just pass pieces of data to gsk_hash_feed()
and it will keep track of the hash-objects state.
Call gsk_hash_done() to finish the hash off,
then use gsk_hash_get() or gsk_hash_get_hex() to
get the value of the hash.
typedef struct {
/* The size of the hash-key (in bytes) */
guint size;
} GskHash;
An abstract hashing object.
guint size; |
number of bytes in the hash. |
GskHash* gsk_hash_new_md5 (void);
Create a new MD5 hasher.
| Returns : | the newly allocated hash object. |
GskHash* gsk_hash_new_sha1 (void);
Create a new SHA1 hasher.
| Returns : | the newly allocated hash object. |
GskHash* gsk_hash_new_crc32 (gboolean big_endian);
Typically called as gsk_hash_new_crc32(G_BYTE_ORDER == G_BIG_ENDIAN).
big_endian : |
whether to compute a big-endian crc32 hash. (As opposed to a little endian hash). |
| Returns : | the newly allocated hash object. |
void gsk_hash_feed (GskHash *hash, gconstpointer data, guint length);
Affect the hash incrementally; hash the given binary data.
You may call this function on little bits of data and it must have exactly the same effect is if you called it once with a larger slab of data.
hash : |
the hash to feed data. |
data : |
binary data to accumulate in the hash. |
length : |
length of the binary data. |
void gsk_hash_feed_str (GskHash *hash, const char *str);
Hash the given binary data (incrementally).
You may mix calls to gsk_hash_feed() and gsk_hash_feed_str().
hash : |
the hash to feed data. |
str : |
a NUL-terminated string to feed to the hash. |
void gsk_hash_done (GskHash *hash);
Finish processing loose data for the hash. This may only be called once in the lifetime of the hash.
hash : |
the hash to finish. |
guint gsk_hash_get_size (GskHash *hash);
Get the number of binary bytes that this function maps to.
hash : |
the hash to query. |
| Returns : | the number of bytes of binary data in this hash. |
void gsk_hash_get (GskHash *hash, guint8 *data_out);
Get a binary hash value. This should be of the
size returned by gsk_hash_get_size().
hash : |
the hash to query. |
data_out : |
binary buffer to fill with the hash value. |
void gsk_hash_get_hex (GskHash *hash, gchar *hex_out);
Get a hex hash value. This should be of the
size returned by (gsk_hash_get_size() * 2 + 1).
hash : |
the hash to query. |
hex_out : |
buffer to fill with a NUL-terminated hex hash value. |
void gsk_hash_destroy (GskHash *hash);
Free memory used by the hash object.
hash : |
the hash function. |