[seahorse/pgp/uids-listbox: 4/6] pgp-uid: Be more defensive in allowing signatures




commit 5e37dbfc2fe4febf05443fdf17f0416900320602
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Mon Aug 16 07:51:11 2021 +0200

    pgp-uid: Be more defensive in allowing signatures
    
    Certain signatures are not really relevant, such as duplicates or the
    signature that is always there by its owner. Since we plan more and more
    on using this GListModel, we might as well not expose them at all.

 pgp/seahorse-pgp-uid.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
---
diff --git a/pgp/seahorse-pgp-uid.c b/pgp/seahorse-pgp-uid.c
index 3d86e866..e9b81663 100644
--- a/pgp/seahorse-pgp-uid.c
+++ b/pgp/seahorse-pgp-uid.c
@@ -383,10 +383,28 @@ seahorse_pgp_uid_add_signature (SeahorsePgpUid       *self,
                                 SeahorsePgpSignature *signature)
 {
     SeahorsePgpUidPrivate *priv = seahorse_pgp_uid_get_instance_private (self);
+    const char *keyid;
 
     g_return_if_fail (SEAHORSE_PGP_IS_UID (self));
     g_return_if_fail (SEAHORSE_PGP_IS_SIGNATURE (signature));
 
+    keyid = seahorse_pgp_signature_get_keyid (signature);
+
+    /* Don't add signature of the parent key */
+    if (seahorse_pgp_key_has_keyid (priv->parent, keyid))
+        return;
+
+    /* Don't allow duplicates */
+    for (unsigned i = 0; i < g_list_model_get_n_items (priv->signatures); i++) {
+        g_autoptr(SeahorsePgpSignature) sig = g_list_model_get_item (priv->signatures, i);
+        const char *sig_keyid;
+
+        sig = g_list_model_get_item (priv->signatures, i);
+        sig_keyid = seahorse_pgp_signature_get_keyid (sig);
+        if (seahorse_pgp_keyid_equal (keyid, sig_keyid))
+            return;
+    }
+
     g_list_store_append (G_LIST_STORE (priv->signatures), signature);
 }
 


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