Rocco Rutte:
[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 void (*crypt_func_application_handler_t) (BODY * m, STATE * s);
29 typedef void (*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      
89      
90      
91      
92      
93      
94      
95      
96      
97      
98      
99      
100      
101      crypt_func_pgp_extract_keys_from_attachment_list_t
102     pgp_extract_keys_from_attachment_list;
103
104   /* S/MIME specific functions.  */
105
106   crypt_func_smime_getkeys_t smime_getkeys;
107   crypt_func_smime_verify_sender_t smime_verify_sender;
108   crypt_func_smime_build_smime_entity_t smime_build_smime_entity;
109   crypt_func_smime_invoke_import_t smime_invoke_import;
110 } crypt_module_functions_t;
111
112
113 /*
114    A structure to decribe a crypto module. 
115  */
116 typedef struct crypt_module_specs {
117   int identifier;               /* Identifying bit.  */
118   crypt_module_functions_t functions;
119 }                 *crypt_module_specs_t;
120
121
122
123 /* 
124    High Level crypto module interface. 
125  */
126
127 void crypto_module_register (crypt_module_specs_t specs);
128 crypt_module_specs_t crypto_module_lookup (int identifier);
129
130 /* If the crypto module identifier by IDENTIFIER has been registered,
131    call its function FUNC.  Do nothing else.  This may be used as an
132    expression. */
133 #define CRYPT_MOD_CALL_CHECK(identifier, func) \
134   (crypto_module_lookup (APPLICATION_ ## identifier) \
135    && (crypto_module_lookup (APPLICATION_ ## identifier))->functions.func)
136
137 /* Call the function FUNC in the crypto module identified by
138    IDENTIFIER. This may be used as an expression. */
139 #define CRYPT_MOD_CALL(identifier, func) \
140   *(crypto_module_lookup (APPLICATION_ ## identifier))->functions.func
141
142 #endif