c6b4e94d9e2150410d7fb8628004f0d1a22261ac
[apps/madmutt.git] / lib-crypt / cryptglue.c
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 2003  Werner Koch <wk@gnupg.org>
4  * Copyright (C) 2004 g10 Code GmbH
5  *
6  * This file is part of mutt-ng, see http://www.muttng.org/.
7  * It's licensed under the GNU General Public License,
8  * please see the file GPL in the top level source directory.
9  */
10
11 /*
12    This file dispatches the generic crypto functions to the
13    implemented backend or provides dummy stubs.  Note, that some
14    generic functions are handled in crypt.c.
15 */
16
17 /* Note: This file has been changed to make use of the new module
18    system.  Consequently there's a 1:1 mapping between the functions
19    contained in this file and the functions implemented by the crypto
20    modules.  */
21
22 #include <lib-lib/lib-lib.h>
23
24 #include "mutt.h"
25 #include "crypt.h"
26 #include "crypt-gpgme.h"
27
28 #define CRYPT_MOD_CALL_CHECK(identifier, func) \
29     ((crypt_mod_##identifier##_gpgme).func)
30
31 #define CRYPT_MOD_CALL(identifier, func) \
32     (*((crypt_mod_##identifier##_gpgme).func))
33
34
35 struct crypt_module_specs crypt_mod_SMIME_gpgme = {
36     NULL,                        /* encrypted_handler */
37
38     NULL,                        /* pgp_make_key_attachment */
39     NULL,                        /* pgp_invoke_getkeys */
40
41     NULL,                        /* smime_getkeys */
42     smime_gpgme_build_smime_entity,
43 };
44
45 struct crypt_module_specs crypt_mod_PGP_gpgme = {
46     pgp_gpgme_encrypted_handler,
47
48     /* PGP specific.  */
49     NULL,                        /* pgp_make_key_attachment, */
50     NULL,                        /* pgp_invoke_getkeys  */
51
52     NULL,                        /* smime_getkeys */
53     NULL,                        /* smime_build_smime_entity */
54 };
55
56
57 /* PGP */
58
59 /* MIME handler for an PGP/MIME encrypted message. */
60 int crypt_pgp_encrypted_handler (BODY * a, STATE * s)
61 {
62     if (CRYPT_MOD_CALL_CHECK (PGP, encrypted_handler))
63         return (CRYPT_MOD_CALL (PGP, encrypted_handler)) (a, s);
64     return (-1);
65 }
66
67 /* fixme: needs documentation. */
68 void crypt_pgp_invoke_getkeys (address_t * addr)
69 {
70     if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_getkeys))
71         (CRYPT_MOD_CALL (PGP, pgp_invoke_getkeys)) (addr);
72 }
73
74 /* Generate a PGP public key attachment. */
75 BODY *crypt_pgp_make_key_attachment (char *tempf)
76 {
77     if (CRYPT_MOD_CALL_CHECK (PGP, pgp_make_key_attachment))
78         return (CRYPT_MOD_CALL (PGP, pgp_make_key_attachment)) (tempf);
79
80     return NULL;
81 }
82
83 /* S/MIME */
84
85 /* fixme: Needs documentation. */
86 void crypt_smime_getkeys (ENVELOPE * env)
87 {
88     if (CRYPT_MOD_CALL_CHECK (SMIME, smime_getkeys))
89         (CRYPT_MOD_CALL (SMIME, smime_getkeys)) (env);
90 }
91
92 /* fixme: needs documentation. */
93 BODY *crypt_smime_build_smime_entity (BODY * a, char *certlist)
94 {
95     if (CRYPT_MOD_CALL_CHECK (SMIME, smime_build_smime_entity))
96         return (CRYPT_MOD_CALL (SMIME, smime_build_smime_entity)) (a, certlist);
97
98     return NULL;
99 }