From 9293e73adcad95f8029e0782e38e62beee7cae68 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Sun, 14 Apr 2019 17:30:08 +0100 Subject: [PATCH] boolify: valid_passphrase() --- commands.c | 2 ++ ncrypt/crypt.c | 8 ++++---- ncrypt/crypt_mod.h | 6 +++--- ncrypt/crypt_mod_pgp_gpgme.c | 4 ++-- ncrypt/crypt_mod_smime_gpgme.c | 4 ++-- ncrypt/cryptglue.c | 8 ++++---- ncrypt/cryptglue.h | 4 ++-- ncrypt/ncrypt.h | 2 +- ncrypt/pgp.c | 10 +++++----- ncrypt/pgp.h | 2 +- ncrypt/smime.c | 8 ++++---- ncrypt/smime.h | 2 +- 12 files changed, 31 insertions(+), 29 deletions(-) diff --git a/commands.c b/commands.c index 492898753..85fa0e3ba 100644 --- a/commands.c +++ b/commands.c @@ -557,7 +557,9 @@ static int pipe_message(struct Mailbox *m, struct EmailList *el, char *cmd, mutt_parse_mime_message(m, en->email); if ((en->email->security & SEC_ENCRYPT) && !crypt_valid_passphrase(en->email->security)) + { return 1; + } } mutt_endwin(); diff --git a/ncrypt/crypt.c b/ncrypt/crypt.c index a2fe777f6..958df3588 100644 --- a/ncrypt/crypt.c +++ b/ncrypt/crypt.c @@ -136,12 +136,12 @@ static void disable_coredumps(void) /** * crypt_valid_passphrase - Check that we have a usable passphrase, ask if not * @param flags Flags, see #SecurityFlags - * @retval 0 Success - * @retval -1 Failure + * @retval true Success + * @retval false Failed */ -int crypt_valid_passphrase(SecurityFlags flags) +bool crypt_valid_passphrase(SecurityFlags flags) { - int rc = 0; + bool rc = false; #ifndef DEBUG disable_coredumps(); diff --git a/ncrypt/crypt_mod.h b/ncrypt/crypt_mod.h index 147afc157..5902dc408 100644 --- a/ncrypt/crypt_mod.h +++ b/ncrypt/crypt_mod.h @@ -52,13 +52,13 @@ struct CryptModuleSpecs void (*void_passphrase)(void); /** * valid_passphrase - Ensure we have a valid passphrase - * @retval 1 Success - * @retval 0 Failed + * @retval true Success + * @retval false Failed * * If the passphrase is within the expiry time (backend-specific), use it. * If not prompt the user again. */ - int (*valid_passphrase)(void); + bool (*valid_passphrase)(void); /** * decrypt_mime - Decrypt an encrypted MIME part * @param[in] fp_in File containing the encrypted part diff --git a/ncrypt/crypt_mod_pgp_gpgme.c b/ncrypt/crypt_mod_pgp_gpgme.c index 73151ede2..3521d0159 100644 --- a/ncrypt/crypt_mod_pgp_gpgme.c +++ b/ncrypt/crypt_mod_pgp_gpgme.c @@ -46,9 +46,9 @@ static void pgp_gpgme_void_passphrase(void) * * This is handled by gpg-agent. */ -static int pgp_gpgme_valid_passphrase(void) +static bool pgp_gpgme_valid_passphrase(void) { - return 1; + return true; } // clang-format off diff --git a/ncrypt/crypt_mod_smime_gpgme.c b/ncrypt/crypt_mod_smime_gpgme.c index c16cebd1d..afd7b7342 100644 --- a/ncrypt/crypt_mod_smime_gpgme.c +++ b/ncrypt/crypt_mod_smime_gpgme.c @@ -46,9 +46,9 @@ static void smime_gpgme_void_passphrase(void) * * This is handled by gpg-agent. */ -static int smime_gpgme_valid_passphrase(void) +static bool smime_gpgme_valid_passphrase(void) { - return 1; + return true; } // clang-format off diff --git a/ncrypt/cryptglue.c b/ncrypt/cryptglue.c index 7f4cac705..d95deb358 100644 --- a/ncrypt/cryptglue.c +++ b/ncrypt/cryptglue.c @@ -177,12 +177,12 @@ void crypt_pgp_void_passphrase(void) /** * crypt_pgp_valid_passphrase - Wrapper for CryptModuleSpecs::valid_passphrase() */ -int crypt_pgp_valid_passphrase(void) +bool crypt_pgp_valid_passphrase(void) { if (CRYPT_MOD_CALL_CHECK(PGP, valid_passphrase)) return CRYPT_MOD_CALL(PGP, valid_passphrase)(); - return 0; + return false; } /** @@ -358,12 +358,12 @@ void crypt_smime_void_passphrase(void) /** * crypt_smime_valid_passphrase - Wrapper for CryptModuleSpecs::valid_passphrase() */ -int crypt_smime_valid_passphrase(void) +bool crypt_smime_valid_passphrase(void) { if (CRYPT_MOD_CALL_CHECK(SMIME, valid_passphrase)) return CRYPT_MOD_CALL(SMIME, valid_passphrase)(); - return 0; + return false; } /** diff --git a/ncrypt/cryptglue.h b/ncrypt/cryptglue.h index e169b52a1..3a787cb0c 100644 --- a/ncrypt/cryptglue.h +++ b/ncrypt/cryptglue.h @@ -35,7 +35,7 @@ void crypt_pgp_invoke_import(const char *fname); void crypt_pgp_set_sender(const char *sender); struct Body *crypt_pgp_sign_message(struct Body *a); struct Body *crypt_pgp_traditional_encryptsign(struct Body *a, int flags, char *keylist); -int crypt_pgp_valid_passphrase(void); +bool crypt_pgp_valid_passphrase(void); int crypt_pgp_verify_one(struct Body *sigbdy, struct State *s, const char *tempf); void crypt_pgp_void_passphrase(void); @@ -44,7 +44,7 @@ char * crypt_smime_find_keys(struct Address *addrlist, bool oppenc_mode); void crypt_smime_invoke_import(char *infile, char *mailbox); void crypt_smime_set_sender(const char *sender); struct Body *crypt_smime_sign_message(struct Body *a); -int crypt_smime_valid_passphrase(void); +bool crypt_smime_valid_passphrase(void); int crypt_smime_verify_one(struct Body *sigbdy, struct State *s, const char *tempf); void crypt_smime_void_passphrase(void); diff --git a/ncrypt/ncrypt.h b/ncrypt/ncrypt.h index 85a6dbb92..01f40bf41 100644 --- a/ncrypt/ncrypt.h +++ b/ncrypt/ncrypt.h @@ -186,7 +186,7 @@ void crypt_forget_passphrase(void); int crypt_get_keys(struct Email *msg, char **keylist, bool oppenc_mode); void crypt_opportunistic_encrypt(struct Email *msg); SecurityFlags crypt_query(struct Body *m); -int crypt_valid_passphrase(SecurityFlags flags); +bool crypt_valid_passphrase(SecurityFlags flags); SecurityFlags mutt_is_application_pgp(struct Body *m); SecurityFlags mutt_is_application_smime(struct Body *m); SecurityFlags mutt_is_malformed_multipart_pgp_encrypted(struct Body *b); diff --git a/ncrypt/pgp.c b/ncrypt/pgp.c index 922107288..59b736d58 100644 --- a/ncrypt/pgp.c +++ b/ncrypt/pgp.c @@ -89,20 +89,20 @@ void pgp_class_void_passphrase(void) /** * pgp_class_valid_passphrase - Implements CryptModuleSpecs::valid_passphrase() */ -int pgp_class_valid_passphrase(void) +bool pgp_class_valid_passphrase(void) { time_t now = time(NULL); if (pgp_use_gpg_agent()) { *PgpPass = '\0'; - return 1; /* handled by gpg-agent */ + return true; /* handled by gpg-agent */ } if (now < PgpExptime) { /* Use cached copy. */ - return 1; + return true; } pgp_class_void_passphrase(); @@ -110,12 +110,12 @@ int pgp_class_valid_passphrase(void) if (mutt_get_password(_("Enter PGP passphrase:"), PgpPass, sizeof(PgpPass)) == 0) { PgpExptime = mutt_date_add_timeout(time(NULL), C_PgpTimeout); - return 1; + return true; } else PgpExptime = 0; - return 0; + return false; } /** diff --git a/ncrypt/pgp.h b/ncrypt/pgp.h index ff73498f3..922527095 100644 --- a/ncrypt/pgp.h +++ b/ncrypt/pgp.h @@ -53,7 +53,7 @@ int pgp_class_application_handler(struct Body *m, struct State *s); int pgp_class_encrypted_handler(struct Body *a, struct State *s); void pgp_class_extract_key_from_attachment(FILE *fp, struct Body *top); void pgp_class_void_passphrase(void); -int pgp_class_valid_passphrase(void); +bool pgp_class_valid_passphrase(void); int pgp_class_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile); struct Body *pgp_class_traditional_encryptsign(struct Body *a, SecurityFlags flags, char *keylist); diff --git a/ncrypt/smime.c b/ncrypt/smime.c index 555a55036..2fb9b91fd 100644 --- a/ncrypt/smime.c +++ b/ncrypt/smime.c @@ -168,14 +168,14 @@ void smime_class_void_passphrase(void) /** * smime_class_valid_passphrase - Implements CryptModuleSpecs::valid_passphrase() */ -int smime_class_valid_passphrase(void) +bool smime_class_valid_passphrase(void) { time_t now = time(NULL); if (now < SmimeExptime) { /* Use cached copy. */ - return 1; + return true; } smime_class_void_passphrase(); @@ -183,12 +183,12 @@ int smime_class_valid_passphrase(void) if (mutt_get_password(_("Enter S/MIME passphrase:"), SmimePass, sizeof(SmimePass)) == 0) { SmimeExptime = mutt_date_add_timeout(time(NULL), C_SmimeTimeout); - return 1; + return true; } else SmimeExptime = 0; - return 0; + return false; } /* diff --git a/ncrypt/smime.h b/ncrypt/smime.h index d03046d70..73a205ed3 100644 --- a/ncrypt/smime.h +++ b/ncrypt/smime.h @@ -56,7 +56,7 @@ void smime_class_getkeys(struct Envelope *env); void smime_class_invoke_import(char *infile, char *mailbox); int smime_class_send_menu(struct Email *msg); struct Body *smime_class_sign_message(struct Body *a); -int smime_class_valid_passphrase(void); +bool smime_class_valid_passphrase(void); int smime_class_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile); int smime_class_verify_sender(struct Email *e); void smime_class_void_passphrase(void); -- 2.40.0