licentivo-launch 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +35 -0
  4. data/ext/launch_native/extconf.rb +28 -0
  5. data/lib/licentivo_launch/vendor/licentivo.rb +262 -0
  6. data/lib/licentivo_launch.rb +352 -0
  7. data/vendor/LICENSE +21 -0
  8. data/vendor/NOTICE +17 -0
  9. data/vendor/VERSION +1 -0
  10. data/vendor/c/app.c +33 -0
  11. data/vendor/c/demo.c +77 -0
  12. data/vendor/c/feature_tasks.h +72 -0
  13. data/vendor/c/licentivo.c +382 -0
  14. data/vendor/c/licentivo.h +67 -0
  15. data/vendor/c/quickstart.c +51 -0
  16. data/vendor/c/test_vectors.c +4 -0
  17. data/vendor/c/vendor/Monocypher-LICENCE.md +173 -0
  18. data/vendor/c/vendor/cJSON-LICENSE +20 -0
  19. data/vendor/c/vendor/cJSON.c +3191 -0
  20. data/vendor/c/vendor/cJSON.h +306 -0
  21. data/vendor/c/vendor/monocypher-ed25519.c +500 -0
  22. data/vendor/c/vendor/monocypher-ed25519.h +140 -0
  23. data/vendor/c/vendor/monocypher.c +2956 -0
  24. data/vendor/c/vendor/monocypher.h +321 -0
  25. data/vendor/curl/COPYING.txt +22 -0
  26. data/vendor/curl/bin/libcurl-x64.dll +0 -0
  27. data/vendor/curl/include/brotli/decode.h +409 -0
  28. data/vendor/curl/include/brotli/encode.h +505 -0
  29. data/vendor/curl/include/brotli/port.h +302 -0
  30. data/vendor/curl/include/brotli/shared_dictionary.h +100 -0
  31. data/vendor/curl/include/brotli/types.h +83 -0
  32. data/vendor/curl/include/curl/curl.h +3374 -0
  33. data/vendor/curl/include/curl/curlver.h +77 -0
  34. data/vendor/curl/include/curl/easy.h +123 -0
  35. data/vendor/curl/include/curl/header.h +74 -0
  36. data/vendor/curl/include/curl/mprintf.h +85 -0
  37. data/vendor/curl/include/curl/multi.h +561 -0
  38. data/vendor/curl/include/curl/options.h +70 -0
  39. data/vendor/curl/include/curl/stdcheaders.h +35 -0
  40. data/vendor/curl/include/curl/system.h +399 -0
  41. data/vendor/curl/include/curl/typecheck-gcc.h +964 -0
  42. data/vendor/curl/include/curl/urlapi.h +156 -0
  43. data/vendor/curl/include/curl/websockets.h +98 -0
  44. data/vendor/curl/include/libpsl.h +207 -0
  45. data/vendor/curl/include/libssh2.h +1516 -0
  46. data/vendor/curl/include/libssh2_publickey.h +128 -0
  47. data/vendor/curl/include/libssh2_sftp.h +382 -0
  48. data/vendor/curl/include/nghttp2/nghttp2.h +6878 -0
  49. data/vendor/curl/include/nghttp2/nghttp2ver.h +42 -0
  50. data/vendor/curl/include/nghttp3/nghttp3.h +3704 -0
  51. data/vendor/curl/include/nghttp3/version.h +46 -0
  52. data/vendor/curl/include/ngtcp2/ngtcp2.h +7485 -0
  53. data/vendor/curl/include/ngtcp2/ngtcp2_crypto.h +1071 -0
  54. data/vendor/curl/include/ngtcp2/ngtcp2_crypto_quictls.h +147 -0
  55. data/vendor/curl/include/ngtcp2/version.h +51 -0
  56. data/vendor/curl/include/openssl/aes.h +120 -0
  57. data/vendor/curl/include/openssl/asn1.h +1121 -0
  58. data/vendor/curl/include/openssl/asn1t.h +996 -0
  59. data/vendor/curl/include/openssl/bio.h +716 -0
  60. data/vendor/curl/include/openssl/blowfish.h +106 -0
  61. data/vendor/curl/include/openssl/bn.h +480 -0
  62. data/vendor/curl/include/openssl/buffer.h +102 -0
  63. data/vendor/curl/include/openssl/camellia.h +121 -0
  64. data/vendor/curl/include/openssl/cast.h +99 -0
  65. data/vendor/curl/include/openssl/chacha.h +54 -0
  66. data/vendor/curl/include/openssl/cmac.h +81 -0
  67. data/vendor/curl/include/openssl/cms.h +541 -0
  68. data/vendor/curl/include/openssl/comp.h +7 -0
  69. data/vendor/curl/include/openssl/conf.h +189 -0
  70. data/vendor/curl/include/openssl/crypto.h +458 -0
  71. data/vendor/curl/include/openssl/ct.h +567 -0
  72. data/vendor/curl/include/openssl/curve25519.h +104 -0
  73. data/vendor/curl/include/openssl/des.h +215 -0
  74. data/vendor/curl/include/openssl/dh.h +245 -0
  75. data/vendor/curl/include/openssl/dsa.h +263 -0
  76. data/vendor/curl/include/openssl/dtls1.h +107 -0
  77. data/vendor/curl/include/openssl/ec.h +675 -0
  78. data/vendor/curl/include/openssl/ecdh.h +6 -0
  79. data/vendor/curl/include/openssl/ecdsa.h +6 -0
  80. data/vendor/curl/include/openssl/engine.h +215 -0
  81. data/vendor/curl/include/openssl/err.h +325 -0
  82. data/vendor/curl/include/openssl/evp.h +1288 -0
  83. data/vendor/curl/include/openssl/hkdf.h +65 -0
  84. data/vendor/curl/include/openssl/hmac.h +101 -0
  85. data/vendor/curl/include/openssl/idea.h +99 -0
  86. data/vendor/curl/include/openssl/kdf.h +137 -0
  87. data/vendor/curl/include/openssl/lhash.h +179 -0
  88. data/vendor/curl/include/openssl/md4.h +105 -0
  89. data/vendor/curl/include/openssl/md5.h +99 -0
  90. data/vendor/curl/include/openssl/mlkem.h +236 -0
  91. data/vendor/curl/include/openssl/modes.h +118 -0
  92. data/vendor/curl/include/openssl/obj_mac.h +4646 -0
  93. data/vendor/curl/include/openssl/objects.h +137 -0
  94. data/vendor/curl/include/openssl/ocsp.h +484 -0
  95. data/vendor/curl/include/openssl/opensslconf.h +16 -0
  96. data/vendor/curl/include/openssl/opensslfeatures.h +153 -0
  97. data/vendor/curl/include/openssl/opensslv.h +18 -0
  98. data/vendor/curl/include/openssl/ossl_typ.h +196 -0
  99. data/vendor/curl/include/openssl/pem.h +542 -0
  100. data/vendor/curl/include/openssl/pkcs12.h +284 -0
  101. data/vendor/curl/include/openssl/pkcs7.h +523 -0
  102. data/vendor/curl/include/openssl/poly1305.h +45 -0
  103. data/vendor/curl/include/openssl/posix_time.h +54 -0
  104. data/vendor/curl/include/openssl/rand.h +118 -0
  105. data/vendor/curl/include/openssl/rc2.h +101 -0
  106. data/vendor/curl/include/openssl/rc4.h +88 -0
  107. data/vendor/curl/include/openssl/ripemd.h +107 -0
  108. data/vendor/curl/include/openssl/rsa.h +603 -0
  109. data/vendor/curl/include/openssl/safestack.h +1739 -0
  110. data/vendor/curl/include/openssl/sha.h +190 -0
  111. data/vendor/curl/include/openssl/sm3.h +49 -0
  112. data/vendor/curl/include/openssl/sm4.h +47 -0
  113. data/vendor/curl/include/openssl/srtp.h +148 -0
  114. data/vendor/curl/include/openssl/ssl.h +2336 -0
  115. data/vendor/curl/include/openssl/ssl3.h +441 -0
  116. data/vendor/curl/include/openssl/stack.h +99 -0
  117. data/vendor/curl/include/openssl/tls1.h +764 -0
  118. data/vendor/curl/include/openssl/ts.h +660 -0
  119. data/vendor/curl/include/openssl/txt_db.h +112 -0
  120. data/vendor/curl/include/openssl/ui.h +397 -0
  121. data/vendor/curl/include/openssl/x509.h +1037 -0
  122. data/vendor/curl/include/openssl/x509_vfy.h +464 -0
  123. data/vendor/curl/include/openssl/x509v3.h +1039 -0
  124. data/vendor/curl/include/zconf.h +206 -0
  125. data/vendor/curl/include/zdict.h +481 -0
  126. data/vendor/curl/include/zlib.h +1859 -0
  127. data/vendor/curl/include/zlib_name_mangling.h +8 -0
  128. data/vendor/curl/include/zstd.h +3198 -0
  129. data/vendor/curl/include/zstd_errors.h +107 -0
  130. data/vendor/curl/lib/libcurl.dll.a +0 -0
  131. data/vendor/curl/licenses/brotli/LICENSE.txt +19 -0
  132. data/vendor/curl/licenses/certdata/LICENSE.url +2 -0
  133. data/vendor/curl/licenses/libpsl/COPYING.txt +20 -0
  134. data/vendor/curl/licenses/libressl/COPYING.txt +133 -0
  135. data/vendor/curl/licenses/libssh2/COPYING.txt +43 -0
  136. data/vendor/curl/licenses/nghttp2/COPYING.txt +23 -0
  137. data/vendor/curl/licenses/nghttp3/COPYING.txt +22 -0
  138. data/vendor/curl/licenses/ngtcp2/COPYING.txt +22 -0
  139. data/vendor/curl/licenses/psl/LICENSE.txt +373 -0
  140. data/vendor/curl/licenses/trurl/COPYING.txt +22 -0
  141. data/vendor/curl/licenses/zlibng/LICENSE.md +19 -0
  142. data/vendor/curl/licenses/zstd/LICENSE.txt +30 -0
  143. metadata +205 -0
