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