e8aaa6b84a7c088c8d3239ff15c518ebc11e0694
[apps/madmutt.git] / crypt-mod.c
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 #if HAVE_CONFIG_H
11 # include "config.h"
12 #endif
13
14 #include "crypt-mod.h"
15
16 /* A type an a variable to keep track of registered crypto modules. */
17 typedef struct crypt_module *crypt_module_t;
18
19 struct crypt_module {
20   crypt_module_specs_t specs;
21   crypt_module_t next, *prevp;
22 };
23
24 static crypt_module_t modules;
25
26 /* Register a new crypto module. */
27 void crypto_module_register (crypt_module_specs_t specs)
28 {
29   crypt_module_t module_new = safe_malloc (sizeof (*module_new));
30
31   module_new->specs = specs;
32   module_new->next = modules;
33   if (modules)
34     modules->prevp = &module_new->next;
35   modules = module_new;
36 }
37
38 /* Return the crypto module specs for IDENTIFIER.  This function is
39    usually used via the CRYPT_MOD_CALL[_CHECK] macros. */
40 crypt_module_specs_t crypto_module_lookup (int identifier)
41 {
42   crypt_module_t module = modules;
43
44   while (module && (module->specs->identifier != identifier))
45     module = module->next;
46
47   return module ? module->specs : NULL;
48 }