]> granicus.if.org Git - neomutt/commitdiff
flagify PgpKeyValidFlags
authorRichard Russon <rich@flatcap.org>
Thu, 24 Oct 2019 01:59:50 +0000 (02:59 +0100)
committerRichard Russon <rich@flatcap.org>
Sun, 27 Oct 2019 01:12:47 +0000 (01:12 +0000)
ncrypt/pgpkey.c

index 33e381775d67d7c299e2be5ecfb5a78b8b08b4c7..9a39ad6b68b58cef0cd86854321f362c0fb607ec 100644 (file)
@@ -83,6 +83,17 @@ static struct PgpCache *id_defaults = NULL;
 
 static const char trust_flags[] = "?- +";
 
+// clang-format off
+typedef uint8_t PgpKeyValidFlags; ///< Pgp Key valid fields, e.g. #PGP_KV_VALID
+#define PGP_KV_NO_FLAGS       0   ///< No flags are set
+#define PGP_KV_VALID    (1 << 0)  ///< PGP Key ID is valid
+#define PGP_KV_ADDR     (1 << 1)  ///< PGP Key address is valid
+#define PGP_KV_STRING   (1 << 2)  ///< PGP Key name string is valid
+#define PGP_KV_STRONGID (1 << 3)  ///< PGP Key is strong
+// clang-format on
+
+#define PGP_KV_MATCH (PGP_KV_ADDR | PGP_KV_STRING)
+
 /**
  * pgp_key_abilities - Turn PGP key abilities into a string
  * @param flags Flags, see #KeyFlags
@@ -545,13 +556,6 @@ static bool pgp_id_is_valid(struct PgpUid *uid)
   return true;
 }
 
-#define PGP_KV_VALID 1
-#define PGP_KV_ADDR 2
-#define PGP_KV_STRING 4
-#define PGP_KV_STRONGID 8
-
-#define PGP_KV_MATCH (PGP_KV_ADDR | PGP_KV_STRING)
-
 /**
  * pgp_id_matches_addr - Does the key ID match the address
  * @param addr   First email address
@@ -559,29 +563,30 @@ static bool pgp_id_is_valid(struct PgpUid *uid)
  * @param uid    UID of PGP key
  * @retval num Flags, e.g. #PGP_KV_VALID
  */
-static int pgp_id_matches_addr(struct Address *addr, struct Address *u_addr, struct PgpUid *uid)
+static PgpKeyValidFlags pgp_id_matches_addr(struct Address *addr,
+                                            struct Address *u_addr, struct PgpUid *uid)
 {
-  int rc = 0;
+  PgpKeyValidFlags flags = PGP_KV_NO_FLAGS;
 
   if (pgp_id_is_valid(uid))
-    rc |= PGP_KV_VALID;
+    flags |= PGP_KV_VALID;
 
   if (pgp_id_is_strong(uid))
-    rc |= PGP_KV_STRONGID;
+    flags |= PGP_KV_STRONGID;
 
   if (addr->mailbox && u_addr->mailbox &&
       (mutt_str_strcasecmp(addr->mailbox, u_addr->mailbox) == 0))
   {
-    rc |= PGP_KV_ADDR;
+    flags |= PGP_KV_ADDR;
   }
 
   if (addr->personal && u_addr->personal &&
       (mutt_str_strcasecmp(addr->personal, u_addr->personal) == 0))
   {
-    rc |= PGP_KV_STRING;
+    flags |= PGP_KV_STRING;
   }
 
-  return rc;
+  return flags;
 }
 
 /**
@@ -1046,7 +1051,7 @@ struct PgpKeyInfo *pgp_getkeybyaddr(struct Address *a, KeyFlags abilities,
       struct Address *qa = NULL;
       TAILQ_FOREACH(qa, &al, entries)
       {
-        int validity = pgp_id_matches_addr(a, qa, q);
+        PgpKeyValidFlags validity = pgp_id_matches_addr(a, qa, q);
 
         if (validity & PGP_KV_MATCH) /* something matches */
           match = true;