[seahorse/feature/seahorse-pgp-key-api: 3/8] pgp: Make pgp key id equality check more robust
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seahorse/feature/seahorse-pgp-key-api: 3/8] pgp: Make pgp key id equality check more robust
- Date: Sun, 15 Aug 2021 12:13:31 +0000 (UTC)
commit 6017136cae2fad9d9a287543110ea8d6e7029376
Author: Niels De Graef <nielsdegraef gmail com>
Date: Sun Aug 15 10:51:19 2021 +0200
pgp: Make pgp key id equality check more robust
Use `g_ascii_strcasecmp()` instead of `g_strcmp0`, so that 2 equal
key ids but with with different casing are still treated as the same
key id.
pgp/seahorse-pgp-key.c | 28 +++++++++++++++++++---------
1 file changed, 19 insertions(+), 9 deletions(-)
---
diff --git a/pgp/seahorse-pgp-key.c b/pgp/seahorse-pgp-key.c
index 37d69e76..686c8ad5 100644
--- a/pgp/seahorse-pgp-key.c
+++ b/pgp/seahorse-pgp-key.c
@@ -78,20 +78,30 @@ seahorse_pgp_keyid_hash (gconstpointer v)
return g_str_hash (keyid);
}
+/**
+ * seahorse_pgp_keyid_equal:
+ * @v1: A fingerprint or key id
+ * @v2: A fingerprint or key id
+ *
+ * Compares key IDs, regardless of casing.
+ */
gboolean
-seahorse_pgp_keyid_equal (gconstpointer v1,
- gconstpointer v2)
+seahorse_pgp_keyid_equal (const void *v1,
+ const void *v2)
{
const char *keyid_1 = v1;
const char *keyid_2 = v2;
- gsize len_1 = strlen (keyid_1);
- gsize len_2 = strlen (keyid_2);
-
- if (len_1 != len_2 && len_1 >= 8 && len_2 >= 8) {
- keyid_1 += len_1 - 8;
- keyid_2 += len_2 - 8;
+ size_t len_1 = strlen (keyid_1);
+ size_t len_2 = strlen (keyid_2);
+
+ /* In case we have a key ids of different length, go to the shortest
+ * reliable form: the long key id (16 characters) */
+ if (len_1 != len_2 && len_1 >= 16 && len_2 >= 16) {
+ keyid_1 += len_1 - 16;
+ keyid_2 += len_2 - 16;
}
- return g_str_equal (keyid_1, keyid_2);
+
+ return g_ascii_strcasecmp (keyid_1, keyid_2) == 0;
}
static char*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]