fix regressions
[apps/madmutt.git] / crypt-mod.h
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 2004 g10 Code GmbH
4  *
5  * This file is part of mutt-ng, see http://www.muttng.org/.
6  * It's licensed under the GNU General Public License,
7  * please see the file GPL in the top level source directory.
8  */
9
10 #ifndef CRYPTOGRAPHY_H
11 #define CRYPTOGRAPHY_H
12
13 #include "mutt.h"
14 #include "mutt_crypt.h"
15
16 #define CRYPTO_SUPPORT(identifier) (WithCrypto & APPLICATION_ ## identifier)
17
18
19 /* 
20     Type defintions for crypto module functions.
21  */
22 typedef void (*crypt_func_void_passphrase_t) (void);
23 typedef int (*crypt_func_valid_passphrase_t) (void);
24
25 typedef int (*crypt_func_decrypt_mime_t) (FILE * a, FILE ** b,
26                                           BODY * c, BODY ** d);
27
28 typedef int (*crypt_func_application_handler_t) (BODY * m, STATE * s);
29 typedef int (*crypt_func_encrypted_handler_t) (BODY * m, STATE * s);
30
31 typedef void (*crypt_func_pgp_invoke_getkeys_t) (ADDRESS * addr);
32 typedef int (*crypt_func_pgp_check_traditional_t) (FILE * fp, BODY * b,
33                                                    int tagged_only);
34 typedef BODY *(*crypt_func_pgp_traditional_encryptsign_t) (BODY * a,
35                                                            int flags,
36                                                            char *keylist);
37 typedef BODY *(*crypt_func_pgp_make_key_attachment_t) (char *tempf);
38 typedef char *(*crypt_func_findkeys_t) (ADDRESS * to,
39                                         ADDRESS * cc, ADDRESS * bcc);
40 typedef BODY *(*crypt_func_sign_message_t) (BODY * a);
41 typedef BODY *(*crypt_func_pgp_encrypt_message_t) (BODY * a, char *keylist,
42                                                    int sign);
43 typedef void (*crypt_func_pgp_invoke_import_t) (const char *fname);
44 typedef int (*crypt_func_verify_one_t) (BODY * sigbdy, STATE * s,
45                                         const char *tempf);
46 typedef void (*crypt_func_pgp_extract_keys_from_attachment_list_t)
47      (FILE * fp, int tag, BODY * top);
48
49 typedef int (*crypt_func_send_menu_t) (HEADER * msg, int *redraw);
50
51  /* (SMIME) */
52 typedef void (*crypt_func_smime_getkeys_t) (ENVELOPE * env);
53 typedef int (*crypt_func_smime_verify_sender_t) (HEADER * h);
54
55 typedef BODY *(*crypt_func_smime_build_smime_entity_t) (BODY * a,
56                                                         char *certlist);
57
58 typedef void (*crypt_func_smime_invoke_import_t) (char *infile,
59                                                   char *mailbox);
60
61 typedef void (*crypt_func_init_t) (void);
62
63
64 /*
65    A structure to keep all crypto module fucntions together.
66  */
67 typedef struct crypt_module_functions {
68     /* Common/General functions.  */
69     crypt_func_init_t init;
70     crypt_func_void_passphrase_t void_passphrase;
71     crypt_func_valid_passphrase_t valid_passphrase;
72     crypt_func_decrypt_mime_t decrypt_mime;
73     crypt_func_application_handler_t application_handler;
74     crypt_func_encrypted_handler_t encrypted_handler;
75     crypt_func_findkeys_t findkeys;
76     crypt_func_sign_message_t sign_message;
77     crypt_func_verify_one_t verify_one;
78     crypt_func_send_menu_t send_menu;
79
80     /* PGP specific functions.  */
81     crypt_func_pgp_encrypt_message_t pgp_encrypt_message;
82     crypt_func_pgp_make_key_attachment_t pgp_make_key_attachment;
83     crypt_func_pgp_check_traditional_t pgp_check_traditional;
84     crypt_func_pgp_traditional_encryptsign_t pgp_traditional_encryptsign;
85     crypt_func_pgp_invoke_getkeys_t pgp_invoke_getkeys;
86     crypt_func_pgp_invoke_import_t pgp_invoke_import;
87
88     crypt_func_pgp_extract_keys_from_attachment_list_t
89         pgp_extract_keys_from_attachment_list;
90
91     /* S/MIME specific functions.  */
92
93     crypt_func_smime_getkeys_t smime_getkeys;
94     crypt_func_smime_verify_sender_t smime_verify_sender;
95     crypt_func_smime_build_smime_entity_t smime_build_smime_entity;
96     crypt_func_smime_invoke_import_t smime_invoke_import;
97 } crypt_module_functions_t;
98
99
100 /*
101    A structure to decribe a crypto module. 
102  */
103 typedef struct crypt_module_specs {
104   int identifier;               /* Identifying bit.  */
105   crypt_module_functions_t functions;
106 }                 *crypt_module_specs_t;
107
108
109
110 /* 
111    High Level crypto module interface. 
112  */
113
114 void crypto_module_register (crypt_module_specs_t specs);
115 crypt_module_specs_t crypto_module_lookup (int identifier);
116
117 /* If the crypto module identifier by IDENTIFIER has been registered,
118    call its function FUNC.  Do nothing else.  This may be used as an
119    expression. */
120 #define CRYPT_MOD_CALL_CHECK(identifier, func) \
121   (crypto_module_lookup (APPLICATION_ ## identifier) \
122    && (crypto_module_lookup (APPLICATION_ ## identifier))->functions.func)
123
124 /* Call the function FUNC in the crypto module identified by
125    IDENTIFIER. This may be used as an expression. */
126 #define CRYPT_MOD_CALL(identifier, func) \
127   *(crypto_module_lookup (APPLICATION_ ## identifier))->functions.func
128
129 #endif