diff options
Diffstat (limited to 'tools/util.c')
-rw-r--r-- | tools/util.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tools/util.c b/tools/util.c index de70388..7ed59e4 100644 --- a/tools/util.c +++ b/tools/util.c | |||
@@ -16,7 +16,9 @@ | |||
16 | #include <fido/rs256.h> | 16 | #include <fido/rs256.h> |
17 | #include <fido/eddsa.h> | 17 | #include <fido/eddsa.h> |
18 | 18 | ||
19 | #include <errno.h> | ||
19 | #include <fcntl.h> | 20 | #include <fcntl.h> |
21 | #include <limits.h> | ||
20 | #include <stdint.h> | 22 | #include <stdint.h> |
21 | #include <stdio.h> | 23 | #include <stdio.h> |
22 | #include <stdlib.h> | 24 | #include <stdlib.h> |
@@ -78,6 +80,25 @@ open_read(const char *file) | |||
78 | return (f); | 80 | return (f); |
79 | } | 81 | } |
80 | 82 | ||
83 | int | ||
84 | base10(const char *str) | ||
85 | { | ||
86 | char *ep; | ||
87 | long long ll; | ||
88 | |||
89 | ll = strtoll(str, &ep, 10); | ||
90 | if (str == ep || *ep != '\0') | ||
91 | return (-1); | ||
92 | else if (ll == LLONG_MIN && errno == ERANGE) | ||
93 | return (-1); | ||
94 | else if (ll == LLONG_MAX && errno == ERANGE) | ||
95 | return (-1); | ||
96 | else if (ll < 0 || ll > INT_MAX) | ||
97 | return (-1); | ||
98 | |||
99 | return ((int)ll); | ||
100 | } | ||
101 | |||
81 | void | 102 | void |
82 | xxd(const void *buf, size_t count) | 103 | xxd(const void *buf, size_t count) |
83 | { | 104 | { |
@@ -362,3 +383,50 @@ print_cred(FILE *out_f, int type, const fido_cred_t *cred) | |||
362 | 383 | ||
363 | free(id); | 384 | free(id); |
364 | } | 385 | } |
386 | |||
387 | int | ||
388 | cose_type(const char *str, int *type) | ||
389 | { | ||
390 | if (strcmp(str, "es256") == 0) | ||
391 | *type = COSE_ES256; | ||
392 | else if (strcmp(str, "rs256") == 0) | ||
393 | *type = COSE_RS256; | ||
394 | else if (strcmp(str, "eddsa") == 0) | ||
395 | *type = COSE_EDDSA; | ||
396 | else { | ||
397 | *type = 0; | ||
398 | return (-1); | ||
399 | } | ||
400 | |||
401 | return (0); | ||
402 | } | ||
403 | |||
404 | const char * | ||
405 | cose_string(int type) | ||
406 | { | ||
407 | switch (type) { | ||
408 | case COSE_EDDSA: | ||
409 | return ("eddsa"); | ||
410 | case COSE_ES256: | ||
411 | return ("es256"); | ||
412 | case COSE_RS256: | ||
413 | return ("rs256"); | ||
414 | default: | ||
415 | return ("unknown"); | ||
416 | } | ||
417 | } | ||
418 | |||
419 | const char * | ||
420 | prot_string(int prot) | ||
421 | { | ||
422 | switch (prot) { | ||
423 | case FIDO_CRED_PROT_UV_OPTIONAL: | ||
424 | return ("uvopt"); | ||
425 | case FIDO_CRED_PROT_UV_OPTIONAL_WITH_ID: | ||
426 | return ("uvopt+id"); | ||
427 | case FIDO_CRED_PROT_UV_REQUIRED: | ||
428 | return ("uvreq"); | ||
429 | default: | ||
430 | return ("unknown"); | ||
431 | } | ||
432 | } | ||