asn1t.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. /*
  2. * WARNING: do not edit!
  3. * Generated by makefile from include\openssl\asn1t.h.in
  4. *
  5. * Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
  6. *
  7. * Licensed under the Apache License 2.0 (the "License"). You may not use
  8. * this file except in compliance with the License. You can obtain a copy
  9. * in the file LICENSE in the source distribution or at
  10. * https://www.openssl.org/source/license.html
  11. */
  12. /* clang-format off */
  13. /* clang-format on */
  14. #ifndef OPENSSL_ASN1T_H
  15. #define OPENSSL_ASN1T_H
  16. #pragma once
  17. #include <openssl/macros.h>
  18. #ifndef OPENSSL_NO_DEPRECATED_3_0
  19. #define HEADER_ASN1T_H
  20. #endif
  21. #include <stddef.h>
  22. #include <openssl/e_os2.h>
  23. #include <openssl/asn1.h>
  24. #ifdef OPENSSL_BUILD_SHLIBCRYPTO
  25. #undef OPENSSL_EXTERN
  26. #define OPENSSL_EXTERN OPENSSL_EXPORT
  27. #endif
  28. /* ASN1 template defines, structures and functions */
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /*-
  33. * These are the possible values for the itype field of the
  34. * ASN1_ITEM structure and determine how it is interpreted.
  35. *
  36. * For PRIMITIVE types the underlying type
  37. * determines the behaviour if items is NULL.
  38. *
  39. * Otherwise templates must contain a single
  40. * template and the type is treated in the
  41. * same way as the type specified in the template.
  42. *
  43. * For SEQUENCE types the templates field points
  44. * to the members, the size field is the
  45. * structure size.
  46. *
  47. * For CHOICE types the templates field points
  48. * to each possible member (typically a union)
  49. * and the 'size' field is the offset of the
  50. * selector.
  51. *
  52. * The 'funcs' field is used for application-specific
  53. * data and functions.
  54. *
  55. * The EXTERN type uses a new style d2i/i2d.
  56. * The new style should be used where possible
  57. * because it avoids things like the d2i IMPLICIT
  58. * hack.
  59. *
  60. * MSTRING is a multiple string type, it is used
  61. * for a CHOICE of character strings where the
  62. * actual strings all occupy an ASN1_STRING
  63. * structure. In this case the 'utype' field
  64. * has a special meaning, it is used as a mask
  65. * of acceptable types using the B_ASN1 constants.
  66. *
  67. * NDEF_SEQUENCE is the same as SEQUENCE except
  68. * that it will use indefinite length constructed
  69. * encoding if requested.
  70. *
  71. */
  72. #define ASN1_ITYPE_PRIMITIVE 0x0
  73. #define ASN1_ITYPE_SEQUENCE 0x1
  74. #define ASN1_ITYPE_CHOICE 0x2
  75. /* unused value 0x3 */
  76. #define ASN1_ITYPE_EXTERN 0x4
  77. #define ASN1_ITYPE_MSTRING 0x5
  78. #define ASN1_ITYPE_NDEF_SEQUENCE 0x6
  79. /* Macro to obtain ASN1_ADB pointer from a type (only used internally) */
  80. #define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)((iptr)()))
  81. /* Macros for start and end of ASN1_ITEM definition */
  82. #define ASN1_ITEM_start(itname) \
  83. const ASN1_ITEM *itname##_it(void) \
  84. { \
  85. static const ASN1_ITEM local_it = {
  86. #define static_ASN1_ITEM_start(itname) \
  87. static ASN1_ITEM_start(itname)
  88. #define ASN1_ITEM_end(itname) \
  89. } \
  90. ; \
  91. return &local_it; \
  92. }
  93. /* Macros to aid ASN1 template writing */
  94. #define ASN1_ITEM_TEMPLATE(tname) \
  95. static const ASN1_TEMPLATE tname##_item_tt
  96. #define ASN1_ITEM_TEMPLATE_END(tname) \
  97. ; \
  98. ASN1_ITEM_start(tname) \
  99. ASN1_ITYPE_PRIMITIVE, \
  100. -1, \
  101. &tname##_item_tt, \
  102. 0, \
  103. NULL, \
  104. 0, \
  105. #tname ASN1_ITEM_end(tname)
  106. #define static_ASN1_ITEM_TEMPLATE_END(tname) \
  107. ; \
  108. static_ASN1_ITEM_start(tname) \
  109. ASN1_ITYPE_PRIMITIVE, \
  110. -1, \
  111. &tname##_item_tt, \
  112. 0, \
  113. NULL, \
  114. 0, \
  115. #tname ASN1_ITEM_end(tname)
  116. /* This is a ASN1 type which just embeds a template */
  117. /*-
  118. * This pair helps declare a SEQUENCE. We can do:
  119. *
  120. * ASN1_SEQUENCE(stname) = {
  121. * ... SEQUENCE components ...
  122. * } ASN1_SEQUENCE_END(stname)
  123. *
  124. * This will produce an ASN1_ITEM called stname_it
  125. * for a structure called stname.
  126. *
  127. * If you want the same structure but a different
  128. * name then use:
  129. *
  130. * ASN1_SEQUENCE(itname) = {
  131. * ... SEQUENCE components ...
  132. * } ASN1_SEQUENCE_END_name(stname, itname)
  133. *
  134. * This will create an item called itname_it using
  135. * a structure called stname.
  136. */
  137. #define ASN1_SEQUENCE(tname) \
  138. static const ASN1_TEMPLATE tname##_seq_tt[]
  139. #define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname)
  140. #define static_ASN1_SEQUENCE_END(stname) static_ASN1_SEQUENCE_END_name(stname, stname)
  141. #define ASN1_SEQUENCE_END_name(stname, tname) \
  142. ; \
  143. ASN1_ITEM_start(tname) \
  144. ASN1_ITYPE_SEQUENCE, \
  145. V_ASN1_SEQUENCE, \
  146. tname##_seq_tt, \
  147. sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \
  148. NULL, \
  149. sizeof(stname), \
  150. #tname ASN1_ITEM_end(tname)
  151. #define static_ASN1_SEQUENCE_END_name(stname, tname) \
  152. ; \
  153. static_ASN1_ITEM_start(tname) \
  154. ASN1_ITYPE_SEQUENCE, \
  155. V_ASN1_SEQUENCE, \
  156. tname##_seq_tt, \
  157. sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \
  158. NULL, \
  159. sizeof(stname), \
  160. #stname ASN1_ITEM_end(tname)
  161. #define ASN1_NDEF_SEQUENCE(tname) \
  162. ASN1_SEQUENCE(tname)
  163. #define ASN1_NDEF_SEQUENCE_cb(tname, cb) \
  164. ASN1_SEQUENCE_cb(tname, cb)
  165. #define ASN1_SEQUENCE_cb(tname, cb) \
  166. static const ASN1_AUX tname##_aux = { NULL, 0, 0, 0, cb, 0, NULL }; \
  167. ASN1_SEQUENCE(tname)
  168. #define ASN1_SEQUENCE_const_cb(tname, const_cb) \
  169. static const ASN1_AUX tname##_aux = { NULL, ASN1_AFLG_CONST_CB, 0, 0, NULL, 0, const_cb }; \
  170. ASN1_SEQUENCE(tname)
  171. #define ASN1_SEQUENCE_cb_const_cb(tname, cb, const_cb) \
  172. static const ASN1_AUX tname##_aux = { NULL, ASN1_AFLG_CONST_CB, 0, 0, cb, 0, const_cb }; \
  173. ASN1_SEQUENCE(tname)
  174. #define ASN1_SEQUENCE_ref(tname, cb) \
  175. static const ASN1_AUX tname##_aux = { NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), offsetof(tname, lock), cb, 0, NULL }; \
  176. ASN1_SEQUENCE(tname)
  177. #define ASN1_SEQUENCE_enc(tname, enc, cb) \
  178. static const ASN1_AUX tname##_aux = { NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc), NULL }; \
  179. ASN1_SEQUENCE(tname)
  180. #define ASN1_NDEF_SEQUENCE_END(tname) \
  181. ; \
  182. ASN1_ITEM_start(tname) \
  183. ASN1_ITYPE_NDEF_SEQUENCE, \
  184. V_ASN1_SEQUENCE, \
  185. tname##_seq_tt, \
  186. sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \
  187. NULL, \
  188. sizeof(tname), \
  189. #tname ASN1_ITEM_end(tname)
  190. #define static_ASN1_NDEF_SEQUENCE_END(tname) \
  191. ; \
  192. static_ASN1_ITEM_start(tname) \
  193. ASN1_ITYPE_NDEF_SEQUENCE, \
  194. V_ASN1_SEQUENCE, \
  195. tname##_seq_tt, \
  196. sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \
  197. NULL, \
  198. sizeof(tname), \
  199. #tname ASN1_ITEM_end(tname)
  200. #define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
  201. #define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
  202. #define static_ASN1_SEQUENCE_END_cb(stname, tname) static_ASN1_SEQUENCE_END_ref(stname, tname)
  203. #define ASN1_SEQUENCE_END_ref(stname, tname) \
  204. ; \
  205. ASN1_ITEM_start(tname) \
  206. ASN1_ITYPE_SEQUENCE, \
  207. V_ASN1_SEQUENCE, \
  208. tname##_seq_tt, \
  209. sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \
  210. &tname##_aux, \
  211. sizeof(stname), \
  212. #tname ASN1_ITEM_end(tname)
  213. #define static_ASN1_SEQUENCE_END_ref(stname, tname) \
  214. ; \
  215. static_ASN1_ITEM_start(tname) \
  216. ASN1_ITYPE_SEQUENCE, \
  217. V_ASN1_SEQUENCE, \
  218. tname##_seq_tt, \
  219. sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \
  220. &tname##_aux, \
  221. sizeof(stname), \
  222. #stname ASN1_ITEM_end(tname)
  223. #define ASN1_NDEF_SEQUENCE_END_cb(stname, tname) \
  224. ; \
  225. ASN1_ITEM_start(tname) \
  226. ASN1_ITYPE_NDEF_SEQUENCE, \
  227. V_ASN1_SEQUENCE, \
  228. tname##_seq_tt, \
  229. sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \
  230. &tname##_aux, \
  231. sizeof(stname), \
  232. #stname ASN1_ITEM_end(tname)
  233. /*-
  234. * This pair helps declare a CHOICE type. We can do:
  235. *
  236. * ASN1_CHOICE(chname) = {
  237. * ... CHOICE options ...
  238. * ASN1_CHOICE_END(chname)
  239. *
  240. * This will produce an ASN1_ITEM called chname_it
  241. * for a structure called chname. The structure
  242. * definition must look like this:
  243. * typedef struct {
  244. * int type;
  245. * union {
  246. * ASN1_SOMETHING *opt1;
  247. * ASN1_SOMEOTHER *opt2;
  248. * } value;
  249. * } chname;
  250. *
  251. * the name of the selector must be 'type'.
  252. * to use an alternative selector name use the
  253. * ASN1_CHOICE_END_selector() version.
  254. */
  255. #define ASN1_CHOICE(tname) \
  256. static const ASN1_TEMPLATE tname##_ch_tt[]
  257. #define ASN1_CHOICE_cb(tname, cb) \
  258. static const ASN1_AUX tname##_aux = { NULL, 0, 0, 0, cb, 0, NULL }; \
  259. ASN1_CHOICE(tname)
  260. #define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname)
  261. #define static_ASN1_CHOICE_END(stname) static_ASN1_CHOICE_END_name(stname, stname)
  262. #define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type)
  263. #define static_ASN1_CHOICE_END_name(stname, tname) static_ASN1_CHOICE_END_selector(stname, tname, type)
  264. #define ASN1_CHOICE_END_selector(stname, tname, selname) \
  265. ; \
  266. ASN1_ITEM_start(tname) \
  267. ASN1_ITYPE_CHOICE, \
  268. offsetof(stname, selname), \
  269. tname##_ch_tt, \
  270. sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE), \
  271. NULL, \
  272. sizeof(stname), \
  273. #stname ASN1_ITEM_end(tname)
  274. #define static_ASN1_CHOICE_END_selector(stname, tname, selname) \
  275. ; \
  276. static_ASN1_ITEM_start(tname) \
  277. ASN1_ITYPE_CHOICE, \
  278. offsetof(stname, selname), \
  279. tname##_ch_tt, \
  280. sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE), \
  281. NULL, \
  282. sizeof(stname), \
  283. #stname ASN1_ITEM_end(tname)
  284. #define ASN1_CHOICE_END_cb(stname, tname, selname) \
  285. ; \
  286. ASN1_ITEM_start(tname) \
  287. ASN1_ITYPE_CHOICE, \
  288. offsetof(stname, selname), \
  289. tname##_ch_tt, \
  290. sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE), \
  291. &tname##_aux, \
  292. sizeof(stname), \
  293. #stname ASN1_ITEM_end(tname)
  294. /* This helps with the template wrapper form of ASN1_ITEM */
  295. #define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \
  296. (flags), (tag), 0, \
  297. #name, ASN1_ITEM_ref(type) \
  298. }
  299. /* These help with SEQUENCE or CHOICE components */
  300. /* used to declare other types */
  301. #define ASN1_EX_TYPE(flags, tag, stname, field, type) { \
  302. (flags), (tag), offsetof(stname, field), \
  303. #field, ASN1_ITEM_ref(type) \
  304. }
  305. /* implicit and explicit helper macros */
  306. #define ASN1_IMP_EX(stname, field, type, tag, ex) \
  307. ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | (ex), tag, stname, field, type)
  308. #define ASN1_EXP_EX(stname, field, type, tag, ex) \
  309. ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | (ex), tag, stname, field, type)
  310. /* Any defined by macros: the field used is in the table itself */
  311. #define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb }
  312. #define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb }
  313. /* Plain simple type */
  314. #define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0, 0, stname, field, type)
  315. /* Embedded simple type */
  316. #define ASN1_EMBED(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_EMBED, 0, stname, field, type)
  317. /* OPTIONAL simple type */
  318. #define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type)
  319. #define ASN1_OPT_EMBED(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL | ASN1_TFLG_EMBED, 0, stname, field, type)
  320. /* IMPLICIT tagged simple type */
  321. #define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0)
  322. #define ASN1_IMP_EMBED(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_EMBED)
  323. /* IMPLICIT tagged OPTIONAL simple type */
  324. #define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
  325. #define ASN1_IMP_OPT_EMBED(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL | ASN1_TFLG_EMBED)
  326. /* Same as above but EXPLICIT */
  327. #define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0)
  328. #define ASN1_EXP_EMBED(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_EMBED)
  329. #define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
  330. #define ASN1_EXP_OPT_EMBED(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL | ASN1_TFLG_EMBED)
  331. /* SEQUENCE OF type */
  332. #define ASN1_SEQUENCE_OF(stname, field, type) \
  333. ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type)
  334. /* OPTIONAL SEQUENCE OF */
  335. #define ASN1_SEQUENCE_OF_OPT(stname, field, type) \
  336. ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL, 0, stname, field, type)
  337. /* Same as above but for SET OF */
  338. #define ASN1_SET_OF(stname, field, type) \
  339. ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type)
  340. #define ASN1_SET_OF_OPT(stname, field, type) \
  341. ASN1_EX_TYPE(ASN1_TFLG_SET_OF | ASN1_TFLG_OPTIONAL, 0, stname, field, type)
  342. /* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */
  343. #define ASN1_IMP_SET_OF(stname, field, type, tag) \
  344. ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
  345. #define ASN1_EXP_SET_OF(stname, field, type, tag) \
  346. ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
  347. #define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \
  348. ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF | ASN1_TFLG_OPTIONAL)
  349. #define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \
  350. ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF | ASN1_TFLG_OPTIONAL)
  351. #define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \
  352. ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
  353. #define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \
  354. ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL)
  355. #define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \
  356. ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
  357. #define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \
  358. ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL)
  359. /* EXPLICIT using indefinite length constructed form */
  360. #define ASN1_NDEF_EXP(stname, field, type, tag) \
  361. ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_NDEF)
  362. /* EXPLICIT OPTIONAL using indefinite length constructed form */
  363. #define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \
  364. ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL | ASN1_TFLG_NDEF)
  365. /* Macros for the ASN1_ADB structure */
  366. #define ASN1_ADB(name) \
  367. static const ASN1_ADB_TABLE name##_adbtbl[]
  368. #define ASN1_ADB_END(name, flags, field, adb_cb, def, none) \
  369. ; \
  370. static const ASN1_ITEM *name##_adb(void) \
  371. { \
  372. static const ASN1_ADB internal_adb = { \
  373. flags, \
  374. offsetof(name, field), \
  375. adb_cb, \
  376. name##_adbtbl, \
  377. sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE), \
  378. def, \
  379. none \
  380. }; \
  381. return (const ASN1_ITEM *)&internal_adb; \
  382. } \
  383. void dummy_function(void)
  384. #define ADB_ENTRY(val, template) { val, template }
  385. #define ASN1_ADB_TEMPLATE(name) \
  386. static const ASN1_TEMPLATE name##_tt
  387. /*
  388. * This is the ASN1 template structure that defines a wrapper round the
  389. * actual type. It determines the actual position of the field in the value
  390. * structure, various flags such as OPTIONAL and the field name.
  391. */
  392. struct ASN1_TEMPLATE_st {
  393. unsigned long flags; /* Various flags */
  394. long tag; /* tag, not used if no tagging */
  395. unsigned long offset; /* Offset of this field in structure */
  396. const char *field_name; /* Field name */
  397. ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */
  398. };
  399. /* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */
  400. #define ASN1_TEMPLATE_item(t) (t->item_ptr)
  401. #define ASN1_TEMPLATE_adb(t) (t->item_ptr)
  402. typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE;
  403. typedef struct ASN1_ADB_st ASN1_ADB;
  404. struct ASN1_ADB_st {
  405. unsigned long flags; /* Various flags */
  406. unsigned long offset; /* Offset of selector field */
  407. int (*adb_cb)(long *psel); /* Application callback */
  408. const ASN1_ADB_TABLE *tbl; /* Table of possible types */
  409. long tblcount; /* Number of entries in tbl */
  410. const ASN1_TEMPLATE *default_tt; /* Type to use if no match */
  411. const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */
  412. };
  413. struct ASN1_ADB_TABLE_st {
  414. long value; /* NID for an object or value for an int */
  415. const ASN1_TEMPLATE tt; /* item for this value */
  416. };
  417. /* template flags */
  418. /* Field is optional */
  419. #define ASN1_TFLG_OPTIONAL (0x1)
  420. /* Field is a SET OF */
  421. #define ASN1_TFLG_SET_OF (0x1 << 1)
  422. /* Field is a SEQUENCE OF */
  423. #define ASN1_TFLG_SEQUENCE_OF (0x2 << 1)
  424. /*
  425. * Special case: this refers to a SET OF that will be sorted into DER order
  426. * when encoded *and* the corresponding STACK will be modified to match the
  427. * new order.
  428. */
  429. #define ASN1_TFLG_SET_ORDER (0x3 << 1)
  430. /* Mask for SET OF or SEQUENCE OF */
  431. #define ASN1_TFLG_SK_MASK (0x3 << 1)
  432. /*
  433. * These flags mean the tag should be taken from the tag field. If EXPLICIT
  434. * then the underlying type is used for the inner tag.
  435. */
  436. /* IMPLICIT tagging */
  437. #define ASN1_TFLG_IMPTAG (0x1 << 3)
  438. /* EXPLICIT tagging, inner tag from underlying type */
  439. #define ASN1_TFLG_EXPTAG (0x2 << 3)
  440. #define ASN1_TFLG_TAG_MASK (0x3 << 3)
  441. /* context specific IMPLICIT */
  442. #define ASN1_TFLG_IMPLICIT (ASN1_TFLG_IMPTAG | ASN1_TFLG_CONTEXT)
  443. /* context specific EXPLICIT */
  444. #define ASN1_TFLG_EXPLICIT (ASN1_TFLG_EXPTAG | ASN1_TFLG_CONTEXT)
  445. /*
  446. * If tagging is in force these determine the type of tag to use. Otherwise
  447. * the tag is determined by the underlying type. These values reflect the
  448. * actual octet format.
  449. */
  450. /* Universal tag */
  451. #define ASN1_TFLG_UNIVERSAL (0x0 << 6)
  452. /* Application tag */
  453. #define ASN1_TFLG_APPLICATION (0x1 << 6)
  454. /* Context specific tag */
  455. #define ASN1_TFLG_CONTEXT (0x2 << 6)
  456. /* Private tag */
  457. #define ASN1_TFLG_PRIVATE (0x3 << 6)
  458. #define ASN1_TFLG_TAG_CLASS (0x3 << 6)
  459. /*
  460. * These are for ANY DEFINED BY type. In this case the 'item' field points to
  461. * an ASN1_ADB structure which contains a table of values to decode the
  462. * relevant type
  463. */
  464. #define ASN1_TFLG_ADB_MASK (0x3 << 8)
  465. #define ASN1_TFLG_ADB_OID (0x1 << 8)
  466. #define ASN1_TFLG_ADB_INT (0x1 << 9)
  467. /*
  468. * This flag when present in a SEQUENCE OF, SET OF or EXPLICIT causes
  469. * indefinite length constructed encoding to be used if required.
  470. */
  471. #define ASN1_TFLG_NDEF (0x1 << 11)
  472. /* Field is embedded and not a pointer */
  473. #define ASN1_TFLG_EMBED (0x1 << 12)
  474. /* This is the actual ASN1 item itself */
  475. struct ASN1_ITEM_st {
  476. char itype; /* The item type, primitive, SEQUENCE, CHOICE
  477. * or extern */
  478. long utype; /* underlying type */
  479. const ASN1_TEMPLATE *templates; /* If SEQUENCE or CHOICE this contains
  480. * the contents */
  481. long tcount; /* Number of templates if SEQUENCE or CHOICE */
  482. const void *funcs; /* further data and type-specific functions */
  483. /* funcs can be ASN1_PRIMITIVE_FUNCS*, ASN1_EXTERN_FUNCS*, or ASN1_AUX* */
  484. long size; /* Structure size (usually) */
  485. const char *sname; /* Structure name */
  486. };
  487. /*
  488. * Cache for ASN1 tag and length, so we don't keep re-reading it for things
  489. * like CHOICE
  490. */
  491. struct ASN1_TLC_st {
  492. char valid; /* Values below are valid */
  493. int ret; /* return value */
  494. long plen; /* length */
  495. int ptag; /* class value */
  496. int pclass; /* class value */
  497. int hdrlen; /* header length */
  498. };
  499. /* Typedefs for ASN1 function pointers */
  500. typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
  501. const ASN1_ITEM *it, int tag, int aclass, char opt,
  502. ASN1_TLC *ctx);
  503. typedef int ASN1_ex_d2i_ex(ASN1_VALUE **pval, const unsigned char **in, long len,
  504. const ASN1_ITEM *it, int tag, int aclass, char opt,
  505. ASN1_TLC *ctx, OSSL_LIB_CTX *libctx,
  506. const char *propq);
  507. typedef int ASN1_ex_i2d(const ASN1_VALUE **pval, unsigned char **out,
  508. const ASN1_ITEM *it, int tag, int aclass);
  509. typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
  510. typedef int ASN1_ex_new_ex_func(ASN1_VALUE **pval, const ASN1_ITEM *it,
  511. OSSL_LIB_CTX *libctx, const char *propq);
  512. typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
  513. typedef int ASN1_ex_print_func(BIO *out, const ASN1_VALUE **pval,
  514. int indent, const char *fname,
  515. const ASN1_PCTX *pctx);
  516. typedef int ASN1_primitive_i2c(const ASN1_VALUE **pval, unsigned char *cont,
  517. int *putype, const ASN1_ITEM *it);
  518. typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont,
  519. int len, int utype, char *free_cont,
  520. const ASN1_ITEM *it);
  521. typedef int ASN1_primitive_print(BIO *out, const ASN1_VALUE **pval,
  522. const ASN1_ITEM *it, int indent,
  523. const ASN1_PCTX *pctx);
  524. typedef struct ASN1_EXTERN_FUNCS_st {
  525. void *app_data;
  526. ASN1_ex_new_func *asn1_ex_new;
  527. ASN1_ex_free_func *asn1_ex_free;
  528. ASN1_ex_free_func *asn1_ex_clear;
  529. ASN1_ex_d2i *asn1_ex_d2i;
  530. ASN1_ex_i2d *asn1_ex_i2d;
  531. ASN1_ex_print_func *asn1_ex_print;
  532. ASN1_ex_new_ex_func *asn1_ex_new_ex;
  533. ASN1_ex_d2i_ex *asn1_ex_d2i_ex;
  534. } ASN1_EXTERN_FUNCS;
  535. typedef struct ASN1_PRIMITIVE_FUNCS_st {
  536. void *app_data;
  537. unsigned long flags;
  538. ASN1_ex_new_func *prim_new;
  539. ASN1_ex_free_func *prim_free;
  540. ASN1_ex_free_func *prim_clear;
  541. ASN1_primitive_c2i *prim_c2i;
  542. ASN1_primitive_i2c *prim_i2c;
  543. ASN1_primitive_print *prim_print;
  544. } ASN1_PRIMITIVE_FUNCS;
  545. /*
  546. * This is the ASN1_AUX structure: it handles various miscellaneous
  547. * requirements. For example the use of reference counts and an informational
  548. * callback. The "informational callback" is called at various points during
  549. * the ASN1 encoding and decoding. It can be used to provide minor
  550. * customisation of the structures used. This is most useful where the
  551. * supplied routines *almost* do the right thing but need some extra help at
  552. * a few points. If the callback returns zero then it is assumed a fatal
  553. * error has occurred and the main operation should be abandoned. If major
  554. * changes in the default behaviour are required then an external type is
  555. * more appropriate.
  556. * For the operations ASN1_OP_I2D_PRE, ASN1_OP_I2D_POST, ASN1_OP_PRINT_PRE, and
  557. * ASN1_OP_PRINT_POST, meanwhile a variant of the callback with const parameter
  558. * 'in' is provided to make clear statically that its input is not modified. If
  559. * and only if this variant is in use the flag ASN1_AFLG_CONST_CB must be set.
  560. */
  561. typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it,
  562. void *exarg);
  563. typedef int ASN1_aux_const_cb(int operation, const ASN1_VALUE **in,
  564. const ASN1_ITEM *it, void *exarg);
  565. typedef struct ASN1_AUX_st {
  566. void *app_data;
  567. int flags;
  568. int ref_offset; /* Offset of reference value */
  569. int ref_lock; /* Offset of lock value */
  570. ASN1_aux_cb *asn1_cb;
  571. int enc_offset; /* Offset of ASN1_ENCODING structure */
  572. ASN1_aux_const_cb *asn1_const_cb; /* for ASN1_OP_I2D_ and ASN1_OP_PRINT_ */
  573. } ASN1_AUX;
  574. /* For print related callbacks exarg points to this structure */
  575. typedef struct ASN1_PRINT_ARG_st {
  576. BIO *out;
  577. int indent;
  578. const ASN1_PCTX *pctx;
  579. } ASN1_PRINT_ARG;
  580. /* For streaming related callbacks exarg points to this structure */
  581. typedef struct ASN1_STREAM_ARG_st {
  582. /* BIO to stream through */
  583. BIO *out;
  584. /* BIO with filters appended */
  585. BIO *ndef_bio;
  586. /* Streaming I/O boundary */
  587. unsigned char **boundary;
  588. } ASN1_STREAM_ARG;
  589. /* Flags in ASN1_AUX */
  590. /* Use a reference count */
  591. #define ASN1_AFLG_REFCOUNT 1
  592. /* Save the encoding of structure (useful for signatures) */
  593. #define ASN1_AFLG_ENCODING 2
  594. /* The Sequence length is invalid */
  595. #define ASN1_AFLG_BROKEN 4
  596. /* Use the new asn1_const_cb */
  597. #define ASN1_AFLG_CONST_CB 8
  598. /* operation values for asn1_cb */
  599. #define ASN1_OP_NEW_PRE 0
  600. #define ASN1_OP_NEW_POST 1
  601. #define ASN1_OP_FREE_PRE 2
  602. #define ASN1_OP_FREE_POST 3
  603. #define ASN1_OP_D2I_PRE 4
  604. #define ASN1_OP_D2I_POST 5
  605. #define ASN1_OP_I2D_PRE 6
  606. #define ASN1_OP_I2D_POST 7
  607. #define ASN1_OP_PRINT_PRE 8
  608. #define ASN1_OP_PRINT_POST 9
  609. #define ASN1_OP_STREAM_PRE 10
  610. #define ASN1_OP_STREAM_POST 11
  611. #define ASN1_OP_DETACHED_PRE 12
  612. #define ASN1_OP_DETACHED_POST 13
  613. #define ASN1_OP_DUP_PRE 14
  614. #define ASN1_OP_DUP_POST 15
  615. #define ASN1_OP_GET0_LIBCTX 16
  616. #define ASN1_OP_GET0_PROPQ 17
  617. /* Macro to implement a primitive type */
  618. #define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0)
  619. #define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \
  620. ASN1_ITEM_start(itname) \
  621. ASN1_ITYPE_PRIMITIVE, \
  622. V_##vname, NULL, 0, NULL, ex, #itname ASN1_ITEM_end(itname)
  623. /* Macro to implement a multi string type */
  624. #define IMPLEMENT_ASN1_MSTRING(itname, mask) \
  625. ASN1_ITEM_start(itname) \
  626. ASN1_ITYPE_MSTRING, \
  627. mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname ASN1_ITEM_end(itname)
  628. #define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \
  629. ASN1_ITEM_start(sname) \
  630. ASN1_ITYPE_EXTERN, \
  631. tag, \
  632. NULL, \
  633. 0, \
  634. &fptrs, \
  635. 0, \
  636. #sname ASN1_ITEM_end(sname)
  637. /* Macro to implement standard functions in terms of ASN1_ITEM structures */
  638. #define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname)
  639. #define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname)
  640. #define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \
  641. IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname)
  642. #define IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(stname) \
  643. IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(static, stname, stname, stname)
  644. #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \
  645. IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname)
  646. #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(pre, stname, itname, fname) \
  647. pre stname *fname##_new(void) \
  648. { \
  649. return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
  650. } \
  651. pre void fname##_free(stname *a) \
  652. { \
  653. ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
  654. }
  655. #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \
  656. stname *fname##_new(void) \
  657. { \
  658. return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
  659. } \
  660. void fname##_free(stname *a) \
  661. { \
  662. ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
  663. }
  664. #define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \
  665. IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
  666. IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
  667. #define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
  668. stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
  669. { \
  670. return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname)); \
  671. } \
  672. int i2d_##fname(const stname *a, unsigned char **out) \
  673. { \
  674. return ASN1_item_i2d((const ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname)); \
  675. }
  676. #define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \
  677. int i2d_##stname##_NDEF(const stname *a, unsigned char **out) \
  678. { \
  679. return ASN1_item_ndef_i2d((const ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname)); \
  680. }
  681. #define IMPLEMENT_STATIC_ASN1_ENCODE_FUNCTIONS(stname) \
  682. static stname *d2i_##stname(stname **a, \
  683. const unsigned char **in, long len) \
  684. { \
  685. return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, \
  686. ASN1_ITEM_rptr(stname)); \
  687. } \
  688. static int i2d_##stname(const stname *a, unsigned char **out) \
  689. { \
  690. return ASN1_item_i2d((const ASN1_VALUE *)a, out, \
  691. ASN1_ITEM_rptr(stname)); \
  692. }
  693. #define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \
  694. stname *stname##_dup(const stname *x) \
  695. { \
  696. return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \
  697. }
  698. #define IMPLEMENT_ASN1_PRINT_FUNCTION(stname) \
  699. IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, stname, stname)
  700. #define IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, itname, fname) \
  701. int fname##_print_ctx(BIO *out, const stname *x, int indent, \
  702. const ASN1_PCTX *pctx) \
  703. { \
  704. return ASN1_item_print(out, (const ASN1_VALUE *)x, indent, \
  705. ASN1_ITEM_rptr(itname), pctx); \
  706. }
  707. /* external definitions for primitive types */
  708. DECLARE_ASN1_ITEM(ASN1_BOOLEAN)
  709. DECLARE_ASN1_ITEM(ASN1_TBOOLEAN)
  710. DECLARE_ASN1_ITEM(ASN1_FBOOLEAN)
  711. DECLARE_ASN1_ITEM(ASN1_SEQUENCE)
  712. DECLARE_ASN1_ITEM(CBIGNUM)
  713. DECLARE_ASN1_ITEM(BIGNUM)
  714. DECLARE_ASN1_ITEM(INT32)
  715. DECLARE_ASN1_ITEM(ZINT32)
  716. DECLARE_ASN1_ITEM(UINT32)
  717. DECLARE_ASN1_ITEM(ZUINT32)
  718. DECLARE_ASN1_ITEM(INT64)
  719. DECLARE_ASN1_ITEM(ZINT64)
  720. DECLARE_ASN1_ITEM(UINT64)
  721. DECLARE_ASN1_ITEM(ZUINT64)
  722. #ifndef OPENSSL_NO_DEPRECATED_3_0
  723. /*
  724. * LONG and ZLONG are strongly discouraged for use as stored data, as the
  725. * underlying C type (long) differs in size depending on the architecture.
  726. * They are designed with 32-bit longs in mind.
  727. */
  728. DECLARE_ASN1_ITEM(LONG)
  729. DECLARE_ASN1_ITEM(ZLONG)
  730. #endif
  731. /* clang-format off */
  732. SKM_DEFINE_STACK_OF_INTERNAL(ASN1_VALUE, ASN1_VALUE, ASN1_VALUE)
  733. #define sk_ASN1_VALUE_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_VALUE_sk_type(sk))
  734. #define sk_ASN1_VALUE_value(sk, idx) ((ASN1_VALUE *)OPENSSL_sk_value(ossl_check_const_ASN1_VALUE_sk_type(sk), (idx)))
  735. #define sk_ASN1_VALUE_new(cmp) ((STACK_OF(ASN1_VALUE) *)OPENSSL_sk_new(ossl_check_ASN1_VALUE_compfunc_type(cmp)))
  736. #define sk_ASN1_VALUE_new_null() ((STACK_OF(ASN1_VALUE) *)OPENSSL_sk_new_null())
  737. #define sk_ASN1_VALUE_new_reserve(cmp, n) ((STACK_OF(ASN1_VALUE) *)OPENSSL_sk_new_reserve(ossl_check_ASN1_VALUE_compfunc_type(cmp), (n)))
  738. #define sk_ASN1_VALUE_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_ASN1_VALUE_sk_type(sk), (n))
  739. #define sk_ASN1_VALUE_free(sk) OPENSSL_sk_free(ossl_check_ASN1_VALUE_sk_type(sk))
  740. #define sk_ASN1_VALUE_zero(sk) OPENSSL_sk_zero(ossl_check_ASN1_VALUE_sk_type(sk))
  741. #define sk_ASN1_VALUE_delete(sk, i) ((ASN1_VALUE *)OPENSSL_sk_delete(ossl_check_ASN1_VALUE_sk_type(sk), (i)))
  742. #define sk_ASN1_VALUE_delete_ptr(sk, ptr) ((ASN1_VALUE *)OPENSSL_sk_delete_ptr(ossl_check_ASN1_VALUE_sk_type(sk), ossl_check_ASN1_VALUE_type(ptr)))
  743. #define sk_ASN1_VALUE_push(sk, ptr) OPENSSL_sk_push(ossl_check_ASN1_VALUE_sk_type(sk), ossl_check_ASN1_VALUE_type(ptr))
  744. #define sk_ASN1_VALUE_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_ASN1_VALUE_sk_type(sk), ossl_check_ASN1_VALUE_type(ptr))
  745. #define sk_ASN1_VALUE_pop(sk) ((ASN1_VALUE *)OPENSSL_sk_pop(ossl_check_ASN1_VALUE_sk_type(sk)))
  746. #define sk_ASN1_VALUE_shift(sk) ((ASN1_VALUE *)OPENSSL_sk_shift(ossl_check_ASN1_VALUE_sk_type(sk)))
  747. #define sk_ASN1_VALUE_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_ASN1_VALUE_sk_type(sk), ossl_check_ASN1_VALUE_freefunc_type(freefunc))
  748. #define sk_ASN1_VALUE_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_ASN1_VALUE_sk_type(sk), ossl_check_ASN1_VALUE_type(ptr), (idx))
  749. #define sk_ASN1_VALUE_set(sk, idx, ptr) ((ASN1_VALUE *)OPENSSL_sk_set(ossl_check_ASN1_VALUE_sk_type(sk), (idx), ossl_check_ASN1_VALUE_type(ptr)))
  750. #define sk_ASN1_VALUE_find(sk, ptr) OPENSSL_sk_find(ossl_check_ASN1_VALUE_sk_type(sk), ossl_check_ASN1_VALUE_type(ptr))
  751. #define sk_ASN1_VALUE_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_ASN1_VALUE_sk_type(sk), ossl_check_ASN1_VALUE_type(ptr))
  752. #define sk_ASN1_VALUE_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_ASN1_VALUE_sk_type(sk), ossl_check_ASN1_VALUE_type(ptr), pnum)
  753. #define sk_ASN1_VALUE_sort(sk) OPENSSL_sk_sort(ossl_check_ASN1_VALUE_sk_type(sk))
  754. #define sk_ASN1_VALUE_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_ASN1_VALUE_sk_type(sk))
  755. #define sk_ASN1_VALUE_dup(sk) ((STACK_OF(ASN1_VALUE) *)OPENSSL_sk_dup(ossl_check_const_ASN1_VALUE_sk_type(sk)))
  756. #define sk_ASN1_VALUE_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(ASN1_VALUE) *)OPENSSL_sk_deep_copy(ossl_check_const_ASN1_VALUE_sk_type(sk), ossl_check_ASN1_VALUE_copyfunc_type(copyfunc), ossl_check_ASN1_VALUE_freefunc_type(freefunc)))
  757. #define sk_ASN1_VALUE_set_cmp_func(sk, cmp) ((sk_ASN1_VALUE_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_ASN1_VALUE_sk_type(sk), ossl_check_ASN1_VALUE_compfunc_type(cmp)))
  758. /* clang-format on */
  759. /* Functions used internally by the ASN1 code */
  760. int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
  761. void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
  762. int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
  763. const ASN1_ITEM *it, int tag, int aclass, char opt,
  764. ASN1_TLC *ctx);
  765. int ASN1_item_ex_i2d(const ASN1_VALUE **pval, unsigned char **out,
  766. const ASN1_ITEM *it, int tag, int aclass);
  767. /* Legacy compatibility */
  768. #define IMPLEMENT_ASN1_FUNCTIONS_const(name) IMPLEMENT_ASN1_FUNCTIONS(name)
  769. #define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
  770. IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname)
  771. #ifdef __cplusplus
  772. }
  773. #endif
  774. #endif