Coverage Report

Created: 2023-06-07 06:15

/src/neomutt/ncrypt/crypt_mod.c
Line
Count
Source (jump to first uncovered line)
1
/**
2
 * @file
3
 * Register crypto modules
4
 *
5
 * @authors
6
 * Copyright (C) 2004 g10 Code GmbH
7
 *
8
 * @copyright
9
 * This program is free software: you can redistribute it and/or modify it under
10
 * the terms of the GNU General Public License as published by the Free Software
11
 * Foundation, either version 2 of the License, or (at your option) any later
12
 * version.
13
 *
14
 * This program is distributed in the hope that it will be useful, but WITHOUT
15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17
 * details.
18
 *
19
 * You should have received a copy of the GNU General Public License along with
20
 * this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
/**
24
 * @page crypt_crypt_mod Register crypto modules
25
 *
26
 * Register crypto modules
27
 */
28
29
#include "config.h"
30
#include "mutt/lib.h"
31
#include "crypt_mod.h"
32
33
/**
34
 * struct CryptModule - A crypto plugin module
35
 *
36
 * A type of a variable to keep track of registered crypto modules.
37
 */
38
struct CryptModule
39
{
40
  const struct CryptModuleSpecs *specs; ///< Crypto module definition
41
  STAILQ_ENTRY(CryptModule) entries;    ///< Linked list
42
};
43
STAILQ_HEAD(CryptModuleList, CryptModule);
44
45
/// Linked list of crypto modules, e.g. #CryptModSmimeClassic, #CryptModPgpGpgme
46
static struct CryptModuleList CryptModules = STAILQ_HEAD_INITIALIZER(CryptModules);
47
48
/**
49
 * crypto_module_register - Register a new crypto module
50
 * @param specs API functions
51
 */
52
void crypto_module_register(const struct CryptModuleSpecs *specs)
53
0
{
54
0
  struct CryptModule *module = mutt_mem_calloc(1, sizeof(struct CryptModule));
55
0
  module->specs = specs;
56
0
  STAILQ_INSERT_HEAD(&CryptModules, module, entries);
57
0
}
58
59
/**
60
 * crypto_module_lookup - Lookup a crypto module by name
61
 * @param identifier Name, e.g. #APPLICATION_PGP
62
 * @retval ptr Crypto module
63
 *
64
 * This function is usually used via the CRYPT_MOD_CALL[_CHECK] macros.
65
 */
66
const struct CryptModuleSpecs *crypto_module_lookup(int identifier)
67
0
{
68
0
  const struct CryptModule *module = NULL;
69
0
  STAILQ_FOREACH(module, &CryptModules, entries)
70
0
  {
71
0
    if (module->specs->identifier == identifier)
72
0
    {
73
0
      return module->specs;
74
0
    }
75
0
  }
76
0
  return NULL;
77
0
}
78
79
/**
80
 * crypto_module_free - Clean up the crypto modules
81
 */
82
void crypto_module_free(void)
83
0
{
84
0
  struct CryptModule *np = NULL, *tmp = NULL;
85
0
  STAILQ_FOREACH_SAFE(np, &CryptModules, entries, tmp)
86
0
  {
87
0
    STAILQ_REMOVE(&CryptModules, np, CryptModule, entries);
88
0
    FREE(&np);
89
0
  }
90
0
}