annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/openssl/asn1t.h @ 69:33d812a61356

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