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) */
};
/**
* 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];
/**
* 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';
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;
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;
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;
/**
* 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;
/**
* 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);
* 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
* 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;
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;
#define MUTT_NCRYPT_NCRYPT_H
#include <stdbool.h>
+#include <stdint.h>
#include <stdio.h>
struct Address;
#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
/**
* 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];
/**
* 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';
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;
* 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];
/**
* 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)
/**
* 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;
#define MUTT_NCRYPT_PGPKEY_H
#include <stdbool.h>
+#include "ncrypt.h"
struct Address;
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 */
#include <stdbool.h>
#include <time.h>
+#include "ncrypt.h"
/**
* struct PgpUid - PGP User ID
char *keyid;
char *fingerprint;
struct PgpUid *address;
- int flags;
+ KeyFlags flags;
short keylen;
time_t gen_time;
int numalg;
/**
* 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];
/**
* 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;
/**
* 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;
/**
* 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];
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;
};