diff options
author | Job Snijders <job@cvs.openbsd.org> | 2023-04-26 19:05:38 +0000 |
---|---|---|
committer | Job Snijders <job@cvs.openbsd.org> | 2023-04-26 19:05:38 +0000 |
commit | b5d726e61f8f673983c0a579e428a19620011129 (patch) | |
tree | 98a771684f9a2330842528cde2443702a7db14c5 | |
parent | b033f6018f47b5a35a19df860326128e45c5198a (diff) |
Add lookup name+function pointer table for improved diagnostics
OK tb@
-rw-r--r-- | regress/lib/libcrypto/x509/x509_asn1.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/regress/lib/libcrypto/x509/x509_asn1.c b/regress/lib/libcrypto/x509/x509_asn1.c index 76f9f5705d0..f41b26f7d86 100644 --- a/regress/lib/libcrypto/x509/x509_asn1.c +++ b/regress/lib/libcrypto/x509/x509_asn1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509_asn1.c,v 1.6 2023/04/26 11:06:32 job Exp $ */ +/* $OpenBSD: x509_asn1.c,v 1.7 2023/04/26 19:05:37 job Exp $ */ /* * Copyright (c) 2023 Job Snijders <job@openbsd.org> * @@ -29,6 +29,31 @@ #include <openssl/rsa.h> #include <openssl/x509.h> +static const struct fnnames { + char *name; + void (*fn); +} fnnames[] = { + { "X509_set_version", X509_set_version }, + { "X509_set_serialNumber", X509_set_serialNumber }, + { "X509_set_issuer_name", X509_set_issuer_name }, + { "X509_set_subject_name", X509_set_subject_name }, + { "X509_set_notBefore", X509_set_notBefore }, + { "X509_set_notAfter", X509_set_notAfter }, + { "X509_set_pubkey", X509_set_pubkey }, + { NULL, NULL } +}; + +static void +lookup_and_err(void (*fn)) +{ + int i; + + for (i = 0; fnnames[i].name; i++) { + if (fnnames[i].fn == fn) + errx(1, "%s failed", fnnames[i].name); + } +} + static void x509_setup(unsigned char **der, unsigned char **der2, X509 **x, long dersz, long *der2sz) @@ -61,7 +86,7 @@ x509_set_integer(int (*f)(X509 *, ASN1_INTEGER *), X509 **x, int i) if (!ASN1_INTEGER_set(ai, i)) errx(1, "ASN1_INTEGER_set"); if (!f(*x, ai)) - err(1, NULL); + lookup_and_err(f); ASN1_INTEGER_free(ai); } @@ -77,7 +102,7 @@ x509_set_name(int (*f)(X509 *, X509_NAME *), X509 **x, if (!X509_NAME_add_entry_by_txt(xn, "C", MBSTRING_ASC, n, -1, -1, 0)) errx(1, "X509_NAME_add_entry_by_txt"); if (!f(*x, xn)) - err(1, NULL); + lookup_and_err(f); X509_NAME_free(xn); } @@ -92,7 +117,7 @@ x509_set_time(int (*f)(X509 *, const ASN1_TIME *), X509 **x, int t) if ((at = X509_gmtime_adj(NULL, t)) == NULL) errx(1, "X509_gmtime_adj"); if (!f(*x, at)) - err(1, NULL); + lookup_and_err(f); ASN1_TIME_free(at); } |