mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-06-19 10:44:49 +02:00
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:
parent
a9e9bc74c3
commit
183ed8a3f8
@ -3011,6 +3011,7 @@ g_hmac_get_digest
|
|||||||
<SUBSECTION>
|
<SUBSECTION>
|
||||||
g_compute_hmac_for_data
|
g_compute_hmac_for_data
|
||||||
g_compute_hmac_for_string
|
g_compute_hmac_for_string
|
||||||
|
g_compute_hmac_for_bytes
|
||||||
</SECTION>
|
</SECTION>
|
||||||
|
|
||||||
<SECTION>
|
<SECTION>
|
||||||
|
36
glib/ghmac.c
36
glib/ghmac.c
@ -370,6 +370,42 @@ g_compute_hmac_for_data (GChecksumType digest_type,
|
|||||||
return retval;
|
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:
|
* g_compute_hmac_for_string:
|
||||||
* @digest_type: a #GChecksumType to use for the HMAC
|
* @digest_type: a #GChecksumType to use for the HMAC
|
||||||
|
@ -72,6 +72,11 @@ gchar *g_compute_hmac_for_string (GChecksumType digest_type,
|
|||||||
gsize key_len,
|
gsize key_len,
|
||||||
const gchar *str,
|
const gchar *str,
|
||||||
gssize length);
|
gssize length);
|
||||||
|
GLIB_AVAILABLE_IN_2_50
|
||||||
|
gchar *g_compute_hmac_for_bytes (GChecksumType digest_type,
|
||||||
|
GBytes *key,
|
||||||
|
GBytes *data);
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user