[epiphany/wip/ephy-sync: 13/52] Add function for hex decoding



commit be3740ca69e671cf773c4b43b03d84a31869b6b0
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date:   Wed Jun 22 15:55:09 2016 +0300

    Add function for hex decoding

 src/ephy-sync-utils.c |   20 ++++++++++++++++++++
 src/ephy-sync-utils.h |   19 ++++++++++---------
 2 files changed, 30 insertions(+), 9 deletions(-)
---
diff --git a/src/ephy-sync-utils.c b/src/ephy-sync-utils.c
index f1d82d0..33ad8f9 100644
--- a/src/ephy-sync-utils.c
+++ b/src/ephy-sync-utils.c
@@ -19,6 +19,9 @@
 #include "ephy-debug.h"
 #include "ephy-sync-utils.h"
 
+#include <glib/gstdio.h>
+#include <string.h>
+
 static const gchar hex_digits[] = "0123456789abcdef";
 
 gchar *
@@ -52,6 +55,23 @@ ephy_sync_utils_encode_hex (guint8 *data,
   return retval;
 }
 
+guint8 *
+ephy_sync_utils_decode_hex (const gchar *hex_string)
+{
+  guint8 *retval;
+  gsize hex_length = strlen (hex_string);
+
+  g_return_val_if_fail (hex_length % 2 == 0, NULL);
+
+  retval = g_malloc (hex_length / 2);
+
+  for (gsize i = 0, j = 0; i < hex_length; i += 2, j++) {
+    sscanf(hex_string + i, "%2hhx", retval + j);
+  }
+
+  return retval;
+}
+
 /* FIXME: Only for debugging, remove when no longer needed */
 void
 ephy_sync_utils_display_hex (const gchar *data_name,
diff --git a/src/ephy-sync-utils.h b/src/ephy-sync-utils.h
index 538bd7b..9ea089c 100644
--- a/src/ephy-sync-utils.h
+++ b/src/ephy-sync-utils.h
@@ -25,19 +25,20 @@ G_BEGIN_DECLS
 
 #define EPHY_SYNC_TOKEN_LENGTH 32
 
-gchar *ephy_sync_utils_kw          (const gchar *name);
+gchar  *ephy_sync_utils_kw          (const gchar *name);
 
-gchar *ephy_sync_utils_kwe         (const gchar *name,
-                                    const gchar *emailUTF8);
+gchar  *ephy_sync_utils_kwe         (const gchar *name,
+                                     const gchar *emailUTF8);
 
-gchar *ephy_sync_utils_encode_hex  (guint8 *data,
-                                    gsize   data_length);
+gchar  *ephy_sync_utils_encode_hex  (guint8 *data,
+                                     gsize   data_length);
 
-/* FIXME: Only for debugging, remove when no longer needed */
-void   ephy_sync_utils_display_hex (const gchar *data_name,
-                                    guint8      *data,
-                                    gsize        data_length);
+guint8 *ephy_sync_utils_decode_hex  (const gchar *hex_string);
 
+/* FIXME: Only for debugging, remove when no longer needed */
+void    ephy_sync_utils_display_hex (const gchar *data_name,
+                                     guint8      *data,
+                                     gsize        data_length);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]