]> granicus.if.org Git - neomutt/commitdiff
add typedef for KeyFlags
authorRichard Russon <rich@flatcap.org>
Wed, 27 Feb 2019 00:14:30 +0000 (00:14 +0000)
committerRichard Russon <rich@flatcap.org>
Fri, 1 Mar 2019 13:10:23 +0000 (13:10 +0000)
ncrypt/crypt_gpgme.c
ncrypt/gnupgparse.c
ncrypt/ncrypt.h
ncrypt/pgpkey.c
ncrypt/pgpkey.h
ncrypt/pgplib.h
ncrypt/smime.c
ncrypt/smime.h

index 35e05addc14e35b8a29b6506240b3ab8d08264a9..fe029854b2206a76f7db14056f8905ef84e4febe 100644 (file)
@@ -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;
index f695fddf039d0d6966cacec465899a88880be49b..6b0a7844688836e8b2b263a6b70fe2cced326776 100644 (file)
@@ -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;
index 8a5dd8405764a20db4efc6c42c2c7fe177306a65..b79fa8c710d6f3bda1068b813580f27d2ccbbcc0 100644 (file)
@@ -50,6 +50,7 @@
 #define MUTT_NCRYPT_NCRYPT_H
 
 #include <stdbool.h>
+#include <stdint.h>
 #include <stdio.h>
 
 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
index 28685ad65923baeca6f91cb3452169f4334a0723..b7fb4d302dd814f60d0fbd79f7b61c8f8cf4cdcc 100644 (file)
@@ -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;
index 774974268d8313f93ca5a419e1ebae823749e41f..20599522fa5ca1c467f189f9255b8d252b725718 100644 (file)
@@ -24,6 +24,7 @@
 #define MUTT_NCRYPT_PGPKEY_H
 
 #include <stdbool.h>
+#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 */
index 393423afa57cac2eba4d3a3fb4e4491924b2cd30..1aeda8925e838204a14a492ce5903b40ef648dad 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <stdbool.h>
 #include <time.h>
+#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;
index 0ef287667c994810e77cdb9bb89814d29827c769..30b516f31910b925df51a291c5846936ea854814 100644 (file)
@@ -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];
index 044b861a7c4ff598e1c6519c0567e0ff46c5feb3..0be6555f3b25e8fa8a9d3cbb92a943c79faf4519 100644 (file)
@@ -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;
 };