diff options
author | job <> | 2023-04-26 19:05:37 +0000 |
---|---|---|
committer | job <> | 2023-04-26 19:05:37 +0000 |
commit | 6ffb28298670459d0df0cbe863c548c2858f3792 (patch) | |
tree | 55f62e8f1060387822ab28f8b0245f708b95eaa7 /src | |
parent | 45c077e1c3c8cdc8e0d04596b98c60252d707c31 (diff) | |
download | openbsd-6ffb28298670459d0df0cbe863c548c2858f3792.tar.gz openbsd-6ffb28298670459d0df0cbe863c548c2858f3792.tar.bz2 openbsd-6ffb28298670459d0df0cbe863c548c2858f3792.zip |
Add lookup name+function pointer table for improved diagnostics
OK tb@
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libcrypto/x509/x509_asn1.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/src/regress/lib/libcrypto/x509/x509_asn1.c b/src/regress/lib/libcrypto/x509/x509_asn1.c index 76f9f5705d..f41b26f7d8 100644 --- a/src/regress/lib/libcrypto/x509/x509_asn1.c +++ b/src/regress/lib/libcrypto/x509/x509_asn1.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: x509_asn1.c,v 1.6 2023/04/26 11:06:32 job Exp $ */ | 1 | /* $OpenBSD: x509_asn1.c,v 1.7 2023/04/26 19:05:37 job Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Job Snijders <job@openbsd.org> | 3 | * Copyright (c) 2023 Job Snijders <job@openbsd.org> |
4 | * | 4 | * |
@@ -29,6 +29,31 @@ | |||
29 | #include <openssl/rsa.h> | 29 | #include <openssl/rsa.h> |
30 | #include <openssl/x509.h> | 30 | #include <openssl/x509.h> |
31 | 31 | ||
32 | static const struct fnnames { | ||
33 | char *name; | ||
34 | void (*fn); | ||
35 | } fnnames[] = { | ||
36 | { "X509_set_version", X509_set_version }, | ||
37 | { "X509_set_serialNumber", X509_set_serialNumber }, | ||
38 | { "X509_set_issuer_name", X509_set_issuer_name }, | ||
39 | { "X509_set_subject_name", X509_set_subject_name }, | ||
40 | { "X509_set_notBefore", X509_set_notBefore }, | ||
41 | { "X509_set_notAfter", X509_set_notAfter }, | ||
42 | { "X509_set_pubkey", X509_set_pubkey }, | ||
43 | { NULL, NULL } | ||
44 | }; | ||
45 | |||
46 | static void | ||
47 | lookup_and_err(void (*fn)) | ||
48 | { | ||
49 | int i; | ||
50 | |||
51 | for (i = 0; fnnames[i].name; i++) { | ||
52 | if (fnnames[i].fn == fn) | ||
53 | errx(1, "%s failed", fnnames[i].name); | ||
54 | } | ||
55 | } | ||
56 | |||
32 | static void | 57 | static void |
33 | x509_setup(unsigned char **der, unsigned char **der2, X509 **x, | 58 | x509_setup(unsigned char **der, unsigned char **der2, X509 **x, |
34 | long dersz, long *der2sz) | 59 | long dersz, long *der2sz) |
@@ -61,7 +86,7 @@ x509_set_integer(int (*f)(X509 *, ASN1_INTEGER *), X509 **x, int i) | |||
61 | if (!ASN1_INTEGER_set(ai, i)) | 86 | if (!ASN1_INTEGER_set(ai, i)) |
62 | errx(1, "ASN1_INTEGER_set"); | 87 | errx(1, "ASN1_INTEGER_set"); |
63 | if (!f(*x, ai)) | 88 | if (!f(*x, ai)) |
64 | err(1, NULL); | 89 | lookup_and_err(f); |
65 | 90 | ||
66 | ASN1_INTEGER_free(ai); | 91 | ASN1_INTEGER_free(ai); |
67 | } | 92 | } |
@@ -77,7 +102,7 @@ x509_set_name(int (*f)(X509 *, X509_NAME *), X509 **x, | |||
77 | if (!X509_NAME_add_entry_by_txt(xn, "C", MBSTRING_ASC, n, -1, -1, 0)) | 102 | if (!X509_NAME_add_entry_by_txt(xn, "C", MBSTRING_ASC, n, -1, -1, 0)) |
78 | errx(1, "X509_NAME_add_entry_by_txt"); | 103 | errx(1, "X509_NAME_add_entry_by_txt"); |
79 | if (!f(*x, xn)) | 104 | if (!f(*x, xn)) |
80 | err(1, NULL); | 105 | lookup_and_err(f); |
81 | 106 | ||
82 | X509_NAME_free(xn); | 107 | X509_NAME_free(xn); |
83 | } | 108 | } |
@@ -92,7 +117,7 @@ x509_set_time(int (*f)(X509 *, const ASN1_TIME *), X509 **x, int t) | |||
92 | if ((at = X509_gmtime_adj(NULL, t)) == NULL) | 117 | if ((at = X509_gmtime_adj(NULL, t)) == NULL) |
93 | errx(1, "X509_gmtime_adj"); | 118 | errx(1, "X509_gmtime_adj"); |
94 | if (!f(*x, at)) | 119 | if (!f(*x, at)) |
95 | err(1, NULL); | 120 | lookup_and_err(f); |
96 | 121 | ||
97 | ASN1_TIME_free(at); | 122 | ASN1_TIME_free(at); |
98 | } | 123 | } |