From: Richard Russon Date: Wed, 27 Feb 2019 00:14:30 +0000 (+0000) Subject: add typedef for KeyFlags X-Git-Tag: 2019-10-25~347^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1a7431a97b0ae18e90947a9332cdc601c598dc38;p=neomutt add typedef for KeyFlags --- diff --git a/ncrypt/crypt_gpgme.c b/ncrypt/crypt_gpgme.c index 35e05addc..fe029854b 100644 --- a/ncrypt/crypt_gpgme.c +++ b/ncrypt/crypt_gpgme.c @@ -114,7 +114,7 @@ struct CryptKeyInfo gpgme_key_t kobj; int idx; /**< and the user ID at this index */ const char *uid; /**< and for convenience point to this user ID */ - unsigned int flags; /**< global and per uid flags (for convenience) */ + KeyFlags flags; /**< global and per uid flags (for convenience) */ gpgme_validity_t validity; /**< uid validity (cached for convenience) */ }; @@ -516,12 +516,12 @@ static const char *crypt_fpr_or_lkeyid(struct CryptKeyInfo *k) /** * crypt_key_abilities - Parse key flags into a string - * @param flags Flags, e.g. #KEYFLAG_CANENCRYPT + * @param flags Flags, see #KeyFlags * @retval ptr Flag string * * Note: The string is statically allocated. */ -static char *crypt_key_abilities(int flags) +static char *crypt_key_abilities(KeyFlags flags) { static char buf[3]; @@ -546,12 +546,12 @@ static char *crypt_key_abilities(int flags) /** * crypt_flags - Parse the key flags into a single character - * @param flags Flags, e.g. #KEYFLAG_EXPIRED + * @param flags Flags, see #KeyFlags * @retval char Flag character * * The returned character describes the most important flag. */ -static char crypt_flags(int flags) +static char crypt_flags(KeyFlags flags) { if (flags & KEYFLAG_REVOKED) return 'R'; @@ -3312,7 +3312,7 @@ static const char *crypt_format_str(char *buf, size_t buflen, size_t col, int co unsigned long data, MuttFormatFlags flags) { char fmt[128]; - int kflags = 0; + KeyFlags kflags = KEYFLAG_NO_FLAGS; int optional = (flags & MUTT_FORMAT_OPTIONAL); const char *s = NULL; @@ -4505,7 +4505,7 @@ static struct CryptKeyInfo *get_candidates(struct ListHead *hints, unsigned int while (!(err = gpgme_op_keylist_next(ctx, &key))) { - unsigned int flags = 0; + KeyFlags flags = KEYFLAG_NO_FLAGS; if (key_check_cap(key, KEY_CAP_CAN_ENCRYPT)) flags |= KEYFLAG_CANENCRYPT; @@ -4556,7 +4556,7 @@ static struct CryptKeyInfo *get_candidates(struct ListHead *hints, unsigned int while (!(err = gpgme_op_keylist_next(ctx, &key))) { - unsigned int flags = KEYFLAG_ISX509; + KeyFlags flags = KEYFLAG_ISX509; if (key_check_cap(key, KEY_CAP_CAN_ENCRYPT)) flags |= KEYFLAG_CANENCRYPT; @@ -4828,14 +4828,14 @@ static struct CryptKeyInfo *crypt_select_key(struct CryptKeyInfo *keys, /** * crypt_getkeybyaddr - Find a key by email address * @param[in] a Address to match - * @param[in] abilities Abilities to match, e.g. #KEYFLAG_CANENCRYPT + * @param[in] abilities Abilities to match, see #KeyFlags * @param[in] app Application type, e.g. #APPLICATION_PGP * @param[out] forced_valid Set to true if user overrode key's validity * @param[in] oppenc_mode If true, use opportunistic encryption * @retval ptr Matching key */ static struct CryptKeyInfo *crypt_getkeybyaddr(struct Address *a, - short abilities, unsigned int app, + KeyFlags abilities, unsigned int app, int *forced_valid, bool oppenc_mode) { struct Address *r = NULL, *p = NULL; @@ -4958,12 +4958,12 @@ static struct CryptKeyInfo *crypt_getkeybyaddr(struct Address *a, /** * crypt_getkeybystr - Find a key by string * @param[in] p String to match - * @param[in] abilities Abilities to match, e.g. #KEYFLAG_CANENCRYPT + * @param[in] abilities Abilities to match, see #KeyFlags * @param[in] app Application type, e.g. #APPLICATION_PGP * @param[out] forced_valid Set to true if user overrode key's validity * @retval ptr Matching key */ -static struct CryptKeyInfo *crypt_getkeybystr(char *p, short abilities, +static struct CryptKeyInfo *crypt_getkeybystr(char *p, KeyFlags abilities, unsigned int app, int *forced_valid) { struct ListHead hints = STAILQ_HEAD_INITIALIZER(hints); @@ -5029,7 +5029,7 @@ static struct CryptKeyInfo *crypt_getkeybystr(char *p, short abilities, * crypt_ask_for_key - Ask the user for a key * @param[in] tag Prompt to display * @param[in] whatfor Label to use (OPTIONAL) - * @param[in] abilities Flags, e.g. #KEYFLAG_CANSIGN + * @param[in] abilities Flags, see #KeyFlags * @param[in] app Application type, e.g. #APPLICATION_PGP * @param[out] forced_valid Set to true if user overrode key's validity * @retval ptr Copy of the selected key @@ -5037,7 +5037,7 @@ static struct CryptKeyInfo *crypt_getkeybystr(char *p, short abilities, * If whatfor is not null use it as default and store it under that label as * the next default. */ -static struct CryptKeyInfo *crypt_ask_for_key(char *tag, char *whatfor, short abilities, +static struct CryptKeyInfo *crypt_ask_for_key(char *tag, char *whatfor, KeyFlags abilities, unsigned int app, int *forced_valid) { struct CryptKeyInfo *key = NULL; diff --git a/ncrypt/gnupgparse.c b/ncrypt/gnupgparse.c index f695fddf0..6b0a78446 100644 --- a/ncrypt/gnupgparse.c +++ b/ncrypt/gnupgparse.c @@ -135,7 +135,7 @@ static struct PgpKeyInfo *parse_pub_line(char *buf, int *is_subkey, struct PgpKe bool is_fpr = false; char *pend = NULL, *p = NULL; int trust = 0; - int flags = 0; + KeyFlags flags = KEYFLAG_NO_FLAGS; struct PgpKeyInfo tmp; *is_subkey = 0; diff --git a/ncrypt/ncrypt.h b/ncrypt/ncrypt.h index 8a5dd8405..b79fa8c71 100644 --- a/ncrypt/ncrypt.h +++ b/ncrypt/ncrypt.h @@ -50,6 +50,7 @@ #define MUTT_NCRYPT_NCRYPT_H #include +#include #include struct Address; @@ -156,6 +157,8 @@ extern char *C_SmimeVerifyOpaqueCommand; #define WithCrypto 0 #endif +typedef uint16_t KeyFlags; ///< Flags describing PGP/SMIME keys, e.g. #KEYFLAG_CANSIGN +#define KEYFLAG_NO_FLAGS 0 ///< No flags are set #define KEYFLAG_CANSIGN (1 << 0) ///< Key is suitable for signing #define KEYFLAG_CANENCRYPT (1 << 1) ///< Key is suitable for encryption #define KEYFLAG_ISX509 (1 << 2) ///< Key is an X.509 key diff --git a/ncrypt/pgpkey.c b/ncrypt/pgpkey.c index 28685ad65..b7fb4d302 100644 --- a/ncrypt/pgpkey.c +++ b/ncrypt/pgpkey.c @@ -82,12 +82,12 @@ static const char trust_flags[] = "?- +"; /** * pgp_key_abilities - Turn PGP key abilities into a string - * @param flags Flags, e.g. #KEYFLAG_CANENCRYPT + * @param flags Flags, see #KeyFlags * @retval ptr Abilities string * * @note This returns a pointer to a static buffer */ -static char *pgp_key_abilities(int flags) +static char *pgp_key_abilities(KeyFlags flags) { static char buf[3]; @@ -112,10 +112,10 @@ static char *pgp_key_abilities(int flags) /** * pgp_flags - Turn PGP key flags into a string - * @param flags Flags, e.g. #KEYFLAG_REVOKED + * @param flags Flags, see #KeyFlags * @retval char Flag character */ -static char pgp_flags(int flags) +static char pgp_flags(KeyFlags flags) { if (flags & KEYFLAG_REVOKED) return 'R'; @@ -177,7 +177,7 @@ static const char *pgp_entry_fmt(char *buf, size_t buflen, size_t col, int cols, unsigned long data, MuttFormatFlags flags) { char fmt[128]; - int kflags = 0; + KeyFlags kflags = KEYFLAG_NO_FLAGS; int optional = (flags & MUTT_FORMAT_OPTIONAL); struct PgpEntry *entry = (struct PgpEntry *) data; @@ -812,11 +812,12 @@ static struct PgpKeyInfo *pgp_select_key(struct PgpKeyInfo *keys, * pgp_ask_for_key - Ask the user for a PGP key * @param tag Prompt for the user * @param whatfor Use for key, e.g. "signing" - * @param abilities Abilities to match, e.g. #KEYFLAG_CANENCRYPT + * @param abilities Abilities to match, see #KeyFlags * @param keyring PGP keyring to use * @retval ptr Selected PGP key */ -struct PgpKeyInfo *pgp_ask_for_key(char *tag, char *whatfor, short abilities, enum PgpRing keyring) +struct PgpKeyInfo *pgp_ask_for_key(char *tag, char *whatfor, KeyFlags abilities, + enum PgpRing keyring) { struct PgpKeyInfo *key = NULL; char resp[128]; @@ -981,12 +982,12 @@ static struct PgpKeyInfo **pgp_get_lastp(struct PgpKeyInfo *p) /** * pgp_getkeybyaddr - Find a PGP key by address * @param a Email address to match - * @param abilities Abilities to match, e.g. #KEYFLAG_CANENCRYPT + * @param abilities Abilities to match, see #KeyFlags * @param keyring PGP keyring to use * @param oppenc_mode If true, use opportunistic encryption * @retval ptr Matching PGP key */ -struct PgpKeyInfo *pgp_getkeybyaddr(struct Address *a, short abilities, +struct PgpKeyInfo *pgp_getkeybyaddr(struct Address *a, KeyFlags abilities, enum PgpRing keyring, bool oppenc_mode) { if (!a) @@ -1117,11 +1118,11 @@ struct PgpKeyInfo *pgp_getkeybyaddr(struct Address *a, short abilities, /** * pgp_getkeybystr - Find a PGP key by string * @param p String to match - * @param abilities Abilities to match, e.g. #KEYFLAG_CANENCRYPT + * @param abilities Abilities to match, see #KeyFlags * @param keyring PGP keyring to use * @retval ptr Matching PGP key */ -struct PgpKeyInfo *pgp_getkeybystr(char *p, short abilities, enum PgpRing keyring) +struct PgpKeyInfo *pgp_getkeybystr(char *p, KeyFlags abilities, enum PgpRing keyring) { struct ListHead hints = STAILQ_HEAD_INITIALIZER(hints); struct PgpKeyInfo *keys = NULL; diff --git a/ncrypt/pgpkey.h b/ncrypt/pgpkey.h index 774974268..20599522f 100644 --- a/ncrypt/pgpkey.h +++ b/ncrypt/pgpkey.h @@ -24,6 +24,7 @@ #define MUTT_NCRYPT_PGPKEY_H #include +#include "ncrypt.h" struct Address; @@ -38,8 +39,8 @@ enum PgpRing struct Body *pgp_class_make_key_attachment(void); -struct PgpKeyInfo *pgp_ask_for_key(char *tag, char *whatfor, short abilities, enum PgpRing keyring); -struct PgpKeyInfo *pgp_getkeybyaddr(struct Address *a, short abilities, enum PgpRing keyring, bool oppenc_mode); -struct PgpKeyInfo *pgp_getkeybystr(char *p, short abilities, enum PgpRing keyring); +struct PgpKeyInfo *pgp_ask_for_key(char *tag, char *whatfor, KeyFlags abilities, enum PgpRing keyring); +struct PgpKeyInfo *pgp_getkeybyaddr(struct Address *a, KeyFlags abilities, enum PgpRing keyring, bool oppenc_mode); +struct PgpKeyInfo *pgp_getkeybystr(char *p, KeyFlags abilities, enum PgpRing keyring); #endif /* MUTT_NCRYPT_PGPKEY_H */ diff --git a/ncrypt/pgplib.h b/ncrypt/pgplib.h index 393423afa..1aeda8925 100644 --- a/ncrypt/pgplib.h +++ b/ncrypt/pgplib.h @@ -26,6 +26,7 @@ #include #include +#include "ncrypt.h" /** * struct PgpUid - PGP User ID @@ -47,7 +48,7 @@ struct PgpKeyInfo char *keyid; char *fingerprint; struct PgpUid *address; - int flags; + KeyFlags flags; short keylen; time_t gen_time; int numalg; diff --git a/ncrypt/smime.c b/ncrypt/smime.c index 0ef287667..30b516f31 100644 --- a/ncrypt/smime.c +++ b/ncrypt/smime.c @@ -411,12 +411,12 @@ static pid_t smime_invoke(FILE **smimein, FILE **smimeout, FILE **smimeerr, /** * smime_key_flags - Turn SMIME key flags into a string - * @param flags Flags, e.g. #KEYFLAG_CANENCRYPT + * @param flags Flags, see #KeyFlags * @retval ptr Flag string * * Note: The string is statically allocated. */ -static char *smime_key_flags(int flags) +static char *smime_key_flags(KeyFlags flags) { static char buf[3]; @@ -779,12 +779,12 @@ static struct SmimeKey *smime_get_key_by_hash(char *hash, bool public) /** * smime_get_key_by_addr - Find an SIME key by address * @param mailbox Email address to match - * @param abilities Abilities to match, e.g. #KEYFLAG_CANENCRYPT + * @param abilities Abilities to match, see #KeyFlags * @param public If true, only get the public keys * @param may_ask If true, the user may be asked to select a key * @retval ptr Matching key */ -static struct SmimeKey *smime_get_key_by_addr(char *mailbox, short abilities, +static struct SmimeKey *smime_get_key_by_addr(char *mailbox, KeyFlags abilities, bool public, bool may_ask) { struct SmimeKey *results = NULL, *result = NULL; @@ -859,11 +859,11 @@ static struct SmimeKey *smime_get_key_by_addr(char *mailbox, short abilities, /** * smime_get_key_by_str - Find an SMIME key by string * @param str String to match - * @param abilities Abilities to match, e.g. #KEYFLAG_CANENCRYPT + * @param abilities Abilities to match, see #KeyFlags * @param public If true, only get the public keys * @retval ptr Matching key */ -static struct SmimeKey *smime_get_key_by_str(char *str, short abilities, bool public) +static struct SmimeKey *smime_get_key_by_str(char *str, KeyFlags abilities, bool public) { struct SmimeKey *results = NULL, *result = NULL; struct SmimeKey *matches = NULL; @@ -905,11 +905,11 @@ static struct SmimeKey *smime_get_key_by_str(char *str, short abilities, bool pu /** * smime_ask_for_key - Ask the user to select a key * @param prompt Prompt to show the user - * @param abilities Abilities to match, e.g. #KEYFLAG_CANENCRYPT + * @param abilities Abilities to match, see #KeyFlags * @param public If true, only get the public keys * @retval ptr Selected SMIME key */ -static struct SmimeKey *smime_ask_for_key(char *prompt, short abilities, bool public) +static struct SmimeKey *smime_ask_for_key(char *prompt, KeyFlags abilities, bool public) { struct SmimeKey *key = NULL; char resp[128]; diff --git a/ncrypt/smime.h b/ncrypt/smime.h index 044b861a7..0be6555f3 100644 --- a/ncrypt/smime.h +++ b/ncrypt/smime.h @@ -43,7 +43,7 @@ struct SmimeKey char *label; char *issuer; char trust; /**< i=Invalid r=revoked e=expired u=unverified v=verified t=trusted */ - int flags; + KeyFlags flags; struct SmimeKey *next; };