[glib] Add g_compute_hmac_for_bytes()
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add g_compute_hmac_for_bytes()
- Date: Sun, 17 Jul 2016 00:48:55 +0000 (UTC)
commit 183ed8a3f8e663c149b2a48add3b60eff3a1a71e
Author: Giovanni Campagna <gcampagn cs stanford edu>
Date: Wed Apr 20 11:47:46 2016 -0700
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
docs/reference/glib/glib-sections.txt | 1 +
glib/ghmac.c | 36 +++++++++++++++++++++++++++++++++
glib/ghmac.h | 5 ++++
3 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 398ca95..4636036 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -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>
diff --git a/glib/ghmac.c b/glib/ghmac.c
index d3334d0..bc498ff 100644
--- a/glib/ghmac.c
+++ b/glib/ghmac.c
@@ -371,6 +371,42 @@ g_compute_hmac_for_data (GChecksumType digest_type,
}
/**
+ * 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
* @key: (array length=key_len): the key to use in the HMAC
diff --git a/glib/ghmac.h b/glib/ghmac.h
index 01d53aa..e099a08 100644
--- a/glib/ghmac.h
+++ b/glib/ghmac.h
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]