@@ -0,0 +1,996 @@
1
+ /* $OpenBSD: asn1t.h,v 1.31 2026/01/16 09:25:15 tb Exp $ */
2
+ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3
+ * project 2000.
4
+ */
5
+ /* ====================================================================
6
+ * Copyright (c) 2000-2005 The OpenSSL Project. All rights reserved.
7
+ *
8
+ * Redistribution and use in source and binary forms, with or without
9
+ * modification, are permitted provided that the following conditions
10
+ * are met:
11
+ *
12
+ * 1. Redistributions of source code must retain the above copyright
13
+ * notice, this list of conditions and the following disclaimer.
14
+ *
15
+ * 2. Redistributions in binary form must reproduce the above copyright
16
+ * notice, this list of conditions and the following disclaimer in
17
+ * the documentation and/or other materials provided with the
18
+ * distribution.
19
+ *
20
+ * 3. All advertising materials mentioning features or use of this
21
+ * software must display the following acknowledgment:
22
+ * "This product includes software developed by the OpenSSL Project
23
+ * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24
+ *
25
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26
+ * endorse or promote products derived from this software without
27
+ * prior written permission. For written permission, please contact
28
+ * licensing@OpenSSL.org.
29
+ *
30
+ * 5. Products derived from this software may not be called "OpenSSL"
31
+ * nor may "OpenSSL" appear in their names without prior written
32
+ * permission of the OpenSSL Project.
33
+ *
34
+ * 6. Redistributions of any form whatsoever must retain the following
35
+ * acknowledgment:
36
+ * "This product includes software developed by the OpenSSL Project
37
+ * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38
+ *
39
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
51
+ * ====================================================================
52
+ *
53
+ * This product includes cryptographic software written by Eric Young
54
+ * (eay@cryptsoft.com). This product includes software written by Tim
55
+ * Hudson (tjh@cryptsoft.com).
56
+ *
57
+ */
58
+ #ifndef HEADER_ASN1T_H
59
+ #define HEADER_ASN1T_H
60
+
61
+ #include <stddef.h>
62
+
63
+ #include <openssl/opensslconf.h>
64
+
65
+ #include <openssl/asn1.h>
66
+
67
+ /* ASN1 template defines, structures and functions */
68
+
69
+ #ifdef __cplusplus
70
+ extern "C" {
71
+ #endif
72
+
73
+ #ifndef LIBRESSL_INTERNAL
74
+
75
+ /* Macro to obtain ASN1_ADB pointer from a type (only used internally) */
76
+ #define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr))
77
+
78
+
79
+ /* Macros for start and end of ASN1_ITEM definition */
80
+
81
+ #define ASN1_ITEM_start(itname) \
82
+ const ASN1_ITEM itname##_it = {
83
+
84
+ #define static_ASN1_ITEM_start(itname) \
85
+ static const ASN1_ITEM itname##_it = {
86
+
87
+ #define ASN1_ITEM_end(itname) \
88
+ };
89
+
90
+
91
+ /* Macros to aid ASN1 template writing */
92
+
93
+ #define ASN1_ITEM_TEMPLATE(tname) \
94
+ static const ASN1_TEMPLATE tname##_item_tt
95
+
96
+ #define ASN1_ITEM_TEMPLATE_END(tname) \
97
+ ; \
98
+ ASN1_ITEM_start(tname) \
99
+ .itype = ASN1_ITYPE_PRIMITIVE, \
100
+ .utype = -1, \
101
+ .templates = &tname##_item_tt, \
102
+ .tcount = 0, \
103
+ .funcs = NULL, \
104
+ .size = 0, \
105
+ .sname = #tname, \
106
+ ASN1_ITEM_end(tname)
107
+
108
+ #define static_ASN1_ITEM_TEMPLATE_END(tname) \
109
+ ; \
110
+ static_ASN1_ITEM_start(tname) \
111
+ .itype = ASN1_ITYPE_PRIMITIVE, \
112
+ .utype = -1, \
113
+ .templates = &tname##_item_tt, \
114
+ .tcount = 0, \
115
+ .funcs = NULL, \
116
+ .size = 0, \
117
+ .sname = #tname, \
118
+ ASN1_ITEM_end(tname)
119
+
120
+
121
+ /* This is a ASN1 type which just embeds a template */
122
+
123
+ /*
124
+ * This pair helps declare a SEQUENCE. We can do:
125
+ *
126
+ * ASN1_SEQUENCE(stname) = {
127
+ * ... SEQUENCE components ...
128
+ * } ASN1_SEQUENCE_END(stname)
129
+ *
130
+ * This will produce an ASN1_ITEM called stname_it
131
+ * for a structure called stname.
132
+ *
133
+ * If you want the same structure but a different
134
+ * name then use:
135
+ *
136
+ * ASN1_SEQUENCE(itname) = {
137
+ * ... SEQUENCE components ...
138
+ * } ASN1_SEQUENCE_END_name(stname, itname)
139
+ *
140
+ * This will create an item called itname_it using
141
+ * a structure called stname.
142
+ */
143
+
144
+ #define ASN1_SEQUENCE(tname) \
145
+ static const ASN1_TEMPLATE tname##_seq_tt[]
146
+
147
+ #define ASN1_SEQUENCE_END(stname) \
148
+ ASN1_SEQUENCE_END_name(stname, stname)
149
+
150
+ #define static_ASN1_SEQUENCE_END(stname) \
151
+ static_ASN1_SEQUENCE_END_name(stname, stname)
152
+
153
+ #define ASN1_SEQUENCE_END_name(stname, tname) \
154
+ ; \
155
+ ASN1_ITEM_start(tname) \
156
+ .itype = ASN1_ITYPE_SEQUENCE, \
157
+ .utype = V_ASN1_SEQUENCE, \
158
+ .templates = tname##_seq_tt, \
159
+ .tcount = sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
160
+ .funcs = NULL, \
161
+ .size = sizeof(stname), \
162
+ .sname = #stname, \
163
+ ASN1_ITEM_end(tname)
164
+
165
+ #define static_ASN1_SEQUENCE_END_name(stname, tname) \
166
+ ; \
167
+ static_ASN1_ITEM_start(tname) \
168
+ .itype = ASN1_ITYPE_SEQUENCE, \
169
+ .utype = V_ASN1_SEQUENCE, \
170
+ .templates = tname##_seq_tt, \
171
+ .tcount = sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
172
+ .funcs = NULL, \
173
+ .size = sizeof(stname), \
174
+ .sname = #stname, \
175
+ ASN1_ITEM_end(tname)
176
+
177
+ #define ASN1_NDEF_SEQUENCE(tname) \
178
+ ASN1_SEQUENCE(tname)
179
+
180
+ #define ASN1_NDEF_SEQUENCE_cb(tname, cb) \
181
+ ASN1_SEQUENCE_cb(tname, cb)
182
+
183
+ #define ASN1_SEQUENCE_cb(tname, cb) \
184
+ static const ASN1_AUX tname##_aux = { \
185
+ .app_data = NULL, \
186
+ .flags = 0, \
187
+ .ref_offset = 0, \
188
+ .ref_lock = 0, \
189
+ .asn1_cb = cb, \
190
+ .enc_offset = 0, \
191
+ }; \
192
+ ASN1_SEQUENCE(tname)
193
+
194
+ #define ASN1_SEQUENCE_ref(tname, cb, lck) \
195
+ static const ASN1_AUX tname##_aux = { \
196
+ .app_data = NULL, \
197
+ .flags = ASN1_AFLG_REFCOUNT, \
198
+ .ref_offset = offsetof(tname, references), \
199
+ .ref_lock = lck, \
200
+ .asn1_cb = cb, \
201
+ .enc_offset = 0, \
202
+ }; \
203
+ ASN1_SEQUENCE(tname)
204
+
205
+ #define ASN1_SEQUENCE_enc(tname, enc, cb) \
206
+ static const ASN1_AUX tname##_aux = { \
207
+ .app_data = NULL, \
208
+ .flags = ASN1_AFLG_ENCODING, \
209
+ .ref_offset = 0, \
210
+ .ref_lock = 0, \
211
+ .asn1_cb = cb, \
212
+ .enc_offset = offsetof(tname, enc), \
213
+ }; \
214
+ ASN1_SEQUENCE(tname)
215
+
216
+ #define ASN1_NDEF_SEQUENCE_END(tname) \
217
+ ; \
218
+ ASN1_ITEM_start(tname) \
219
+ .itype = ASN1_ITYPE_NDEF_SEQUENCE, \
220
+ .utype = V_ASN1_SEQUENCE, \
221
+ .templates = tname##_seq_tt, \
222
+ .tcount = sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
223
+ .funcs = NULL, \
224
+ .size = sizeof(tname), \
225
+ .sname = #tname, \
226
+ ASN1_ITEM_end(tname)
227
+
228
+ #define static_ASN1_NDEF_SEQUENCE_END(tname) \
229
+ ; \
230
+ static_ASN1_ITEM_start(tname) \
231
+ .itype = ASN1_ITYPE_NDEF_SEQUENCE, \
232
+ .utype = V_ASN1_SEQUENCE, \
233
+ .templates = tname##_seq_tt, \
234
+ .tcount = sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
235
+ .funcs = NULL, \
236
+ .size = sizeof(tname), \
237
+ .sname = #tname, \
238
+ ASN1_ITEM_end(tname)
239
+
240
+ #define ASN1_SEQUENCE_END_enc(stname, tname) \
241
+ ASN1_SEQUENCE_END_ref(stname, tname)
242
+
243
+ #define ASN1_SEQUENCE_END_cb(stname, tname) \
244
+ ASN1_SEQUENCE_END_ref(stname, tname)
245
+
246
+ #define static_ASN1_SEQUENCE_END_cb(stname, tname) \
247
+ static_ASN1_SEQUENCE_END_ref(stname, tname)
248
+
249
+ #define ASN1_SEQUENCE_END_ref(stname, tname) \
250
+ ; \
251
+ ASN1_ITEM_start(tname) \
252
+ .itype = ASN1_ITYPE_SEQUENCE, \
253
+ .utype = V_ASN1_SEQUENCE, \
254
+ .templates = tname##_seq_tt, \
255
+ .tcount = sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
256
+ .funcs = &tname##_aux, \
257
+ .size = sizeof(stname), \
258
+ .sname = #stname, \
259
+ ASN1_ITEM_end(tname)
260
+
261
+ #define static_ASN1_SEQUENCE_END_ref(stname, tname) \
262
+ ; \
263
+ static_ASN1_ITEM_start(tname) \
264
+ .itype = ASN1_ITYPE_SEQUENCE, \
265
+ .utype = V_ASN1_SEQUENCE, \
266
+ .templates = tname##_seq_tt, \
267
+ .tcount = sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
268
+ .funcs = &tname##_aux, \
269
+ .size = sizeof(stname), \
270
+ .sname = #stname, \
271
+ ASN1_ITEM_end(tname)
272
+
273
+ #define ASN1_NDEF_SEQUENCE_END_cb(stname, tname) \
274
+ ; \
275
+ ASN1_ITEM_start(tname) \
276
+ .itype = ASN1_ITYPE_NDEF_SEQUENCE, \
277
+ .utype = V_ASN1_SEQUENCE, \
278
+ .templates = tname##_seq_tt, \
279
+ .tcount = sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
280
+ .funcs = &tname##_aux, \
281
+ .size = sizeof(stname), \
282
+ .sname = #stname, \
283
+ ASN1_ITEM_end(tname)
284
+
285
+
286
+ /*
287
+ * This pair helps declare a CHOICE type. We can do:
288
+ *
289
+ * ASN1_CHOICE(chname) = {
290
+ * ... CHOICE options ...
291
+ * ASN1_CHOICE_END(chname)
292
+ *
293
+ * This will produce an ASN1_ITEM called chname_it
294
+ * for a structure called chname. The structure
295
+ * definition must look like this:
296
+ * typedef struct {
297
+ * int type;
298
+ * union {
299
+ * ASN1_SOMETHING *opt1;
300
+ * ASN1_SOMEOTHER *opt2;
301
+ * } value;
302
+ * } chname;
303
+ *
304
+ * the name of the selector must be 'type'.
305
+ * to use an alternative selector name use the
306
+ * ASN1_CHOICE_END_selector() version.
307
+ */
308
+
309
+ #define ASN1_CHOICE(tname) \
310
+ static const ASN1_TEMPLATE tname##_ch_tt[]
311
+
312
+ #define ASN1_CHOICE_cb(tname, cb) \
313
+ static const ASN1_AUX tname##_aux = { \
314
+ .app_data = NULL, \
315
+ .flags = 0, \
316
+ .ref_offset = 0, \
317
+ .ref_lock = 0, \
318
+ .asn1_cb = cb, \
319
+ .enc_offset = 0, \
320
+ }; \
321
+ ASN1_CHOICE(tname)
322
+
323
+ #define ASN1_CHOICE_END(stname) \
324
+ ASN1_CHOICE_END_name(stname, stname)
325
+
326
+ #define static_ASN1_CHOICE_END(stname) \
327
+ static_ASN1_CHOICE_END_name(stname, stname)
328
+
329
+ #define ASN1_CHOICE_END_name(stname, tname) \
330
+ ASN1_CHOICE_END_selector(stname, tname, type)
331
+
332
+ #define static_ASN1_CHOICE_END_name(stname, tname) \
333
+ static_ASN1_CHOICE_END_selector(stname, tname, type)
334
+
335
+ #define ASN1_CHOICE_END_selector(stname, tname, selname) \
336
+ ; \
337
+ ASN1_ITEM_start(tname) \
338
+ .itype = ASN1_ITYPE_CHOICE, \
339
+ .utype = offsetof(stname, selname), \
340
+ .templates = tname##_ch_tt, \
341
+ .tcount = sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
342
+ .funcs = NULL, \
343
+ .size = sizeof(stname), \
344
+ .sname = #stname, \
345
+ ASN1_ITEM_end(tname)
346
+
347
+ #define static_ASN1_CHOICE_END_selector(stname, tname, selname) \
348
+ ; \
349
+ static_ASN1_ITEM_start(tname) \
350
+ .itype = ASN1_ITYPE_CHOICE, \
351
+ .utype = offsetof(stname, selname), \
352
+ .templates = tname##_ch_tt, \
353
+ .tcount = sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
354
+ .funcs = NULL, \
355
+ .size = sizeof(stname), \
356
+ .sname = #stname, \
357
+ ASN1_ITEM_end(tname)
358
+
359
+ #define ASN1_CHOICE_END_cb(stname, tname, selname) \
360
+ ; \
361
+ ASN1_ITEM_start(tname) \
362
+ .itype = ASN1_ITYPE_CHOICE, \
363
+ .utype = offsetof(stname, selname), \
364
+ .templates = tname##_ch_tt, \
365
+ .tcount = sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
366
+ .funcs = &tname##_aux, \
367
+ .size = sizeof(stname), \
368
+ .sname = #stname, \
369
+ ASN1_ITEM_end(tname)
370
+
371
+ /* This helps with the template wrapper form of ASN1_ITEM */
372
+
373
+ #define ASN1_EX_TEMPLATE_TYPE(flagsval, tagval, name, type) \
374
+ { \
375
+ .flags = (flagsval), \
376
+ .tag = (tagval), \
377
+ .offset = 0, \
378
+ .field_name = #name, \
379
+ .item = ASN1_ITEM_ref(type), \
380
+ }
381
+
382
+ /* These help with SEQUENCE or CHOICE components */
383
+
384
+ /* used to declare other types */
385
+
386
+ #define ASN1_EX_TYPE(flagsval, tagval, stname, field, type) \
387
+ { \
388
+ .flags = (flagsval), \
389
+ .tag = (tagval), \
390
+ .offset = offsetof(stname, field), \
391
+ .field_name = #field, \
392
+ .item = ASN1_ITEM_ref(type), \
393
+ }
394
+
395
+ /* implicit and explicit helper macros */
396
+
397
+ #define ASN1_IMP_EX(stname, field, type, tag, ex) \
398
+ ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type)
399
+
400
+ #define ASN1_EXP_EX(stname, field, type, tag, ex) \
401
+ ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type)
402
+
403
+ /* Any defined by macros: the field used is in the table itself */
404
+
405
+ #define ASN1_ADB_OBJECT(tblname) \
406
+ { \
407
+ .flags = ASN1_TFLG_ADB_OID, \
408
+ .tag = -1, \
409
+ .offset = 0, \
410
+ .field_name = #tblname, \
411
+ .item = (const ASN1_ITEM *)&(tblname##_adb), \
412
+ }
413
+ #define ASN1_ADB_INTEGER(tblname) \
414
+ { \
415
+ .flags = ASN1_TFLG_ADB_INT, \
416
+ .tag = -1, \
417
+ .offset = 0, \
418
+ .field_name = #tblname, \
419
+ .item = (const ASN1_ITEM *)&(tblname##_adb), \
420
+ }
421
+
422
+ /* Plain simple type */
423
+ #define ASN1_SIMPLE(stname, field, type) \
424
+ ASN1_EX_TYPE(0, 0, stname, field, type)
425
+
426
+ /* OPTIONAL simple type */
427
+ #define ASN1_OPT(stname, field, type) \
428
+ ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type)
429
+
430
+ /* IMPLICIT tagged simple type */
431
+ #define ASN1_IMP(stname, field, type, tag) \
432
+ ASN1_IMP_EX(stname, field, type, tag, 0)
433
+
434
+ /* IMPLICIT tagged OPTIONAL simple type */
435
+ #define ASN1_IMP_OPT(stname, field, type, tag) \
436
+ ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
437
+
438
+ /* Same as above but EXPLICIT */
439
+
440
+ #define ASN1_EXP(stname, field, type, tag) \
441
+ ASN1_EXP_EX(stname, field, type, tag, 0)
442
+ #define ASN1_EXP_OPT(stname, field, type, tag) \
443
+ ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
444
+
445
+ /* SEQUENCE OF type */
446
+ #define ASN1_SEQUENCE_OF(stname, field, type) \
447
+ ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type)
448
+
449
+ /* OPTIONAL SEQUENCE OF */
450
+ #define ASN1_SEQUENCE_OF_OPT(stname, field, type) \
451
+ ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
452
+
453
+ /* Same as above but for SET OF */
454
+
455
+ #define ASN1_SET_OF(stname, field, type) \
456
+ ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type)
457
+
458
+ #define ASN1_SET_OF_OPT(stname, field, type) \
459
+ ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
460
+
461
+ /* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */
462
+
463
+ #define ASN1_IMP_SET_OF(stname, field, type, tag) \
464
+ ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
465
+
466
+ #define ASN1_EXP_SET_OF(stname, field, type, tag) \
467
+ ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
468
+
469
+ #define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \
470
+ ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
471
+
472
+ #define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \
473
+ ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
474
+
475
+ #define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \
476
+ ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
477
+
478
+ #define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \
479
+ ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
480
+
481
+ #define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \
482
+ ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
483
+
484
+ #define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \
485
+ ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
486
+
487
+ /* EXPLICIT using indefinite length constructed form */
488
+ #define ASN1_NDEF_EXP(stname, field, type, tag) \
489
+ ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_NDEF)
490
+
491
+ /* EXPLICIT OPTIONAL using indefinite length constructed form */
492
+ #define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \
493
+ ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF)
494
+
495
+ /* Macros for the ASN1_ADB structure */
496
+
497
+ #define ASN1_ADB(name) \
498
+ static const ASN1_ADB_TABLE name##_adbtbl[]
499
+
500
+ /* In 5b70372d OpenSSL added adb_cb. Ignore this until someone complains. */
501
+ #define ASN1_ADB_END(name, flagsval, field, adb_cb, def, none) \
502
+ ; \
503
+ static const ASN1_ADB name##_adb = { \
504
+ .flags = flagsval, \
505
+ .offset = offsetof(name, field), \
506
+ .tbl = name##_adbtbl, \
507
+ .tblcount = sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
508
+ .default_tt = def, \
509
+ .null_tt = none, \
510
+ }
511
+
512
+ #define ADB_ENTRY(val, template) \
513
+ { \
514
+ .value = val, \
515
+ .tt = template, \
516
+ }
517
+
518
+ #define ASN1_ADB_TEMPLATE(name) \
519
+ static const ASN1_TEMPLATE name##_tt
520
+
521
+ #endif /* !LIBRESSL_INTERNAL */
522
+
523
+ /* This is the ASN1 template structure that defines
524
+ * a wrapper round the actual type. It determines the
525
+ * actual position of the field in the value structure,
526
+ * various flags such as OPTIONAL and the field name.
527
+ */
528
+
529
+ struct ASN1_TEMPLATE_st {
530
+ unsigned long flags; /* Various flags */
531
+ long tag; /* tag, not used if no tagging */
532
+ unsigned long offset; /* Offset of this field in structure */
533
+ const char *field_name; /* Field name */
534
+ ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */
535
+ };
536
+
537
+ /* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */
538
+
539
+ #define ASN1_TEMPLATE_item(t) (t->item_ptr)
540
+ #define ASN1_TEMPLATE_adb(t) (t->item_ptr)
541
+
542
+ typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE;
543
+ typedef struct ASN1_ADB_st ASN1_ADB;
544
+
545
+ struct ASN1_ADB_st {
546
+ unsigned long flags; /* Various flags */
547
+ unsigned long offset; /* Offset of selector field */
548
+ const ASN1_ADB_TABLE *tbl; /* Table of possible types */
549
+ long tblcount; /* Number of entries in tbl */
550
+ const ASN1_TEMPLATE *default_tt; /* Type to use if no match */
551
+ const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */
552
+ };
553
+
554
+ struct ASN1_ADB_TABLE_st {
555
+ long value; /* NID for an object or value for an int */
556
+ const ASN1_TEMPLATE tt; /* item for this value */
557
+ };
558
+
559
+ /* template flags */
560
+
561
+ /* Field is optional */
562
+ #define ASN1_TFLG_OPTIONAL (0x1)
563
+
564
+ /* Field is a SET OF */
565
+ #define ASN1_TFLG_SET_OF (0x1 << 1)
566
+
567
+ /* Field is a SEQUENCE OF */
568
+ #define ASN1_TFLG_SEQUENCE_OF (0x2 << 1)
569
+
570
+ /*
571
+ * Special case: this refers to a SET OF that will be sorted into DER order
572
+ * when encoded *and* the corresponding STACK will be modified to match
573
+ * the new order.
574
+ */
575
+ #define ASN1_TFLG_SET_ORDER (0x3 << 1)
576
+
577
+ /* Mask for SET OF or SEQUENCE OF */
578
+ #define ASN1_TFLG_SK_MASK (0x3 << 1)
579
+
580
+ /*
581
+ * These flags mean the tag should be taken from the tag field. If EXPLICIT
582
+ * then the underlying type is used for the inner tag.
583
+ */
584
+
585
+ /* IMPLICIT tagging */
586
+ #define ASN1_TFLG_IMPTAG (0x1 << 3)
587
+
588
+
589
+ /* EXPLICIT tagging, inner tag from underlying type */
590
+ #define ASN1_TFLG_EXPTAG (0x2 << 3)
591
+
592
+ #define ASN1_TFLG_TAG_MASK (0x3 << 3)
593
+
594
+ /* context specific IMPLICIT */
595
+ #define ASN1_TFLG_IMPLICIT ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT
596
+
597
+ /* context specific EXPLICIT */
598
+ #define ASN1_TFLG_EXPLICIT ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT
599
+
600
+ /*
601
+ * If tagging is in force these determine the type of tag to use. Otherwise
602
+ * the tag is determined by the underlying type. These values reflect the
603
+ * actual octet format.
604
+ */
605
+
606
+ /* Universal tag */
607
+ #define ASN1_TFLG_UNIVERSAL (0x0<<6)
608
+ /* Application tag */
609
+ #define ASN1_TFLG_APPLICATION (0x1<<6)
610
+ /* Context specific tag */
611
+ #define ASN1_TFLG_CONTEXT (0x2<<6)
612
+ /* Private tag */
613
+ #define ASN1_TFLG_PRIVATE (0x3<<6)
614
+
615
+ #define ASN1_TFLG_TAG_CLASS (0x3<<6)
616
+
617
+ /*
618
+ * These are for ANY DEFINED BY type. In this case the 'item' field points
619
+ * to an ASN1_ADB structure which contains a table of values to decode the
620
+ * relevant type.
621
+ */
622
+
623
+ #define ASN1_TFLG_ADB_MASK (0x3<<8)
624
+
625
+ #define ASN1_TFLG_ADB_OID (0x1<<8)
626
+
627
+ #define ASN1_TFLG_ADB_INT (0x1<<9)
628
+
629
+ /*
630
+ * This flag when present in a SEQUENCE OF, SET OF or EXPLICIT causes
631
+ * indefinite length constructed encoding to be used if required.
632
+ */
633
+
634
+ #define ASN1_TFLG_NDEF (0x1<<11)
635
+
636
+ /* This is the actual ASN1 item itself */
637
+
638
+ struct ASN1_ITEM_st {
639
+ char itype; /* The item type, primitive, SEQUENCE, CHOICE or extern */
640
+ long utype; /* underlying type */
641
+ const ASN1_TEMPLATE *templates; /* contents for SEQUENCE or CHOICE */
642
+ long tcount; /* Number of templates if SEQUENCE or CHOICE */
643
+ const void *funcs; /* functions that handle this type */
644
+ long size; /* Structure size (usually) */
645
+ const char *sname; /* Structure name */
646
+ };
647
+
648
+ /*
649
+ * These are values for the itype field and determine how the type is
650
+ * interpreted.
651
+ *
652
+ * For PRIMITIVE types the underlying type determines the behaviour if
653
+ * items is NULL.
654
+ *
655
+ * Otherwise templates must contain a single template and the type is
656
+ * treated in the same way as the type specified in the template.
657
+ *
658
+ * For SEQUENCE types the templates field points to the members, the
659
+ * size field is the structure size.
660
+ *
661
+ * For CHOICE types the templates field points to each possible member
662
+ * (typically a union) and the 'size' field is the offset of the selector.
663
+ *
664
+ * The 'funcs' field is used for application specific functions.
665
+ *
666
+ * The EXTERN type uses a new style d2i/i2d. The new style should be used
667
+ * where possible because it avoids things like the d2i IMPLICIT hack.
668
+ *
669
+ * MSTRING is a multiple string type, it is used for a CHOICE of character
670
+ * strings where the actual strings all occupy an ASN1_STRING structure.
671
+ * In this case the 'utype' field has a special meaning, it is used as a
672
+ * mask of acceptable types using the B_ASN1 constants.
673
+ *
674
+ * NDEF_SEQUENCE is the same as SEQUENCE except that it will use
675
+ * indefinite length constructed encoding if requested.
676
+ *
677
+ */
678
+
679
+ #define ASN1_ITYPE_PRIMITIVE 0x0
680
+
681
+ #define ASN1_ITYPE_SEQUENCE 0x1
682
+
683
+ #define ASN1_ITYPE_CHOICE 0x2
684
+
685
+ #define ASN1_ITYPE_EXTERN 0x4
686
+
687
+ #define ASN1_ITYPE_MSTRING 0x5
688
+
689
+ #define ASN1_ITYPE_NDEF_SEQUENCE 0x6
690
+
691
+ /* Cache for ASN1 tag and length, so we
692
+ * don't keep re-reading it for things
693
+ * like CHOICE
694
+ */
695
+
696
+ struct ASN1_TLC_st {
697
+ char valid; /* Values below are valid */
698
+ int ret; /* return value */
699
+ long plen; /* length */
700
+ int ptag; /* class value */
701
+ int pclass; /* class value */
702
+ int hdrlen; /* header length */
703
+ };
704
+
705
+ /* Typedefs for ASN1 function pointers */
706
+
707
+ typedef ASN1_VALUE * ASN1_new_func(void);
708
+ typedef void ASN1_free_func(ASN1_VALUE *a);
709
+ typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, const unsigned char ** in,
710
+ long length);
711
+ typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in);
712
+
713
+ typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
714
+ const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx);
715
+
716
+ typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
717
+ const ASN1_ITEM *it, int tag, int aclass);
718
+ typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
719
+ typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
720
+
721
+ typedef int ASN1_ex_print_func(BIO *out, ASN1_VALUE **pval, int indent,
722
+ const char *fname, const ASN1_PCTX *pctx);
723
+
724
+ typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont,
725
+ int *putype, const ASN1_ITEM *it);
726
+ typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont,
727
+ int len, int utype, char *free_cont, const ASN1_ITEM *it);
728
+ typedef int ASN1_primitive_print(BIO *out, ASN1_VALUE **pval,
729
+ const ASN1_ITEM *it, int indent, const ASN1_PCTX *pctx);
730
+
731
+ typedef struct ASN1_EXTERN_FUNCS_st {
732
+ void *app_data;
733
+ ASN1_ex_new_func *asn1_ex_new;
734
+ ASN1_ex_free_func *asn1_ex_free;
735
+ ASN1_ex_free_func *asn1_ex_clear;
736
+ ASN1_ex_d2i *asn1_ex_d2i;
737
+ ASN1_ex_i2d *asn1_ex_i2d;
738
+ ASN1_ex_print_func *asn1_ex_print;
739
+ } ASN1_EXTERN_FUNCS;
740
+
741
+ typedef struct ASN1_PRIMITIVE_FUNCS_st {
742
+ void *app_data;
743
+ unsigned long flags;
744
+ ASN1_ex_new_func *prim_new;
745
+ ASN1_ex_free_func *prim_free;
746
+ ASN1_ex_free_func *prim_clear;
747
+ ASN1_primitive_c2i *prim_c2i;
748
+ ASN1_primitive_i2c *prim_i2c;
749
+ ASN1_primitive_print *prim_print;
750
+ } ASN1_PRIMITIVE_FUNCS;
751
+
752
+ /*
753
+ * This is the ASN1_AUX structure: it handles various miscellaneous
754
+ * requirements. For example the use of reference counts and an
755
+ * informational callback.
756
+ *
757
+ * The "informational callback" is called at various points during
758
+ * the ASN1 encoding and decoding. It can be used to provide minor
759
+ * customisation of the structures used. This is most useful where
760
+ * the supplied routines *almost* do the right thing but need some
761
+ * extra help at a few points. If the callback returns zero then it
762
+ * is assumed a fatal error has occurred and the main operation
763
+ * should be abandoned.
764
+ *
765
+ * If major changes in the default behaviour are required then an
766
+ * external type is more appropriate.
767
+ */
768
+
769
+ typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it,
770
+ void *exarg);
771
+
772
+ typedef struct ASN1_AUX_st {
773
+ void *app_data;
774
+ int flags;
775
+ int ref_offset; /* Offset of reference value */
776
+ int ref_lock; /* Lock type to use */
777
+ ASN1_aux_cb *asn1_cb;
778
+ int enc_offset; /* Offset of ASN1_ENCODING structure */
779
+ } ASN1_AUX;
780
+
781
+ /* For print related callbacks exarg points to this structure */
782
+ typedef struct ASN1_PRINT_ARG_st {
783
+ BIO *out;
784
+ int indent;
785
+ const ASN1_PCTX *pctx;
786
+ } ASN1_PRINT_ARG;
787
+
788
+ /* For streaming related callbacks exarg points to this structure */
789
+ typedef struct ASN1_STREAM_ARG_st {
790
+ /* BIO to stream through */
791
+ BIO *out;
792
+ /* BIO with filters appended */
793
+ BIO *ndef_bio;
794
+ /* Streaming I/O boundary */
795
+ unsigned char **boundary;
796
+ } ASN1_STREAM_ARG;
797
+
798
+ /* Flags in ASN1_AUX */
799
+
800
+ /* Use a reference count */
801
+ #define ASN1_AFLG_REFCOUNT 1
802
+ /* Save the encoding of structure (useful for signatures) */
803
+ #define ASN1_AFLG_ENCODING 2
804
+
805
+ /* operation values for asn1_cb */
806
+
807
+ #define ASN1_OP_NEW_PRE 0
808
+ #define ASN1_OP_NEW_POST 1
809
+ #define ASN1_OP_FREE_PRE 2
810
+ #define ASN1_OP_FREE_POST 3
811
+ #define ASN1_OP_D2I_PRE 4
812
+ #define ASN1_OP_D2I_POST 5
813
+ #define ASN1_OP_I2D_PRE 6
814
+ #define ASN1_OP_I2D_POST 7
815
+ #define ASN1_OP_PRINT_PRE 8
816
+ #define ASN1_OP_PRINT_POST 9
817
+ #define ASN1_OP_STREAM_PRE 10
818
+ #define ASN1_OP_STREAM_POST 11
819
+ #define ASN1_OP_DETACHED_PRE 12
820
+ #define ASN1_OP_DETACHED_POST 13
821
+
822
+ #ifndef LIBRESSL_INTERNAL
823
+
824
+ /* Macro to implement a primitive type */
825
+ #define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0)
826
+ #define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \
827
+ ASN1_ITEM_start(itname) \
828
+ .itype = ASN1_ITYPE_PRIMITIVE, \
829
+ .utype = V_##vname, \
830
+ .templates = NULL, \
831
+ .tcount = 0, \
832
+ .funcs = NULL, \
833
+ .size = ex, \
834
+ .sname = #itname, \
835
+ ASN1_ITEM_end(itname)
836
+
837
+ /* Macro to implement a multi string type */
838
+ #define IMPLEMENT_ASN1_MSTRING(itname, mask) \
839
+ ASN1_ITEM_start(itname) \
840
+ .itype = ASN1_ITYPE_MSTRING, \
841
+ .utype = mask, \
842
+ .templates = NULL, \
843
+ .tcount = 0, \
844
+ .funcs = NULL, \
845
+ .size = sizeof(ASN1_STRING), \
846
+ .sname = #itname, \
847
+ ASN1_ITEM_end(itname)
848
+ #define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \
849
+ ASN1_ITEM_start(sname) \
850
+ .itype = ASN1_ITYPE_EXTERN, \
851
+ .utype = tag, \
852
+ .templates = NULL, \
853
+ .tcount = 0, \
854
+ .funcs = &fptrs, \
855
+ .size = 0, \
856
+ .sname = #sname, \
857
+ ASN1_ITEM_end(sname)
858
+
859
+ /* Macro to implement standard functions in terms of ASN1_ITEM structures */
860
+
861
+ #define IMPLEMENT_ASN1_FUNCTIONS(stname) \
862
+ IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname)
863
+
864
+ #define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) \
865
+ IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname)
866
+
867
+ #define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \
868
+ IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname)
869
+
870
+ #define IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(stname) \
871
+ IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(static, stname, stname, stname)
872
+
873
+ #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \
874
+ IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname)
875
+
876
+ #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(pre, stname, itname, fname) \
877
+ pre stname * \
878
+ fname##_new(void) \
879
+ { \
880
+ return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
881
+ } \
882
+ pre void \
883
+ fname##_free(stname *a) \
884
+ { \
885
+ ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
886
+ }
887
+
888
+ #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \
889
+ stname * \
890
+ fname##_new(void) \
891
+ { \
892
+ return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
893
+ } \
894
+ void \
895
+ fname##_free(stname *a) \
896
+ { \
897
+ ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
898
+ }
899
+
900
+ #define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \
901
+ IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
902
+ IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
903
+
904
+ #define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
905
+ stname * \
906
+ d2i_##fname(stname **a, const unsigned char **in, long len) \
907
+ { \
908
+ return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, \
909
+ len, ASN1_ITEM_rptr(itname)); \
910
+ } \
911
+ int \
912
+ i2d_##fname(stname *a, unsigned char **out) \
913
+ { \
914
+ return ASN1_item_i2d((ASN1_VALUE *)a, out, \
915
+ ASN1_ITEM_rptr(itname)); \
916
+ }
917
+
918
+ #define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \
919
+ int \
920
+ i2d_##stname##_NDEF(stname *a, unsigned char **out) \
921
+ { \
922
+ return ASN1_item_ndef_i2d((ASN1_VALUE *)a, out, \
923
+ ASN1_ITEM_rptr(stname)); \
924
+ }
925
+
926
+ /* This includes evil casts to remove const: they will go away when full
927
+ * ASN1 constification is done.
928
+ */
929
+ #define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
930
+ stname * \
931
+ d2i_##fname(stname **a, const unsigned char **in, long len) \
932
+ { \
933
+ return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, \
934
+ len, ASN1_ITEM_rptr(itname)); \
935
+ } \
936
+ int \
937
+ i2d_##fname(const stname *a, unsigned char **out) \
938
+ { \
939
+ return ASN1_item_i2d((ASN1_VALUE *)a, out, \
940
+ ASN1_ITEM_rptr(itname)); \
941
+ }
942
+
943
+ #define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \
944
+ stname * \
945
+ stname##_dup(stname *x) \
946
+ { \
947
+ return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \
948
+ }
949
+
950
+ #define IMPLEMENT_ASN1_PRINT_FUNCTION(stname) \
951
+ IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, stname, stname)
952
+
953
+ #define IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, itname, fname) \
954
+ int \
955
+ fname##_print_ctx(BIO *out, stname *x, int indent, \
956
+ const ASN1_PCTX *pctx) \
957
+ { \
958
+ return ASN1_item_print(out, (ASN1_VALUE *)x, indent, \
959
+ ASN1_ITEM_rptr(itname), pctx); \
960
+ }
961
+
962
+ #define IMPLEMENT_ASN1_FUNCTIONS_const(name) \
963
+ IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name)
964
+
965
+ #define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \
966
+ IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
967
+ IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
968
+
969
+ #endif /* !LIBRESSL_INTERNAL */
970
+
971
+ /* external definitions for primitive types */
972
+
973
+ extern const ASN1_ITEM ASN1_BOOLEAN_it;
974
+ extern const ASN1_ITEM ASN1_TBOOLEAN_it;
975
+ extern const ASN1_ITEM ASN1_FBOOLEAN_it;
976
+ extern const ASN1_ITEM ASN1_SEQUENCE_it;
977
+ extern const ASN1_ITEM BIGNUM_it;
978
+ extern const ASN1_ITEM LONG_it;
979
+ extern const ASN1_ITEM ZLONG_it;
980
+ extern const ASN1_ITEM CBIGNUM_it;
981
+
982
+ DECLARE_STACK_OF(ASN1_VALUE)
983
+
984
+ /* Functions used internally by the ASN1 code */
985
+
986
+ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
987
+ void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
988
+ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
989
+ const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx);
990
+ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
991
+ const ASN1_ITEM *it, int tag, int aclass);
992
+
993
+ #ifdef __cplusplus
994
+ }
995
+ #endif
996
+ #endif