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