[epiphany/wip/google-safe-browsing: 11/12] gsb-utils: Use GBytes for full hashes too



commit 15607e8dc8c6f7871a8515e92eda4cb77143337f
Author: Gabriel Ivascu <gabrielivascu gnome org>
Date:   Mon Sep 18 18:22:09 2017 +0300

    gsb-utils: Use GBytes for full hashes too
    
    This allows better handling in g_hash_table_new_full() and
    g_list_copy_deep() due to g_bytes_hash(), g_bytes_equal(),
    g_bytes_ref(), g_bytes_unref().

 lib/safe-browsing/ephy-gsb-storage.c |    8 ++++++--
 lib/safe-browsing/ephy-gsb-utils.c   |    8 ++++----
 lib/safe-browsing/ephy-gsb-utils.h   |    2 +-
 3 files changed, 11 insertions(+), 7 deletions(-)
---
diff --git a/lib/safe-browsing/ephy-gsb-storage.c b/lib/safe-browsing/ephy-gsb-storage.c
index 6038523..58b9677 100644
--- a/lib/safe-browsing/ephy-gsb-storage.c
+++ b/lib/safe-browsing/ephy-gsb-storage.c
@@ -1166,7 +1166,9 @@ ephy_gsb_storage_lookup_hash_prefixes (EphyGSBStorage *self,
   }
 
   for (GList *l = cues; l && l->data; l = l->next) {
-    ephy_sqlite_statement_bind_blob (statement, id++, l->data, CUE_LEN, &error);
+    ephy_sqlite_statement_bind_blob (statement, id++,
+                                     g_bytes_get_data (l->data, NULL), CUE_LEN,
+                                     &error);
     if (error) {
       g_warning ("Failed to bind cue value as blob: %s", error->message);
       goto out;
@@ -1233,7 +1235,9 @@ ephy_gsb_storage_lookup_full_hashes (EphyGSBStorage *self,
   }
 
   for (GList *l = hashes; l && l->data; l = l->next) {
-    ephy_sqlite_statement_bind_blob (statement, id++, l->data, GSB_HASH_SIZE, &error);
+    ephy_sqlite_statement_bind_blob (statement, id++,
+                                     g_bytes_get_data (l->data, NULL), GSB_HASH_SIZE,
+                                     &error);
     if (error) {
       g_warning ("Failed to bind hash value as blob: %s", error->message);
       goto out;
diff --git a/lib/safe-browsing/ephy-gsb-utils.c b/lib/safe-browsing/ephy-gsb-utils.c
index c2bf37f..db42623 100644
--- a/lib/safe-browsing/ephy-gsb-utils.c
+++ b/lib/safe-browsing/ephy-gsb-utils.c
@@ -117,8 +117,7 @@ ephy_gsb_hash_full_lookup_new (const guint8 *hash,
   g_assert (threat_entry_type);
 
   lookup = g_slice_new (EphyGSBHashFullLookup);
-  lookup->hash = g_malloc (GSB_HASH_SIZE);
-  memcpy (lookup->hash, hash, GSB_HASH_SIZE);
+  lookup->hash = g_bytes_new (hash, GSB_HASH_SIZE);
   lookup->threat_type = g_strdup (threat_type);
   lookup->platform_type = g_strdup (platform_type);
   lookup->threat_entry_type = g_strdup (threat_entry_type);
@@ -132,7 +131,7 @@ ephy_gsb_hash_full_lookup_free (EphyGSBHashFullLookup *lookup)
 {
   g_assert (lookup);
 
-  g_free (lookup->hash);
+  g_bytes_unref (lookup->hash);
   g_free (lookup->threat_type);
   g_free (lookup->platform_type);
   g_free (lookup->threat_entry_type);
@@ -615,8 +614,9 @@ ephy_gsb_utils_compute_hashes (const char *url)
       g_checksum_reset (checksum);
       g_checksum_update (checksum, (const guint8 *)value, strlen (value));
       g_checksum_get_digest (checksum, hash, &hash_len);
-      retval = g_list_prepend (retval, hash);
+      retval = g_list_prepend (retval, g_bytes_new (hash, hash_len));
 
+      g_free (hash);
       g_free (value);
     }
   }
diff --git a/lib/safe-browsing/ephy-gsb-utils.h b/lib/safe-browsing/ephy-gsb-utils.h
index 079f071..759f525 100644
--- a/lib/safe-browsing/ephy-gsb-utils.h
+++ b/lib/safe-browsing/ephy-gsb-utils.h
@@ -47,7 +47,7 @@ typedef struct {
 
 typedef struct {
   /* The 32 bytes full hash. */
-  guint8   *hash;
+  GBytes   *hash;
   char     *threat_type;
   char     *platform_type;
   char     *threat_entry_type;


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