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