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