summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Ivascu <gabrielivascu@gnome.org>2017-09-18 18:22:09 +0300
committerGabriel Ivascu <gabrielivascu@gnome.org>2017-10-03 18:29:53 +0200
commit57218b2a209d91229a6d7e03b2f32be878ac73c5 (patch)
treee7f66e64ba8c62484639f92f2b7d4a80db2a6a24
parentbf848bd1f1e53146beaea99bb4434a8c9d770ed7 (diff)
downloadepiphany-57218b2a209d91229a6d7e03b2f32be878ac73c5.tar.gz
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().
-rw-r--r--lib/safe-browsing/ephy-gsb-storage.c8
-rw-r--r--lib/safe-browsing/ephy-gsb-utils.c8
-rw-r--r--lib/safe-browsing/ephy-gsb-utils.h2
-rw-r--r--tests/ephy-gsb-utils-test.c5
4 files changed, 14 insertions, 9 deletions
diff --git a/lib/safe-browsing/ephy-gsb-storage.c b/lib/safe-browsing/ephy-gsb-storage.c
index ce09870b0..846d34d5e 100644
--- a/lib/safe-browsing/ephy-gsb-storage.c
+++ b/lib/safe-browsing/ephy-gsb-storage.c
@@ -1157,7 +1157,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;
@@ -1224,7 +1226,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 0f540ec73..83a6f9dab 100644
--- a/lib/safe-browsing/ephy-gsb-utils.c
+++ b/lib/safe-browsing/ephy-gsb-utils.c
@@ -119,8 +119,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);
@@ -134,7 +133,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);
@@ -610,8 +609,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 3acb0182d..739b7772a 100644
--- a/lib/safe-browsing/ephy-gsb-utils.h
+++ b/lib/safe-browsing/ephy-gsb-utils.h
@@ -44,7 +44,7 @@ typedef struct {
} EphyGSBHashPrefixLookup;
typedef struct {
- guint8 *hash; /* The 32 bytes full hash */
+ GBytes *hash; /* The 32 bytes full hash */
char *threat_type;
char *platform_type;
char *threat_entry_type;
diff --git a/tests/ephy-gsb-utils-test.c b/tests/ephy-gsb-utils-test.c
index 8c5330d40..f0bc45376 100644
--- a/tests/ephy-gsb-utils-test.c
+++ b/tests/ephy-gsb-utils-test.c
@@ -161,12 +161,13 @@ test_ephy_gsb_utils_compute_hashes (void)
g_assert_cmpuint (g_list_length (hashes), ==, test.num_hashes);
for (guint k = 0; k < test.num_hashes; k++, h = h->next) {
- char *hash_hex = bytes_to_hex (h->data, GSB_HASH_SIZE);
+ char *hash_hex = bytes_to_hex (g_bytes_get_data (h->data, NULL),
+ g_bytes_get_size (h->data));
g_assert_cmpstr (hash_hex, ==, test.hashes_hex[k]);
g_free (hash_hex);
}
- g_list_free_full (hashes, g_free);
+ g_list_free_full (hashes, (GDestroyNotify)g_bytes_unref);
}
}