From: Richard Russon Date: Thu, 24 Oct 2019 01:59:50 +0000 (+0100) Subject: flagify PgpKeyValidFlags X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3b181ac91127c2f8af5a27bd01401684c04bc7b0;p=neomutt flagify PgpKeyValidFlags --- diff --git a/ncrypt/pgpkey.c b/ncrypt/pgpkey.c index 33e381775..9a39ad6b6 100644 --- a/ncrypt/pgpkey.c +++ b/ncrypt/pgpkey.c @@ -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;