summaryrefslogtreecommitdiff
path: root/usr.sbin/rpki-client/parser.c
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2022-01-21 18:49:45 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2022-01-21 18:49:45 +0000
commit2c34598a3059320a42aeb910916b45650bdf4949 (patch)
tree27bad1dd646829df348feac9877f83b5c480b5d4 /usr.sbin/rpki-client/parser.c
parent5c13252dd5a14e24a35f1ddf58384d458e4dd572 (diff)
Add function to determine the file type from the file name extension
rpki-client uses the same idiom to determine the file type in too many places. Use one function that determines the appropriate RTYPE from the file name. Add that type to struct mftfile and use this new member to simplify queue_add_from_mft*(). input/ok claudio
Diffstat (limited to 'usr.sbin/rpki-client/parser.c')
-rw-r--r--usr.sbin/rpki-client/parser.c20
1 files changed, 2 insertions, 18 deletions
diff --git a/usr.sbin/rpki-client/parser.c b/usr.sbin/rpki-client/parser.c
index 70b198f2a40..c6d0e5c0cfe 100644
--- a/usr.sbin/rpki-client/parser.c
+++ b/usr.sbin/rpki-client/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.48 2022/01/21 14:08:33 tb Exp $ */
+/* $OpenBSD: parser.c,v 1.49 2022/01/21 18:49:44 tb Exp $ */
/*
* Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -912,25 +912,9 @@ proc_parser_file(char *file, unsigned char *buf, size_t len)
struct tal *tal = NULL;
enum rtype type;
char *aia = NULL, *aki = NULL, *ski = NULL;
- size_t sz;
unsigned long verify_flags = X509_V_FLAG_CRL_CHECK;
- sz = strlen(file);
- if (sz < 5)
- errx(1, "%s: unsupported file type", file);
- if (strcasecmp(file + sz - 4, ".tal") == 0)
- type = RTYPE_TAL;
- else if (strcasecmp(file + sz - 4, ".cer") == 0)
- type = RTYPE_CER;
- else if (strcasecmp(file + sz - 4, ".crl") == 0)
- type = RTYPE_CRL;
- else if (strcasecmp(file + sz - 4, ".mft") == 0)
- type = RTYPE_MFT;
- else if (strcasecmp(file + sz - 4, ".roa") == 0)
- type = RTYPE_ROA;
- else if (strcasecmp(file + sz - 4, ".gbr") == 0)
- type = RTYPE_GBR;
- else
+ if ((type = rtype_from_file_extension(file)) == RTYPE_INVALID)
errx(1, "%s: unsupported file type", file);
switch (type) {