Andreas Krennmair:
[apps/madmutt.git] / crypt-mod.c
1 /*
2  * Copyright (C) 2004 g10 Code GmbH
3  *
4  *     This program is free software; you can redistribute it and/or modify
5  *     it under the terms of the GNU General Public License as published by
6  *     the Free Software Foundation; either version 2 of the License, or
7  *     (at your option) any later version.
8  * 
9  *     This program is distributed in the hope that it will be useful,
10  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *     GNU General Public License for more details.
13  * 
14  *     You should have received a copy of the GNU General Public License
15  *     along with this program; if not, write to the Free Software
16  *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
17  */
18
19 #if HAVE_CONFIG_H
20 # include "config.h"
21 #endif
22
23 #include "crypt-mod.h"
24
25 /* A type an a variable to keep track of registered crypto modules. */
26 typedef struct crypt_module *crypt_module_t;
27
28 struct crypt_module {
29   crypt_module_specs_t specs;
30   crypt_module_t next, *prevp;
31 };
32
33 static crypt_module_t modules;
34
35 /* Register a new crypto module. */
36 void crypto_module_register (crypt_module_specs_t specs)
37 {
38   crypt_module_t module_new = safe_malloc (sizeof (*module_new));
39
40   module_new->specs = specs;
41   module_new->next = modules;
42   if (modules)
43     modules->prevp = &module_new->next;
44   modules = module_new;
45 }
46
47 /* Return the crypto module specs for IDENTIFIER.  This function is
48    usually used via the CRYPT_MOD_CALL[_CHECK] macros. */
49 crypt_module_specs_t crypto_module_lookup (int identifier)
50 {
51   crypt_module_t module = modules;
52
53   while (module && (module->specs->identifier != identifier))
54     module = module->next;
55
56   return module ? module->specs : NULL;
57 }