File indexing completed on 2026-09-10 09:18:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef OPENSSL_ASN1T_H
0018 #define OPENSSL_ASN1T_H
0019 #pragma once
0020
0021 #include <openssl/macros.h>
0022 #ifndef OPENSSL_NO_DEPRECATED_3_0
0023 #define HEADER_ASN1T_H
0024 #endif
0025
0026 #include <stddef.h>
0027 #include <openssl/e_os2.h>
0028 #include <openssl/asn1.h>
0029
0030 #ifdef OPENSSL_BUILD_SHLIBCRYPTO
0031 #undef OPENSSL_EXTERN
0032 #define OPENSSL_EXTERN OPENSSL_EXPORT
0033 #endif
0034
0035
0036
0037 #ifdef __cplusplus
0038 extern "C" {
0039 #endif
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082 #define ASN1_ITYPE_PRIMITIVE 0x0
0083 #define ASN1_ITYPE_SEQUENCE 0x1
0084 #define ASN1_ITYPE_CHOICE 0x2
0085
0086 #define ASN1_ITYPE_EXTERN 0x4
0087 #define ASN1_ITYPE_MSTRING 0x5
0088 #define ASN1_ITYPE_NDEF_SEQUENCE 0x6
0089
0090
0091 #define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)((iptr)()))
0092
0093
0094
0095 #define ASN1_ITEM_start(itname) \
0096 const ASN1_ITEM *itname##_it(void) \
0097 { \
0098 static const ASN1_ITEM local_it = {
0099
0100 #define static_ASN1_ITEM_start(itname) \
0101 static ASN1_ITEM_start(itname)
0102
0103 #define ASN1_ITEM_end(itname) \
0104 } \
0105 ; \
0106 return &local_it; \
0107 }
0108
0109
0110
0111 #define ASN1_ITEM_TEMPLATE(tname) \
0112 static const ASN1_TEMPLATE tname##_item_tt
0113
0114 #define ASN1_ITEM_TEMPLATE_END(tname) \
0115 ; \
0116 ASN1_ITEM_start(tname) \
0117 ASN1_ITYPE_PRIMITIVE, \
0118 -1, \
0119 &tname##_item_tt, \
0120 0, \
0121 NULL, \
0122 0, \
0123 #tname ASN1_ITEM_end(tname)
0124 #define static_ASN1_ITEM_TEMPLATE_END(tname) \
0125 ; \
0126 static_ASN1_ITEM_start(tname) \
0127 ASN1_ITYPE_PRIMITIVE, \
0128 -1, \
0129 &tname##_item_tt, \
0130 0, \
0131 NULL, \
0132 0, \
0133 #tname ASN1_ITEM_end(tname)
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158 #define ASN1_SEQUENCE(tname) \
0159 static const ASN1_TEMPLATE tname##_seq_tt[]
0160
0161 #define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname)
0162
0163 #define static_ASN1_SEQUENCE_END(stname) static_ASN1_SEQUENCE_END_name(stname, stname)
0164
0165 #define ASN1_SEQUENCE_END_name(stname, tname) \
0166 ; \
0167 ASN1_ITEM_start(tname) \
0168 ASN1_ITYPE_SEQUENCE, \
0169 V_ASN1_SEQUENCE, \
0170 tname##_seq_tt, \
0171 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \
0172 NULL, \
0173 sizeof(stname), \
0174 #tname ASN1_ITEM_end(tname)
0175
0176 #define static_ASN1_SEQUENCE_END_name(stname, tname) \
0177 ; \
0178 static_ASN1_ITEM_start(tname) \
0179 ASN1_ITYPE_SEQUENCE, \
0180 V_ASN1_SEQUENCE, \
0181 tname##_seq_tt, \
0182 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \
0183 NULL, \
0184 sizeof(stname), \
0185 #stname ASN1_ITEM_end(tname)
0186
0187 #define ASN1_NDEF_SEQUENCE(tname) \
0188 ASN1_SEQUENCE(tname)
0189
0190 #define ASN1_NDEF_SEQUENCE_cb(tname, cb) \
0191 ASN1_SEQUENCE_cb(tname, cb)
0192
0193 #define ASN1_SEQUENCE_cb(tname, cb) \
0194 static const ASN1_AUX tname##_aux = { NULL, 0, 0, 0, cb, 0, NULL }; \
0195 ASN1_SEQUENCE(tname)
0196
0197 #define ASN1_SEQUENCE_const_cb(tname, const_cb) \
0198 static const ASN1_AUX tname##_aux = { NULL, ASN1_AFLG_CONST_CB, 0, 0, NULL, 0, const_cb }; \
0199 ASN1_SEQUENCE(tname)
0200
0201 #define ASN1_SEQUENCE_cb_const_cb(tname, cb, const_cb) \
0202 static const ASN1_AUX tname##_aux = { NULL, ASN1_AFLG_CONST_CB, 0, 0, cb, 0, const_cb }; \
0203 ASN1_SEQUENCE(tname)
0204
0205 #define ASN1_SEQUENCE_ref(tname, cb) \
0206 static const ASN1_AUX tname##_aux = { NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), offsetof(tname, lock), cb, 0, NULL }; \
0207 ASN1_SEQUENCE(tname)
0208
0209 #define ASN1_SEQUENCE_enc(tname, enc, cb) \
0210 static const ASN1_AUX tname##_aux = { NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc), NULL }; \
0211 ASN1_SEQUENCE(tname)
0212
0213 #define ASN1_NDEF_SEQUENCE_END(tname) \
0214 ; \
0215 ASN1_ITEM_start(tname) \
0216 ASN1_ITYPE_NDEF_SEQUENCE, \
0217 V_ASN1_SEQUENCE, \
0218 tname##_seq_tt, \
0219 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \
0220 NULL, \
0221 sizeof(tname), \
0222 #tname ASN1_ITEM_end(tname)
0223 #define static_ASN1_NDEF_SEQUENCE_END(tname) \
0224 ; \
0225 static_ASN1_ITEM_start(tname) \
0226 ASN1_ITYPE_NDEF_SEQUENCE, \
0227 V_ASN1_SEQUENCE, \
0228 tname##_seq_tt, \
0229 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \
0230 NULL, \
0231 sizeof(tname), \
0232 #tname ASN1_ITEM_end(tname)
0233
0234 #define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
0235
0236 #define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
0237 #define static_ASN1_SEQUENCE_END_cb(stname, tname) static_ASN1_SEQUENCE_END_ref(stname, tname)
0238
0239 #define ASN1_SEQUENCE_END_ref(stname, tname) \
0240 ; \
0241 ASN1_ITEM_start(tname) \
0242 ASN1_ITYPE_SEQUENCE, \
0243 V_ASN1_SEQUENCE, \
0244 tname##_seq_tt, \
0245 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \
0246 &tname##_aux, \
0247 sizeof(stname), \
0248 #tname ASN1_ITEM_end(tname)
0249 #define static_ASN1_SEQUENCE_END_ref(stname, tname) \
0250 ; \
0251 static_ASN1_ITEM_start(tname) \
0252 ASN1_ITYPE_SEQUENCE, \
0253 V_ASN1_SEQUENCE, \
0254 tname##_seq_tt, \
0255 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \
0256 &tname##_aux, \
0257 sizeof(stname), \
0258 #stname ASN1_ITEM_end(tname)
0259
0260 #define ASN1_NDEF_SEQUENCE_END_cb(stname, tname) \
0261 ; \
0262 ASN1_ITEM_start(tname) \
0263 ASN1_ITYPE_NDEF_SEQUENCE, \
0264 V_ASN1_SEQUENCE, \
0265 tname##_seq_tt, \
0266 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE), \
0267 &tname##_aux, \
0268 sizeof(stname), \
0269 #stname ASN1_ITEM_end(tname)
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294 #define ASN1_CHOICE(tname) \
0295 static const ASN1_TEMPLATE tname##_ch_tt[]
0296
0297 #define ASN1_CHOICE_cb(tname, cb) \
0298 static const ASN1_AUX tname##_aux = { NULL, 0, 0, 0, cb, 0, NULL }; \
0299 ASN1_CHOICE(tname)
0300
0301 #define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname)
0302
0303 #define static_ASN1_CHOICE_END(stname) static_ASN1_CHOICE_END_name(stname, stname)
0304
0305 #define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type)
0306
0307 #define static_ASN1_CHOICE_END_name(stname, tname) static_ASN1_CHOICE_END_selector(stname, tname, type)
0308
0309 #define ASN1_CHOICE_END_selector(stname, tname, selname) \
0310 ; \
0311 ASN1_ITEM_start(tname) \
0312 ASN1_ITYPE_CHOICE, \
0313 offsetof(stname, selname), \
0314 tname##_ch_tt, \
0315 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE), \
0316 NULL, \
0317 sizeof(stname), \
0318 #stname ASN1_ITEM_end(tname)
0319
0320 #define static_ASN1_CHOICE_END_selector(stname, tname, selname) \
0321 ; \
0322 static_ASN1_ITEM_start(tname) \
0323 ASN1_ITYPE_CHOICE, \
0324 offsetof(stname, selname), \
0325 tname##_ch_tt, \
0326 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE), \
0327 NULL, \
0328 sizeof(stname), \
0329 #stname ASN1_ITEM_end(tname)
0330
0331 #define ASN1_CHOICE_END_cb(stname, tname, selname) \
0332 ; \
0333 ASN1_ITEM_start(tname) \
0334 ASN1_ITYPE_CHOICE, \
0335 offsetof(stname, selname), \
0336 tname##_ch_tt, \
0337 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE), \
0338 &tname##_aux, \
0339 sizeof(stname), \
0340 #stname ASN1_ITEM_end(tname)
0341
0342
0343
0344 #define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \
0345 (flags), (tag), 0, \
0346 #name, ASN1_ITEM_ref(type) \
0347 }
0348
0349
0350
0351
0352
0353 #define ASN1_EX_TYPE(flags, tag, stname, field, type) { \
0354 (flags), (tag), offsetof(stname, field), \
0355 #field, ASN1_ITEM_ref(type) \
0356 }
0357
0358
0359
0360 #define ASN1_IMP_EX(stname, field, type, tag, ex) \
0361 ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | (ex), tag, stname, field, type)
0362
0363 #define ASN1_EXP_EX(stname, field, type, tag, ex) \
0364 ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | (ex), tag, stname, field, type)
0365
0366
0367
0368 #define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb }
0369 #define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb }
0370
0371
0372 #define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0, 0, stname, field, type)
0373
0374 #define ASN1_EMBED(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_EMBED, 0, stname, field, type)
0375
0376
0377 #define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type)
0378 #define ASN1_OPT_EMBED(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL | ASN1_TFLG_EMBED, 0, stname, field, type)
0379
0380
0381 #define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0)
0382 #define ASN1_IMP_EMBED(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_EMBED)
0383
0384
0385 #define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
0386 #define ASN1_IMP_OPT_EMBED(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL | ASN1_TFLG_EMBED)
0387
0388
0389
0390 #define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0)
0391 #define ASN1_EXP_EMBED(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_EMBED)
0392 #define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
0393 #define ASN1_EXP_OPT_EMBED(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL | ASN1_TFLG_EMBED)
0394
0395
0396 #define ASN1_SEQUENCE_OF(stname, field, type) \
0397 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type)
0398
0399
0400 #define ASN1_SEQUENCE_OF_OPT(stname, field, type) \
0401 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL, 0, stname, field, type)
0402
0403
0404
0405 #define ASN1_SET_OF(stname, field, type) \
0406 ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type)
0407
0408 #define ASN1_SET_OF_OPT(stname, field, type) \
0409 ASN1_EX_TYPE(ASN1_TFLG_SET_OF | ASN1_TFLG_OPTIONAL, 0, stname, field, type)
0410
0411
0412
0413 #define ASN1_IMP_SET_OF(stname, field, type, tag) \
0414 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
0415
0416 #define ASN1_EXP_SET_OF(stname, field, type, tag) \
0417 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
0418
0419 #define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \
0420 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF | ASN1_TFLG_OPTIONAL)
0421
0422 #define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \
0423 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF | ASN1_TFLG_OPTIONAL)
0424
0425 #define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \
0426 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
0427
0428 #define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \
0429 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL)
0430
0431 #define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \
0432 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
0433
0434 #define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \
0435 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL)
0436
0437
0438 #define ASN1_NDEF_EXP(stname, field, type, tag) \
0439 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_NDEF)
0440
0441
0442 #define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \
0443 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL | ASN1_TFLG_NDEF)
0444
0445
0446
0447 #define ASN1_ADB(name) \
0448 static const ASN1_ADB_TABLE name##_adbtbl[]
0449
0450 #define ASN1_ADB_END(name, flags, field, adb_cb, def, none) \
0451 ; \
0452 static const ASN1_ITEM *name##_adb(void) \
0453 { \
0454 static const ASN1_ADB internal_adb = { \
0455 flags, \
0456 offsetof(name, field), \
0457 adb_cb, \
0458 name##_adbtbl, \
0459 sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE), \
0460 def, \
0461 none \
0462 }; \
0463 return (const ASN1_ITEM *)&internal_adb; \
0464 } \
0465 void dummy_function(void)
0466
0467 #define ADB_ENTRY(val, template) { val, template }
0468
0469 #define ASN1_ADB_TEMPLATE(name) \
0470 static const ASN1_TEMPLATE name##_tt
0471
0472
0473
0474
0475
0476
0477
0478 struct ASN1_TEMPLATE_st {
0479 unsigned long flags;
0480 long tag;
0481 unsigned long offset;
0482 const char *field_name;
0483 ASN1_ITEM_EXP *item;
0484 };
0485
0486
0487
0488 #define ASN1_TEMPLATE_item(t) (t->item_ptr)
0489 #define ASN1_TEMPLATE_adb(t) (t->item_ptr)
0490
0491 typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE;
0492 typedef struct ASN1_ADB_st ASN1_ADB;
0493
0494 struct ASN1_ADB_st {
0495 unsigned long flags;
0496 unsigned long offset;
0497 int (*adb_cb)(long *psel);
0498 const ASN1_ADB_TABLE *tbl;
0499 long tblcount;
0500 const ASN1_TEMPLATE *default_tt;
0501 const ASN1_TEMPLATE *null_tt;
0502 };
0503
0504 struct ASN1_ADB_TABLE_st {
0505 long value;
0506 const ASN1_TEMPLATE tt;
0507 };
0508
0509
0510
0511
0512 #define ASN1_TFLG_OPTIONAL (0x1)
0513
0514
0515 #define ASN1_TFLG_SET_OF (0x1 << 1)
0516
0517
0518 #define ASN1_TFLG_SEQUENCE_OF (0x2 << 1)
0519
0520
0521
0522
0523
0524
0525 #define ASN1_TFLG_SET_ORDER (0x3 << 1)
0526
0527
0528 #define ASN1_TFLG_SK_MASK (0x3 << 1)
0529
0530
0531
0532
0533
0534
0535
0536 #define ASN1_TFLG_IMPTAG (0x1 << 3)
0537
0538
0539 #define ASN1_TFLG_EXPTAG (0x2 << 3)
0540
0541 #define ASN1_TFLG_TAG_MASK (0x3 << 3)
0542
0543
0544 #define ASN1_TFLG_IMPLICIT (ASN1_TFLG_IMPTAG | ASN1_TFLG_CONTEXT)
0545
0546
0547 #define ASN1_TFLG_EXPLICIT (ASN1_TFLG_EXPTAG | ASN1_TFLG_CONTEXT)
0548
0549
0550
0551
0552
0553
0554
0555
0556 #define ASN1_TFLG_UNIVERSAL (0x0 << 6)
0557
0558 #define ASN1_TFLG_APPLICATION (0x1 << 6)
0559
0560 #define ASN1_TFLG_CONTEXT (0x2 << 6)
0561
0562 #define ASN1_TFLG_PRIVATE (0x3 << 6)
0563
0564 #define ASN1_TFLG_TAG_CLASS (0x3 << 6)
0565
0566
0567
0568
0569
0570
0571
0572 #define ASN1_TFLG_ADB_MASK (0x3 << 8)
0573
0574 #define ASN1_TFLG_ADB_OID (0x1 << 8)
0575
0576 #define ASN1_TFLG_ADB_INT (0x1 << 9)
0577
0578
0579
0580
0581
0582
0583 #define ASN1_TFLG_NDEF (0x1 << 11)
0584
0585
0586 #define ASN1_TFLG_EMBED (0x1 << 12)
0587
0588
0589
0590 struct ASN1_ITEM_st {
0591 char itype;
0592
0593 long utype;
0594 const ASN1_TEMPLATE *templates;
0595
0596 long tcount;
0597 const void *funcs;
0598
0599 long size;
0600 const char *sname;
0601 };
0602
0603
0604
0605
0606
0607
0608 struct ASN1_TLC_st {
0609 char valid;
0610 int ret;
0611 long plen;
0612 int ptag;
0613 int pclass;
0614 int hdrlen;
0615 };
0616
0617
0618 typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
0619 const ASN1_ITEM *it, int tag, int aclass, char opt,
0620 ASN1_TLC *ctx);
0621
0622 typedef int ASN1_ex_d2i_ex(ASN1_VALUE **pval, const unsigned char **in, long len,
0623 const ASN1_ITEM *it, int tag, int aclass, char opt,
0624 ASN1_TLC *ctx, OSSL_LIB_CTX *libctx,
0625 const char *propq);
0626 typedef int ASN1_ex_i2d(const ASN1_VALUE **pval, unsigned char **out,
0627 const ASN1_ITEM *it, int tag, int aclass);
0628 typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
0629 typedef int ASN1_ex_new_ex_func(ASN1_VALUE **pval, const ASN1_ITEM *it,
0630 OSSL_LIB_CTX *libctx, const char *propq);
0631 typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
0632
0633 typedef int ASN1_ex_print_func(BIO *out, const ASN1_VALUE **pval,
0634 int indent, const char *fname,
0635 const ASN1_PCTX *pctx);
0636
0637 typedef int ASN1_primitive_i2c(const ASN1_VALUE **pval, unsigned char *cont,
0638 int *putype, const ASN1_ITEM *it);
0639 typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont,
0640 int len, int utype, char *free_cont,
0641 const ASN1_ITEM *it);
0642 typedef int ASN1_primitive_print(BIO *out, const ASN1_VALUE **pval,
0643 const ASN1_ITEM *it, int indent,
0644 const ASN1_PCTX *pctx);
0645
0646 typedef struct ASN1_EXTERN_FUNCS_st {
0647 void *app_data;
0648 ASN1_ex_new_func *asn1_ex_new;
0649 ASN1_ex_free_func *asn1_ex_free;
0650 ASN1_ex_free_func *asn1_ex_clear;
0651 ASN1_ex_d2i *asn1_ex_d2i;
0652 ASN1_ex_i2d *asn1_ex_i2d;
0653 ASN1_ex_print_func *asn1_ex_print;
0654 ASN1_ex_new_ex_func *asn1_ex_new_ex;
0655 ASN1_ex_d2i_ex *asn1_ex_d2i_ex;
0656 } ASN1_EXTERN_FUNCS;
0657
0658 typedef struct ASN1_PRIMITIVE_FUNCS_st {
0659 void *app_data;
0660 unsigned long flags;
0661 ASN1_ex_new_func *prim_new;
0662 ASN1_ex_free_func *prim_free;
0663 ASN1_ex_free_func *prim_clear;
0664 ASN1_primitive_c2i *prim_c2i;
0665 ASN1_primitive_i2c *prim_i2c;
0666 ASN1_primitive_print *prim_print;
0667 } ASN1_PRIMITIVE_FUNCS;
0668
0669
0670
0671
0672
0673
0674
0675
0676
0677
0678
0679
0680
0681
0682
0683
0684
0685
0686 typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it,
0687 void *exarg);
0688 typedef int ASN1_aux_const_cb(int operation, const ASN1_VALUE **in,
0689 const ASN1_ITEM *it, void *exarg);
0690
0691 typedef struct ASN1_AUX_st {
0692 void *app_data;
0693 int flags;
0694 int ref_offset;
0695 int ref_lock;
0696 ASN1_aux_cb *asn1_cb;
0697 int enc_offset;
0698 ASN1_aux_const_cb *asn1_const_cb;
0699 } ASN1_AUX;
0700
0701
0702 typedef struct ASN1_PRINT_ARG_st {
0703 BIO *out;
0704 int indent;
0705 const ASN1_PCTX *pctx;
0706 } ASN1_PRINT_ARG;
0707
0708
0709 typedef struct ASN1_STREAM_ARG_st {
0710
0711 BIO *out;
0712
0713 BIO *ndef_bio;
0714
0715 unsigned char **boundary;
0716 } ASN1_STREAM_ARG;
0717
0718
0719
0720
0721 #define ASN1_AFLG_REFCOUNT 1
0722
0723 #define ASN1_AFLG_ENCODING 2
0724
0725 #define ASN1_AFLG_BROKEN 4
0726
0727 #define ASN1_AFLG_CONST_CB 8
0728
0729
0730
0731 #define ASN1_OP_NEW_PRE 0
0732 #define ASN1_OP_NEW_POST 1
0733 #define ASN1_OP_FREE_PRE 2
0734 #define ASN1_OP_FREE_POST 3
0735 #define ASN1_OP_D2I_PRE 4
0736 #define ASN1_OP_D2I_POST 5
0737 #define ASN1_OP_I2D_PRE 6
0738 #define ASN1_OP_I2D_POST 7
0739 #define ASN1_OP_PRINT_PRE 8
0740 #define ASN1_OP_PRINT_POST 9
0741 #define ASN1_OP_STREAM_PRE 10
0742 #define ASN1_OP_STREAM_POST 11
0743 #define ASN1_OP_DETACHED_PRE 12
0744 #define ASN1_OP_DETACHED_POST 13
0745 #define ASN1_OP_DUP_PRE 14
0746 #define ASN1_OP_DUP_POST 15
0747 #define ASN1_OP_GET0_LIBCTX 16
0748 #define ASN1_OP_GET0_PROPQ 17
0749
0750
0751 #define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0)
0752 #define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \
0753 ASN1_ITEM_start(itname) \
0754 ASN1_ITYPE_PRIMITIVE, \
0755 V_##vname, NULL, 0, NULL, ex, #itname ASN1_ITEM_end(itname)
0756
0757
0758 #define IMPLEMENT_ASN1_MSTRING(itname, mask) \
0759 ASN1_ITEM_start(itname) \
0760 ASN1_ITYPE_MSTRING, \
0761 mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname ASN1_ITEM_end(itname)
0762
0763 #define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \
0764 ASN1_ITEM_start(sname) \
0765 ASN1_ITYPE_EXTERN, \
0766 tag, \
0767 NULL, \
0768 0, \
0769 &fptrs, \
0770 0, \
0771 #sname ASN1_ITEM_end(sname)
0772
0773
0774
0775 #define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname)
0776
0777 #define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname)
0778
0779 #define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \
0780 IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname)
0781
0782 #define IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(stname) \
0783 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(static, stname, stname, stname)
0784
0785 #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \
0786 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname)
0787
0788 #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(pre, stname, itname, fname) \
0789 pre stname *fname##_new(void) \
0790 { \
0791 return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
0792 } \
0793 pre void fname##_free(stname *a) \
0794 { \
0795 ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
0796 }
0797
0798 #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \
0799 stname *fname##_new(void) \
0800 { \
0801 return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
0802 } \
0803 void fname##_free(stname *a) \
0804 { \
0805 ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
0806 }
0807
0808 #define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \
0809 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
0810 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
0811
0812 #define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
0813 stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
0814 { \
0815 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname)); \
0816 } \
0817 int i2d_##fname(const stname *a, unsigned char **out) \
0818 { \
0819 return ASN1_item_i2d((const ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname)); \
0820 }
0821
0822 #define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \
0823 int i2d_##stname##_NDEF(const stname *a, unsigned char **out) \
0824 { \
0825 return ASN1_item_ndef_i2d((const ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname)); \
0826 }
0827
0828 #define IMPLEMENT_STATIC_ASN1_ENCODE_FUNCTIONS(stname) \
0829 static stname *d2i_##stname(stname **a, \
0830 const unsigned char **in, long len) \
0831 { \
0832 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, \
0833 ASN1_ITEM_rptr(stname)); \
0834 } \
0835 static int i2d_##stname(const stname *a, unsigned char **out) \
0836 { \
0837 return ASN1_item_i2d((const ASN1_VALUE *)a, out, \
0838 ASN1_ITEM_rptr(stname)); \
0839 }
0840
0841 #define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \
0842 stname *stname##_dup(const stname *x) \
0843 { \
0844 return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \
0845 }
0846
0847 #define IMPLEMENT_ASN1_PRINT_FUNCTION(stname) \
0848 IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, stname, stname)
0849
0850 #define IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, itname, fname) \
0851 int fname##_print_ctx(BIO *out, const stname *x, int indent, \
0852 const ASN1_PCTX *pctx) \
0853 { \
0854 return ASN1_item_print(out, (const ASN1_VALUE *)x, indent, \
0855 ASN1_ITEM_rptr(itname), pctx); \
0856 }
0857
0858
0859
0860 DECLARE_ASN1_ITEM(ASN1_BOOLEAN)
0861 DECLARE_ASN1_ITEM(ASN1_TBOOLEAN)
0862 DECLARE_ASN1_ITEM(ASN1_FBOOLEAN)
0863 DECLARE_ASN1_ITEM(ASN1_SEQUENCE)
0864 DECLARE_ASN1_ITEM(CBIGNUM)
0865 DECLARE_ASN1_ITEM(BIGNUM)
0866 DECLARE_ASN1_ITEM(INT32)
0867 DECLARE_ASN1_ITEM(ZINT32)
0868 DECLARE_ASN1_ITEM(UINT32)
0869 DECLARE_ASN1_ITEM(ZUINT32)
0870 DECLARE_ASN1_ITEM(INT64)
0871 DECLARE_ASN1_ITEM(ZINT64)
0872 DECLARE_ASN1_ITEM(UINT64)
0873 DECLARE_ASN1_ITEM(ZUINT64)
0874
0875 #ifndef OPENSSL_NO_DEPRECATED_3_0
0876
0877
0878
0879
0880
0881 DECLARE_ASN1_ITEM(LONG)
0882 DECLARE_ASN1_ITEM(ZLONG)
0883 #endif
0884
0885
0886 SKM_DEFINE_STACK_OF_INTERNAL(ASN1_VALUE, ASN1_VALUE, ASN1_VALUE)
0887 #define sk_ASN1_VALUE_num(sk) OPENSSL_sk_num(ossl_check_const_ASN1_VALUE_sk_type(sk))
0888 #define sk_ASN1_VALUE_value(sk, idx) ((ASN1_VALUE *)OPENSSL_sk_value(ossl_check_const_ASN1_VALUE_sk_type(sk), (idx)))
0889 #define sk_ASN1_VALUE_new(cmp) ((STACK_OF(ASN1_VALUE) *)OPENSSL_sk_new(ossl_check_ASN1_VALUE_compfunc_type(cmp)))
0890 #define sk_ASN1_VALUE_new_null() ((STACK_OF(ASN1_VALUE) *)OPENSSL_sk_new_null())
0891 #define sk_ASN1_VALUE_new_reserve(cmp, n) ((STACK_OF(ASN1_VALUE) *)OPENSSL_sk_new_reserve(ossl_check_ASN1_VALUE_compfunc_type(cmp), (n)))
0892 #define sk_ASN1_VALUE_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_ASN1_VALUE_sk_type(sk), (n))
0893 #define sk_ASN1_VALUE_free(sk) OPENSSL_sk_free(ossl_check_ASN1_VALUE_sk_type(sk))
0894 #define sk_ASN1_VALUE_zero(sk) OPENSSL_sk_zero(ossl_check_ASN1_VALUE_sk_type(sk))
0895 #define sk_ASN1_VALUE_delete(sk, i) ((ASN1_VALUE *)OPENSSL_sk_delete(ossl_check_ASN1_VALUE_sk_type(sk), (i)))
0896 #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)))
0897 #define sk_ASN1_VALUE_push(sk, ptr) OPENSSL_sk_push(ossl_check_ASN1_VALUE_sk_type(sk), ossl_check_ASN1_VALUE_type(ptr))
0898 #define sk_ASN1_VALUE_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_ASN1_VALUE_sk_type(sk), ossl_check_ASN1_VALUE_type(ptr))
0899 #define sk_ASN1_VALUE_pop(sk) ((ASN1_VALUE *)OPENSSL_sk_pop(ossl_check_ASN1_VALUE_sk_type(sk)))
0900 #define sk_ASN1_VALUE_shift(sk) ((ASN1_VALUE *)OPENSSL_sk_shift(ossl_check_ASN1_VALUE_sk_type(sk)))
0901 #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))
0902 #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))
0903 #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)))
0904 #define sk_ASN1_VALUE_find(sk, ptr) OPENSSL_sk_find(ossl_check_ASN1_VALUE_sk_type(sk), ossl_check_ASN1_VALUE_type(ptr))
0905 #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))
0906 #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)
0907 #define sk_ASN1_VALUE_sort(sk) OPENSSL_sk_sort(ossl_check_ASN1_VALUE_sk_type(sk))
0908 #define sk_ASN1_VALUE_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_ASN1_VALUE_sk_type(sk))
0909 #define sk_ASN1_VALUE_dup(sk) ((STACK_OF(ASN1_VALUE) *)OPENSSL_sk_dup(ossl_check_const_ASN1_VALUE_sk_type(sk)))
0910 #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)))
0911 #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)))
0912
0913
0914
0915
0916
0917 int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
0918 void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
0919
0920 int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
0921 const ASN1_ITEM *it, int tag, int aclass, char opt,
0922 ASN1_TLC *ctx);
0923
0924 int ASN1_item_ex_i2d(const ASN1_VALUE **pval, unsigned char **out,
0925 const ASN1_ITEM *it, int tag, int aclass);
0926
0927
0928 #define IMPLEMENT_ASN1_FUNCTIONS_const(name) IMPLEMENT_ASN1_FUNCTIONS(name)
0929 #define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
0930 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname)
0931
0932 #ifdef __cplusplus
0933 }
0934 #endif
0935 #endif