| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <stdlib.h> |
| 7 |
#include <strings.h> |
| 8 |
|
| 9 |
#include "vboot_host.h" |
| 10 |
|
| 11 |
static int lookup_helper(const char *str, const char *table[], size_t size, |
| 12 |
unsigned int *out) |
| 13 |
{ |
| 14 |
unsigned int algo; |
| 15 |
char *e; |
| 16 |
|
| 17 |
|
| 18 |
for (algo = 0; algo < size; algo++) |
| 19 |
if (table[algo] && !strcasecmp(table[algo], str)) |
| 20 |
goto found; |
| 21 |
|
| 22 |
|
| 23 |
algo = strtoul(str, &e, 0); |
| 24 |
if (!*str || (e && *e)) |
| 25 |
|
| 26 |
return false; |
| 27 |
if (algo >= size || !table[algo]) |
| 28 |
|
| 29 |
return false; |
| 30 |
|
| 31 |
found: |
| 32 |
*out = algo; |
| 33 |
return true; |
| 34 |
} |
| 35 |
|
| 36 |
bool vb2_lookup_sig_alg(const char *str, enum vb2_signature_algorithm *sig_alg) |
| 37 |
{ |
| 38 |
return lookup_helper(str, vb2_sig_names, VB2_SIG_ALG_COUNT, sig_alg); |
| 39 |
} |
| 40 |
|
| 41 |
bool vb2_lookup_hash_alg(const char *str, enum vb2_hash_algorithm *hash_alg) |
| 42 |
{ |
| 43 |
return lookup_helper(str, vb2_hash_names, VB2_HASH_ALG_COUNT, hash_alg); |
| 44 |
} |