From 1d2158ccd21b09e41a1212a928e9a907156dbbea Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Fri, 8 Jun 2018 15:31:52 +0100 Subject: [PATCH] fold CryptModuleFunctions into CryptModuleSpecs --- ncrypt/crypt_mod.h | 39 ++++++++-------------- ncrypt/crypt_mod_pgp_classic.c | 53 +++++++++++++++--------------- ncrypt/crypt_mod_pgp_gpgme.c | 56 ++++++++++++++++++-------------- ncrypt/crypt_mod_smime_classic.c | 53 +++++++++++++++--------------- ncrypt/crypt_mod_smime_gpgme.c | 53 +++++++++++++++--------------- 5 files changed, 126 insertions(+), 128 deletions(-) diff --git a/ncrypt/crypt_mod.h b/ncrypt/crypt_mod.h index f918be1ed..1ad8402f5 100644 --- a/ncrypt/crypt_mod.h +++ b/ncrypt/crypt_mod.h @@ -23,8 +23,8 @@ #ifndef _NCRYPT_CRYPT_MOD_H #define _NCRYPT_CRYPT_MOD_H +#include #include -#include "ncrypt.h" struct Address; struct Body; @@ -33,12 +33,14 @@ struct Header; struct State; /** - * struct CryptModuleFunctions - Crypto API for signing/verifying/encrypting + * struct CryptModuleSpecs - Crypto API * - * A structure to keep all crypto module functions together. + * A structure to describe a crypto module. */ -struct CryptModuleFunctions +struct CryptModuleSpecs { + int identifier; /**< Identifying bit */ + /* Common/General functions */ void (*init)(void); void (*void_passphrase)(void); @@ -68,34 +70,21 @@ struct CryptModuleFunctions void (*smime_invoke_import)(char *infile, char *mailbox); }; -/** - * struct CryptModuleSpecs - Crypto API - * - * A structure to describe a crypto module. - */ -struct CryptModuleSpecs -{ - int identifier; /**< Identifying bit */ - struct CryptModuleFunctions functions; -}; - -/* - High Level crypto module interface. - */ +/* High Level crypto module interface */ void crypto_module_register(struct CryptModuleSpecs *specs); struct CryptModuleSpecs *crypto_module_lookup(int identifier); -/** If the crypto module identifier by IDENTIFIER has been registered, - call its function FUNC. Do nothing else. This may be used as an - expression. */ +/* If the crypto module identifier by IDENTIFIER has been registered, + * call its function FUNC. Do nothing else. This may be used as an + * expression. */ #define CRYPT_MOD_CALL_CHECK(identifier, func) \ (crypto_module_lookup(APPLICATION_##identifier) && \ - (crypto_module_lookup(APPLICATION_##identifier))->functions.func) + (crypto_module_lookup(APPLICATION_##identifier))->func) -/** Call the function FUNC in the crypto module identified by - IDENTIFIER. This may be used as an expression. */ +/* Call the function FUNC in the crypto module identified by + * IDENTIFIER. This may be used as an expression. */ #define CRYPT_MOD_CALL(identifier, func) \ - *(crypto_module_lookup(APPLICATION_##identifier))->functions.func + *(crypto_module_lookup(APPLICATION_##identifier))->func #endif /* _NCRYPT_CRYPT_MOD_H */ diff --git a/ncrypt/crypt_mod_pgp_classic.c b/ncrypt/crypt_mod_pgp_classic.c index 861ff13b1..0c2bce991 100644 --- a/ncrypt/crypt_mod_pgp_classic.c +++ b/ncrypt/crypt_mod_pgp_classic.c @@ -121,32 +121,33 @@ static void crypt_mod_pgp_extract_keys_from_attachment_list(FILE *fp, int tag, pgp_extract_keys_from_attachment_list(fp, tag, top); } +// clang-format off struct CryptModuleSpecs crypt_mod_pgp_classic = { APPLICATION_PGP, - { - NULL, /* init */ - crypt_mod_pgp_void_passphrase, - crypt_mod_pgp_valid_passphrase, - crypt_mod_pgp_decrypt_mime, - crypt_mod_pgp_application_handler, - crypt_mod_pgp_encrypted_handler, - crypt_mod_pgp_findkeys, - crypt_mod_pgp_sign_message, - crypt_mod_pgp_verify_one, - crypt_mod_pgp_send_menu, - NULL, - - crypt_mod_pgp_encrypt_message, - crypt_mod_pgp_make_key_attachment, - crypt_mod_pgp_check_traditional, - crypt_mod_pgp_traditional_encryptsign, - crypt_mod_pgp_invoke_getkeys, - crypt_mod_pgp_invoke_import, - crypt_mod_pgp_extract_keys_from_attachment_list, - - NULL, /* smime_getkeys */ - NULL, /* smime_verify_sender */ - NULL, /* smime_build_smime_entity */ - NULL, /* smime_invoke_import */ - }, + + NULL, /* init */ + crypt_mod_pgp_void_passphrase, + crypt_mod_pgp_valid_passphrase, + crypt_mod_pgp_decrypt_mime, + crypt_mod_pgp_application_handler, + crypt_mod_pgp_encrypted_handler, + crypt_mod_pgp_findkeys, + crypt_mod_pgp_sign_message, + crypt_mod_pgp_verify_one, + crypt_mod_pgp_send_menu, + NULL, /* set_sender */ + + crypt_mod_pgp_encrypt_message, + crypt_mod_pgp_make_key_attachment, + crypt_mod_pgp_check_traditional, + crypt_mod_pgp_traditional_encryptsign, + crypt_mod_pgp_invoke_getkeys, + crypt_mod_pgp_invoke_import, + crypt_mod_pgp_extract_keys_from_attachment_list, + + NULL, /* smime_getkeys */ + NULL, /* smime_verify_sender */ + NULL, /* smime_build_smime_entity */ + NULL, /* smime_invoke_import */ }; +// clang-format on diff --git a/ncrypt/crypt_mod_pgp_gpgme.c b/ncrypt/crypt_mod_pgp_gpgme.c index c879a697c..7109c18fb 100644 --- a/ncrypt/crypt_mod_pgp_gpgme.c +++ b/ncrypt/crypt_mod_pgp_gpgme.c @@ -103,41 +103,47 @@ static struct Body *crypt_mod_pgp_encrypt_message(struct Body *a, char *keylist, return pgp_gpgme_encrypt_message(a, keylist, sign); } -#ifdef HAVE_GPGME_OP_EXPORT_KEYS static struct Body *crypt_mod_pgp_make_key_attachment(char *tempf) { +#ifdef HAVE_GPGME_OP_EXPORT_KEYS return pgp_gpgme_make_key_attachment(tempf); -} +#else + return NULL; #endif +} static void crypt_mod_pgp_set_sender(const char *sender) { mutt_gpgme_set_sender(sender); } +// clang-format off struct CryptModuleSpecs crypt_mod_pgp_gpgme = { APPLICATION_PGP, - { - /* Common. */ - crypt_mod_pgp_init, crypt_mod_pgp_void_passphrase, crypt_mod_pgp_valid_passphrase, - crypt_mod_pgp_decrypt_mime, crypt_mod_pgp_application_handler, - crypt_mod_pgp_encrypted_handler, crypt_mod_pgp_findkeys, crypt_mod_pgp_sign_message, - crypt_mod_pgp_verify_one, crypt_mod_pgp_send_menu, crypt_mod_pgp_set_sender, - - /* PGP specific. */ - crypt_mod_pgp_encrypt_message, -#ifdef HAVE_GPGME_OP_EXPORT_KEYS - crypt_mod_pgp_make_key_attachment, -#else - NULL, -#endif - crypt_mod_pgp_check_traditional, NULL, /* pgp_traditional_encryptsign */ - NULL, /* pgp_invoke_getkeys */ - crypt_mod_pgp_invoke_import, NULL, /* pgp_extract_keys_from_attachment_list */ - - NULL, /* smime_getkeys */ - NULL, /* smime_verify_sender */ - NULL, /* smime_build_smime_entity */ - NULL, /* smime_invoke_import */ - }, + + crypt_mod_pgp_init, + crypt_mod_pgp_void_passphrase, + crypt_mod_pgp_valid_passphrase, + crypt_mod_pgp_decrypt_mime, + crypt_mod_pgp_application_handler, + crypt_mod_pgp_encrypted_handler, + crypt_mod_pgp_findkeys, + crypt_mod_pgp_sign_message, + crypt_mod_pgp_verify_one, + crypt_mod_pgp_send_menu, + crypt_mod_pgp_set_sender, + + crypt_mod_pgp_encrypt_message, + crypt_mod_pgp_make_key_attachment, + crypt_mod_pgp_check_traditional, + NULL, /* pgp_traditional_encryptsign */ + NULL, /* pgp_invoke_getkeys */ + crypt_mod_pgp_invoke_import, + NULL, /* pgp_extract_keys_from_attachment_list */ + + NULL, /* smime_getkeys */ + NULL, /* smime_verify_sender */ + NULL, /* smime_build_smime_entity */ + NULL, /* smime_invoke_import */ }; +// clang-format on diff --git a/ncrypt/crypt_mod_smime_classic.c b/ncrypt/crypt_mod_smime_classic.c index af64f4113..08bf1aa09 100644 --- a/ncrypt/crypt_mod_smime_classic.c +++ b/ncrypt/crypt_mod_smime_classic.c @@ -98,32 +98,33 @@ static void crypt_mod_smime_invoke_import(char *infile, char *mailbox) smime_invoke_import(infile, mailbox); } +// clang-format off struct CryptModuleSpecs crypt_mod_smime_classic = { APPLICATION_SMIME, - { - NULL, /* init */ - crypt_mod_smime_void_passphrase, - crypt_mod_smime_valid_passphrase, - crypt_mod_smime_decrypt_mime, - crypt_mod_smime_application_handler, - NULL, /* encrypted_handler */ - crypt_mod_smime_findkeys, - crypt_mod_smime_sign_message, - crypt_mod_smime_verify_one, - crypt_mod_smime_send_menu, - NULL, - - NULL, /* pgp_encrypt_message */ - NULL, /* pgp_make_key_attachment */ - NULL, /* pgp_check_traditional */ - NULL, /* pgp_traditional_encryptsign */ - NULL, /* pgp_invoke_getkeys */ - NULL, /* pgp_invoke_import */ - NULL, /* pgp_extract_keys_from_attachment_list */ - - crypt_mod_smime_getkeys, - crypt_mod_smime_verify_sender, - crypt_mod_smime_build_smime_entity, - crypt_mod_smime_invoke_import, - }, + + NULL, /* init */ + crypt_mod_smime_void_passphrase, + crypt_mod_smime_valid_passphrase, + crypt_mod_smime_decrypt_mime, + crypt_mod_smime_application_handler, + NULL, /* encrypted_handler */ + crypt_mod_smime_findkeys, + crypt_mod_smime_sign_message, + crypt_mod_smime_verify_one, + crypt_mod_smime_send_menu, + NULL, /* set_sender */ + + NULL, /* pgp_encrypt_message */ + NULL, /* pgp_make_key_attachment */ + NULL, /* pgp_check_traditional */ + NULL, /* pgp_traditional_encryptsign */ + NULL, /* pgp_invoke_getkeys */ + NULL, /* pgp_invoke_import */ + NULL, /* pgp_extract_keys_from_attachment_list */ + + crypt_mod_smime_getkeys, + crypt_mod_smime_verify_sender, + crypt_mod_smime_build_smime_entity, + crypt_mod_smime_invoke_import, }; +// clang-format on diff --git a/ncrypt/crypt_mod_smime_gpgme.c b/ncrypt/crypt_mod_smime_gpgme.c index 164daf41a..87755f1e2 100644 --- a/ncrypt/crypt_mod_smime_gpgme.c +++ b/ncrypt/crypt_mod_smime_gpgme.c @@ -93,32 +93,33 @@ static int crypt_mod_smime_verify_sender(struct Header *h) return smime_gpgme_verify_sender(h); } +// clang-format off struct CryptModuleSpecs crypt_mod_smime_gpgme = { APPLICATION_SMIME, - { - crypt_mod_smime_init, - crypt_mod_smime_void_passphrase, - crypt_mod_smime_valid_passphrase, - crypt_mod_smime_decrypt_mime, - crypt_mod_smime_application_handler, - NULL, /* encrypted_handler */ - crypt_mod_smime_findkeys, - crypt_mod_smime_sign_message, - crypt_mod_smime_verify_one, - crypt_mod_smime_send_menu, - NULL, - - NULL, /* pgp_encrypt_message */ - NULL, /* pgp_make_key_attachment */ - NULL, /* pgp_check_traditional */ - NULL, /* pgp_traditional_encryptsign */ - NULL, /* pgp_invoke_getkeys */ - NULL, /* pgp_invoke_import */ - NULL, /* pgp_extract_keys_from_attachment_list */ - - NULL, /* smime_getkeys */ - crypt_mod_smime_verify_sender, - crypt_mod_smime_build_smime_entity, - NULL, /* smime_invoke_import */ - }, + + crypt_mod_smime_init, + crypt_mod_smime_void_passphrase, + crypt_mod_smime_valid_passphrase, + crypt_mod_smime_decrypt_mime, + crypt_mod_smime_application_handler, + NULL, /* encrypted_handler */ + crypt_mod_smime_findkeys, + crypt_mod_smime_sign_message, + crypt_mod_smime_verify_one, + crypt_mod_smime_send_menu, + NULL, /* set_sender */ + + NULL, /* pgp_encrypt_message */ + NULL, /* pgp_make_key_attachment */ + NULL, /* pgp_check_traditional */ + NULL, /* pgp_traditional_encryptsign */ + NULL, /* pgp_invoke_getkeys */ + NULL, /* pgp_invoke_import */ + NULL, /* pgp_extract_keys_from_attachment_list */ + + NULL, /* smime_getkeys */ + crypt_mod_smime_verify_sender, + crypt_mod_smime_build_smime_entity, + NULL, /* smime_invoke_import */ }; +// clang-format on -- 2.40.0