-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulticert.c
38 lines (32 loc) · 884 Bytes
/
multicert.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <config.h>
#include "openconnect-internal.h"
static const struct {
openconnect_hash_type id;
const char *name;
} digest_table[OPENCONNECT_HASH_MAX + 1] = {
[ OPENCONNECT_HASH_SHA256 ] = { OPENCONNECT_HASH_SHA256, "sha256" },
[ OPENCONNECT_HASH_SHA384 ] = { OPENCONNECT_HASH_SHA384, "sha384" },
[ OPENCONNECT_HASH_SHA512 ] = { OPENCONNECT_HASH_SHA512, "sha512" },
};
const char *multicert_hash_get_name(int id)
{
size_t i;
if (id > 0 && (size_t) id < ARRAY_SIZE(digest_table)) {
i = (size_t) id;
if (digest_table[i].id)
return digest_table[i].name;
}
return NULL;
}
openconnect_hash_type multicert_hash_get_id(const char *name)
{
size_t i;
if (name) {
for (i = 1; i < ARRAY_SIZE(digest_table); i++) {
if (digest_table[i].name &&
!strcmp(digest_table[i].name, name))
return digest_table[i].id;
}
}
return OPENCONNECT_HASH_UNKNOWN;
}