summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2021-12-14 17:07:57 +0000
committerjsing <>2021-12-14 17:07:57 +0000
commit1d9510b0e4ff14df346622c4b2cdb7e461b208a6 (patch)
tree5f8cda8220c836d7ad994fd74624fb35597d12f2
parentb0ded7e0f27d6bb0af75894e53b0045e7c362f7b (diff)
downloadopenbsd-1d9510b0e4ff14df346622c4b2cdb7e461b208a6.tar.gz
openbsd-1d9510b0e4ff14df346622c4b2cdb7e461b208a6.tar.bz2
openbsd-1d9510b0e4ff14df346622c4b2cdb7e461b208a6.zip
Add regress for ASN1_tag2bit() and ASN1_tag2str()
-rw-r--r--src/regress/lib/libcrypto/asn1/Makefile3
-rw-r--r--src/regress/lib/libcrypto/asn1/asn1api.c133
2 files changed, 135 insertions, 1 deletions
diff --git a/src/regress/lib/libcrypto/asn1/Makefile b/src/regress/lib/libcrypto/asn1/Makefile
index 90eca92f8e..7540aeb447 100644
--- a/src/regress/lib/libcrypto/asn1/Makefile
+++ b/src/regress/lib/libcrypto/asn1/Makefile
@@ -1,6 +1,7 @@
1# $OpenBSD: Makefile,v 1.10 2021/12/11 22:58:48 schwarze Exp $ 1# $OpenBSD: Makefile,v 1.11 2021/12/14 17:07:57 jsing Exp $
2 2
3TESTS = \ 3TESTS = \
4 asn1api \
4 asn1basic \ 5 asn1basic \
5 asn1complex \ 6 asn1complex \
6 asn1evp \ 7 asn1evp \
diff --git a/src/regress/lib/libcrypto/asn1/asn1api.c b/src/regress/lib/libcrypto/asn1/asn1api.c
new file mode 100644
index 0000000000..05b7353d4d
--- /dev/null
+++ b/src/regress/lib/libcrypto/asn1/asn1api.c
@@ -0,0 +1,133 @@
1/* $OpenBSD: asn1api.c,v 1.1 2021/12/14 17:07:57 jsing Exp $ */
2/*
3 * Copyright (c) 2021 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <openssl/asn1.h>
19#include <openssl/err.h>
20
21#include <err.h>
22#include <stdio.h>
23#include <string.h>
24
25const long asn1_tag2bits[] = {
26 [0] = 0,
27 [1] = 0,
28 [2] = 0,
29 [3] = B_ASN1_BIT_STRING,
30 [4] = B_ASN1_OCTET_STRING,
31 [5] = 0,
32 [6] = 0,
33 [7] = B_ASN1_UNKNOWN,
34 [8] = B_ASN1_UNKNOWN,
35 [9] = B_ASN1_UNKNOWN,
36 [10] = B_ASN1_UNKNOWN,
37 [11] = B_ASN1_UNKNOWN,
38 [12] = B_ASN1_UTF8STRING,
39 [13] = B_ASN1_UNKNOWN,
40 [14] = B_ASN1_UNKNOWN,
41 [15] = B_ASN1_UNKNOWN,
42 [16] = B_ASN1_SEQUENCE,
43 [17] = 0,
44 [18] = B_ASN1_NUMERICSTRING,
45 [19] = B_ASN1_PRINTABLESTRING,
46 [20] = B_ASN1_T61STRING,
47 [21] = B_ASN1_VIDEOTEXSTRING,
48 [22] = B_ASN1_IA5STRING,
49 [23] = B_ASN1_UTCTIME,
50 [24] = B_ASN1_GENERALIZEDTIME,
51 [25] = B_ASN1_GRAPHICSTRING,
52 [26] = B_ASN1_ISO64STRING,
53 [27] = B_ASN1_GENERALSTRING,
54 [28] = B_ASN1_UNIVERSALSTRING,
55 [29] = B_ASN1_UNKNOWN,
56 [30] = B_ASN1_BMPSTRING,
57};
58
59static int
60asn1_tag2bit(void)
61{
62 int failed = 1;
63 long bit;
64 int i;
65
66 for (i = -3; i <= V_ASN1_NEG + 30; i++) {
67 bit = ASN1_tag2bit(i);
68 if (i >= 0 && i <= 30) {
69 if (bit != asn1_tag2bits[i]) {
70 fprintf(stderr, "FAIL: ASN1_tag2bit(%d) = 0x%lx,"
71 " want 0x%lx\n", i, bit, asn1_tag2bits[i]);
72 goto failed;
73 }
74 } else {
75 if (bit != 0) {
76 fprintf(stderr, "FAIL: ASN1_tag2bit(%d) = 0x%lx,"
77 " want 0x0\n", i, bit);
78 goto failed;
79 }
80 }
81 }
82
83 failed = 0;
84
85 failed:
86 return failed;
87}
88
89static int
90asn1_tag2str(void)
91{
92 int failed = 1;
93 const char *s;
94 int i;
95
96 for (i = -3; i <= V_ASN1_NEG + 30; i++) {
97 if ((s = ASN1_tag2str(i)) == NULL) {
98 fprintf(stderr, "FAIL: ASN1_tag2str(%d) returned "
99 "NULL\n", i);
100 goto failed;
101 }
102 if ((i >= 0 && i <= 30) || i == V_ASN1_NEG_INTEGER ||
103 i == V_ASN1_NEG_ENUMERATED) {
104 if (strcmp(s, "(unknown)") == 0) {
105 fprintf(stderr, "FAIL: ASN1_tag2str(%d) = '%s',"
106 " want tag name\n", i, s);
107 goto failed;
108 }
109 } else {
110 if (strcmp(s, "(unknown)") != 0) {
111 fprintf(stderr, "FAIL: ASN1_tag2str(%d) = '%s',"
112 " want '(unknown')\n", i, s);
113 goto failed;
114 }
115 }
116 }
117
118 failed = 0;
119
120 failed:
121 return failed;
122}
123
124int
125main(int argc, char **argv)
126{
127 int failed = 0;
128
129 failed |= asn1_tag2bit();
130 failed |= asn1_tag2str();
131
132 return (failed);
133}