Add g_compute_hmac_for_bytes()

As an introspection-friendly GBytes variant of g_compute_hmac_for_data()

https://bugzilla.gnome.org/show_bug.cgi?id=765338
This commit is contained in:
Giovanni Campagna 2016-04-20 11:47:46 -07:00 committed by Matthias Clasen
parent a9e9bc74c3
commit 183ed8a3f8
3 changed files with 42 additions and 0 deletions

View File

@ -3011,6 +3011,7 @@ g_hmac_get_digest
<SUBSECTION>
g_compute_hmac_for_data
g_compute_hmac_for_string
g_compute_hmac_for_bytes
</SECTION>
<SECTION>

View File

@ -370,6 +370,42 @@ g_compute_hmac_for_data (GChecksumType digest_type,
return retval;
}
/**
* g_compute_hmac_for_bytes:
* @digest_type: a #GChecksumType to use for the HMAC
* @key: the key to use in the HMAC
* @data: binary blob to compute the HMAC of
*
* Computes the HMAC for a binary @data. This is a
* convenience wrapper for g_hmac_new(), g_hmac_get_string()
* and g_hmac_unref().
*
* The hexadecimal string returned will be in lower case.
*
* Returns: the HMAC of the binary data as a string in hexadecimal.
* The returned string should be freed with g_free() when done using it.
*
* Since: 2.50
*/
gchar *
g_compute_hmac_for_bytes (GChecksumType digest_type,
GBytes *key,
GBytes *data)
{
gconstpointer byte_data;
gsize length;
gconstpointer key_data;
gsize key_len;
g_return_val_if_fail (data != NULL, NULL);
g_return_val_if_fail (key != NULL, NULL);
byte_data = g_bytes_get_data (data, &length);
key_data = g_bytes_get_data (key, &key_len);
return g_compute_hmac_for_data (digest_type, key_data, key_len, byte_data, length);
}
/**
* g_compute_hmac_for_string:
* @digest_type: a #GChecksumType to use for the HMAC

View File

@ -72,6 +72,11 @@ gchar *g_compute_hmac_for_string (GChecksumType digest_type,
gsize key_len,
const gchar *str,
gssize length);
GLIB_AVAILABLE_IN_2_50
gchar *g_compute_hmac_for_bytes (GChecksumType digest_type,
GBytes *key,
GBytes *data);
G_END_DECLS