00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 #ifndef HEADER_ASN1T_H
00059 #define HEADER_ASN1T_H
00060
00061 #include <stddef.h>
00062 #include <openssl/e_os2.h>
00063 #include <openssl/asn1.h>
00064
00065 #ifdef OPENSSL_BUILD_SHLIBCRYPTO
00066 # undef OPENSSL_EXTERN
00067 # define OPENSSL_EXTERN OPENSSL_EXPORT
00068 #endif
00069
00070
00071
00072 #ifdef __cplusplus
00073 extern "C" {
00074 #endif
00075
00076
00077 #ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
00078
00079
00080 #define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr))
00081
00082
00083
00084
00085 #define ASN1_ITEM_start(itname) \
00086 OPENSSL_GLOBAL const ASN1_ITEM itname##_it = {
00087
00088 #define ASN1_ITEM_end(itname) \
00089 };
00090
00091 #else
00092
00093
00094 #define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr()))
00095
00096
00097
00098
00099 #define ASN1_ITEM_start(itname) \
00100 const ASN1_ITEM * itname##_it(void) \
00101 { \
00102 static const ASN1_ITEM local_it = {
00103
00104 #define ASN1_ITEM_end(itname) \
00105 }; \
00106 return &local_it; \
00107 }
00108
00109 #endif
00110
00111
00112
00113
00114 #define ASN1_ITEM_TEMPLATE(tname) \
00115 static const ASN1_TEMPLATE tname##_item_tt
00116
00117 #define ASN1_ITEM_TEMPLATE_END(tname) \
00118 ;\
00119 ASN1_ITEM_start(tname) \
00120 ASN1_ITYPE_PRIMITIVE,\
00121 -1,\
00122 &tname##_item_tt,\
00123 0,\
00124 NULL,\
00125 0,\
00126 #tname \
00127 ASN1_ITEM_end(tname)
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 #define ASN1_SEQUENCE(tname) \
00153 static const ASN1_TEMPLATE tname##_seq_tt[]
00154
00155 #define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname)
00156
00157 #define ASN1_SEQUENCE_END_name(stname, tname) \
00158 ;\
00159 ASN1_ITEM_start(tname) \
00160 ASN1_ITYPE_SEQUENCE,\
00161 V_ASN1_SEQUENCE,\
00162 tname##_seq_tt,\
00163 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
00164 NULL,\
00165 sizeof(stname),\
00166 #stname \
00167 ASN1_ITEM_end(tname)
00168
00169 #define ASN1_NDEF_SEQUENCE(tname) \
00170 ASN1_SEQUENCE(tname)
00171
00172 #define ASN1_SEQUENCE_cb(tname, cb) \
00173 static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
00174 ASN1_SEQUENCE(tname)
00175
00176 #define ASN1_BROKEN_SEQUENCE(tname) \
00177 static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \
00178 ASN1_SEQUENCE(tname)
00179
00180 #define ASN1_SEQUENCE_ref(tname, cb, lck) \
00181 static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \
00182 ASN1_SEQUENCE(tname)
00183
00184 #define ASN1_SEQUENCE_enc(tname, enc, cb) \
00185 static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \
00186 ASN1_SEQUENCE(tname)
00187
00188 #define ASN1_NDEF_SEQUENCE_END(tname) \
00189 ;\
00190 ASN1_ITEM_start(tname) \
00191 ASN1_ITYPE_NDEF_SEQUENCE,\
00192 V_ASN1_SEQUENCE,\
00193 tname##_seq_tt,\
00194 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
00195 NULL,\
00196 sizeof(tname),\
00197 #tname \
00198 ASN1_ITEM_end(tname)
00199
00200 #define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname)
00201
00202 #define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
00203
00204 #define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
00205
00206 #define ASN1_SEQUENCE_END_ref(stname, tname) \
00207 ;\
00208 ASN1_ITEM_start(tname) \
00209 ASN1_ITYPE_SEQUENCE,\
00210 V_ASN1_SEQUENCE,\
00211 tname##_seq_tt,\
00212 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
00213 &tname##_aux,\
00214 sizeof(stname),\
00215 #stname \
00216 ASN1_ITEM_end(tname)
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 #define ASN1_CHOICE(tname) \
00242 static const ASN1_TEMPLATE tname##_ch_tt[]
00243
00244 #define ASN1_CHOICE_cb(tname, cb) \
00245 static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
00246 ASN1_CHOICE(tname)
00247
00248 #define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname)
00249
00250 #define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type)
00251
00252 #define ASN1_CHOICE_END_selector(stname, tname, selname) \
00253 ;\
00254 ASN1_ITEM_start(tname) \
00255 ASN1_ITYPE_CHOICE,\
00256 offsetof(stname,selname) ,\
00257 tname##_ch_tt,\
00258 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
00259 NULL,\
00260 sizeof(stname),\
00261 #stname \
00262 ASN1_ITEM_end(tname)
00263
00264 #define ASN1_CHOICE_END_cb(stname, tname, selname) \
00265 ;\
00266 ASN1_ITEM_start(tname) \
00267 ASN1_ITYPE_CHOICE,\
00268 offsetof(stname,selname) ,\
00269 tname##_ch_tt,\
00270 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
00271 &tname##_aux,\
00272 sizeof(stname),\
00273 #stname \
00274 ASN1_ITEM_end(tname)
00275
00276
00277
00278 #define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \
00279 (flags), (tag), 0,\
00280 #name, ASN1_ITEM_ref(type) }
00281
00282
00283
00284
00285
00286 #define ASN1_EX_TYPE(flags, tag, stname, field, type) { \
00287 (flags), (tag), offsetof(stname, field),\
00288 #field, ASN1_ITEM_ref(type) }
00289
00290
00291
00292 #define ASN1_EX_COMBINE(flags, tag, type) { \
00293 (flags)|ASN1_TFLG_COMBINE, (tag), 0, NULL, ASN1_ITEM_ref(type) }
00294
00295
00296
00297 #define ASN1_IMP_EX(stname, field, type, tag, ex) \
00298 ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type)
00299
00300 #define ASN1_EXP_EX(stname, field, type, tag, ex) \
00301 ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type)
00302
00303
00304
00305 #ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
00306 #define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
00307 #define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
00308 #else
00309 #define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb }
00310 #define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb }
00311 #endif
00312
00313 #define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type)
00314
00315
00316 #define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type)
00317
00318
00319 #define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0)
00320
00321
00322 #define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
00323
00324
00325
00326 #define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0)
00327 #define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
00328
00329
00330 #define ASN1_SEQUENCE_OF(stname, field, type) \
00331 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type)
00332
00333
00334 #define ASN1_SEQUENCE_OF_OPT(stname, field, type) \
00335 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
00336
00337
00338
00339 #define ASN1_SET_OF(stname, field, type) \
00340 ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type)
00341
00342 #define ASN1_SET_OF_OPT(stname, field, type) \
00343 ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
00344
00345
00346
00347 #define ASN1_IMP_SET_OF(stname, field, type, tag) \
00348 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
00349
00350 #define ASN1_EXP_SET_OF(stname, field, type, tag) \
00351 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
00352
00353 #define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \
00354 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
00355
00356 #define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \
00357 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
00358
00359 #define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \
00360 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
00361
00362 #define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \
00363 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
00364
00365 #define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \
00366 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
00367
00368 #define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \
00369 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
00370
00371
00372 #define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \
00373 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF)
00374
00375
00376
00377 #define ASN1_ADB(name) \
00378 static const ASN1_ADB_TABLE name##_adbtbl[]
00379
00380 #ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
00381
00382 #define ASN1_ADB_END(name, flags, field, app_table, def, none) \
00383 ;\
00384 static const ASN1_ADB name##_adb = {\
00385 flags,\
00386 offsetof(name, field),\
00387 app_table,\
00388 name##_adbtbl,\
00389 sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
00390 def,\
00391 none\
00392 }
00393
00394 #else
00395
00396 #define ASN1_ADB_END(name, flags, field, app_table, def, none) \
00397 ;\
00398 static const ASN1_ITEM *name##_adb(void) \
00399 { \
00400 static const ASN1_ADB internal_adb = \
00401 {\
00402 flags,\
00403 offsetof(name, field),\
00404 app_table,\
00405 name##_adbtbl,\
00406 sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
00407 def,\
00408 none\
00409 }; \
00410 return (const ASN1_ITEM *) &internal_adb; \
00411 } \
00412 void dummy_function(void)
00413
00414 #endif
00415
00416 #define ADB_ENTRY(val, template) {val, template}
00417
00418 #define ASN1_ADB_TEMPLATE(name) \
00419 static const ASN1_TEMPLATE name##_tt
00420
00421
00422
00423
00424
00425
00426
00427 struct ASN1_TEMPLATE_st {
00428 unsigned long flags;
00429 long tag;
00430 unsigned long offset;
00431 #ifndef NO_ASN1_FIELD_NAMES
00432 const char *field_name;
00433 #endif
00434 ASN1_ITEM_EXP *item;
00435 };
00436
00437
00438
00439 #define ASN1_TEMPLATE_item(t) (t->item_ptr)
00440 #define ASN1_TEMPLATE_adb(t) (t->item_ptr)
00441
00442 typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE;
00443 typedef struct ASN1_ADB_st ASN1_ADB;
00444
00445 struct ASN1_ADB_st {
00446 unsigned long flags;
00447 unsigned long offset;
00448 STACK_OF(ASN1_ADB_TABLE) **app_items;
00449 const ASN1_ADB_TABLE *tbl;
00450 long tblcount;
00451 const ASN1_TEMPLATE *default_tt;
00452 const ASN1_TEMPLATE *null_tt;
00453 };
00454
00455 struct ASN1_ADB_TABLE_st {
00456 long value;
00457 const ASN1_TEMPLATE tt;
00458 };
00459
00460
00461
00462
00463 #define ASN1_TFLG_OPTIONAL (0x1)
00464
00465
00466 #define ASN1_TFLG_SET_OF (0x1 << 1)
00467
00468
00469 #define ASN1_TFLG_SEQUENCE_OF (0x2 << 1)
00470
00471
00472
00473
00474
00475
00476 #define ASN1_TFLG_SET_ORDER (0x3 << 1)
00477
00478
00479 #define ASN1_TFLG_SK_MASK (0x3 << 1)
00480
00481
00482
00483
00484
00485
00486
00487 #define ASN1_TFLG_IMPTAG (0x1 << 3)
00488
00489
00490
00491 #define ASN1_TFLG_EXPTAG (0x2 << 3)
00492
00493 #define ASN1_TFLG_TAG_MASK (0x3 << 3)
00494
00495
00496 #define ASN1_TFLG_IMPLICIT ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT
00497
00498
00499 #define ASN1_TFLG_EXPLICIT ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT
00500
00501
00502
00503
00504
00505
00506
00507
00508 #define ASN1_TFLG_UNIVERSAL (0x0<<6)
00509
00510 #define ASN1_TFLG_APPLICATION (0x1<<6)
00511
00512 #define ASN1_TFLG_CONTEXT (0x2<<6)
00513
00514 #define ASN1_TFLG_PRIVATE (0x3<<6)
00515
00516 #define ASN1_TFLG_TAG_CLASS (0x3<<6)
00517
00518
00519
00520
00521
00522
00523
00524 #define ASN1_TFLG_ADB_MASK (0x3<<8)
00525
00526 #define ASN1_TFLG_ADB_OID (0x1<<8)
00527
00528 #define ASN1_TFLG_ADB_INT (0x1<<9)
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538 #define ASN1_TFLG_COMBINE (0x1<<10)
00539
00540
00541
00542
00543
00544
00545 #define ASN1_TFLG_NDEF (0x1<<11)
00546
00547
00548
00549 struct ASN1_ITEM_st {
00550 char itype;
00551 long utype;
00552 const ASN1_TEMPLATE *templates;
00553 long tcount;
00554 const void *funcs;
00555 long size;
00556 #ifndef NO_ASN1_FIELD_NAMES
00557 const char *sname;
00558 #endif
00559 };
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605 #define ASN1_ITYPE_PRIMITIVE 0x0
00606
00607 #define ASN1_ITYPE_SEQUENCE 0x1
00608
00609 #define ASN1_ITYPE_CHOICE 0x2
00610
00611 #define ASN1_ITYPE_COMPAT 0x3
00612
00613 #define ASN1_ITYPE_EXTERN 0x4
00614
00615 #define ASN1_ITYPE_MSTRING 0x5
00616
00617 #define ASN1_ITYPE_NDEF_SEQUENCE 0x6
00618
00619
00620
00621
00622
00623
00624 struct ASN1_TLC_st{
00625 char valid;
00626 int ret;
00627 long plen;
00628 int ptag;
00629 int pclass;
00630 int hdrlen;
00631 };
00632
00633
00634
00635 typedef ASN1_VALUE * ASN1_new_func(void);
00636 typedef void ASN1_free_func(ASN1_VALUE *a);
00637 typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, const unsigned char ** in, long length);
00638 typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in);
00639
00640 typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it,
00641 int tag, int aclass, char opt, ASN1_TLC *ctx);
00642
00643 typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
00644 typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
00645 typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
00646
00647 typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
00648 typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
00649
00650 typedef struct ASN1_COMPAT_FUNCS_st {
00651 ASN1_new_func *asn1_new;
00652 ASN1_free_func *asn1_free;
00653 ASN1_d2i_func *asn1_d2i;
00654 ASN1_i2d_func *asn1_i2d;
00655 } ASN1_COMPAT_FUNCS;
00656
00657 typedef struct ASN1_EXTERN_FUNCS_st {
00658 void *app_data;
00659 ASN1_ex_new_func *asn1_ex_new;
00660 ASN1_ex_free_func *asn1_ex_free;
00661 ASN1_ex_free_func *asn1_ex_clear;
00662 ASN1_ex_d2i *asn1_ex_d2i;
00663 ASN1_ex_i2d *asn1_ex_i2d;
00664 } ASN1_EXTERN_FUNCS;
00665
00666 typedef struct ASN1_PRIMITIVE_FUNCS_st {
00667 void *app_data;
00668 unsigned long flags;
00669 ASN1_ex_new_func *prim_new;
00670 ASN1_ex_free_func *prim_free;
00671 ASN1_ex_free_func *prim_clear;
00672 ASN1_primitive_c2i *prim_c2i;
00673 ASN1_primitive_i2c *prim_i2c;
00674 } ASN1_PRIMITIVE_FUNCS;
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693 typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it);
00694
00695 typedef struct ASN1_AUX_st {
00696 void *app_data;
00697 int flags;
00698 int ref_offset;
00699 int ref_lock;
00700 ASN1_aux_cb *asn1_cb;
00701 int enc_offset;
00702 } ASN1_AUX;
00703
00704
00705
00706
00707 #define ASN1_AFLG_REFCOUNT 1
00708
00709 #define ASN1_AFLG_ENCODING 2
00710
00711 #define ASN1_AFLG_BROKEN 4
00712
00713
00714
00715 #define ASN1_OP_NEW_PRE 0
00716 #define ASN1_OP_NEW_POST 1
00717 #define ASN1_OP_FREE_PRE 2
00718 #define ASN1_OP_FREE_POST 3
00719 #define ASN1_OP_D2I_PRE 4
00720 #define ASN1_OP_D2I_POST 5
00721 #define ASN1_OP_I2D_PRE 6
00722 #define ASN1_OP_I2D_POST 7
00723
00724
00725 #define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0)
00726 #define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \
00727 ASN1_ITEM_start(itname) \
00728 ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \
00729 ASN1_ITEM_end(itname)
00730
00731
00732 #define IMPLEMENT_ASN1_MSTRING(itname, mask) \
00733 ASN1_ITEM_start(itname) \
00734 ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \
00735 ASN1_ITEM_end(itname)
00736
00737
00738
00739 #define IMPLEMENT_COMPAT_ASN1(sname) IMPLEMENT_COMPAT_ASN1_type(sname, V_ASN1_SEQUENCE)
00740
00741 #define IMPLEMENT_COMPAT_ASN1_type(sname, tag) \
00742 static const ASN1_COMPAT_FUNCS sname##_ff = { \
00743 (ASN1_new_func *)sname##_new, \
00744 (ASN1_free_func *)sname##_free, \
00745 (ASN1_d2i_func *)d2i_##sname, \
00746 (ASN1_i2d_func *)i2d_##sname, \
00747 }; \
00748 ASN1_ITEM_start(sname) \
00749 ASN1_ITYPE_COMPAT, \
00750 tag, \
00751 NULL, \
00752 0, \
00753 &sname##_ff, \
00754 0, \
00755 #sname \
00756 ASN1_ITEM_end(sname)
00757
00758 #define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \
00759 ASN1_ITEM_start(sname) \
00760 ASN1_ITYPE_EXTERN, \
00761 tag, \
00762 NULL, \
00763 0, \
00764 &fptrs, \
00765 0, \
00766 #sname \
00767 ASN1_ITEM_end(sname)
00768
00769
00770
00771 #define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname)
00772
00773 #define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname)
00774
00775 #define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \
00776 IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname)
00777
00778 #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \
00779 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname)
00780
00781 #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \
00782 stname *fname##_new(void) \
00783 { \
00784 return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
00785 } \
00786 void fname##_free(stname *a) \
00787 { \
00788 ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
00789 }
00790
00791 #define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \
00792 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
00793 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
00794
00795 #define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
00796 stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
00797 { \
00798 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
00799 } \
00800 int i2d_##fname(stname *a, unsigned char **out) \
00801 { \
00802 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
00803 }
00804
00805 #define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \
00806 int i2d_##stname##_NDEF(stname *a, unsigned char **out) \
00807 { \
00808 return ASN1_item_ndef_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname));\
00809 }
00810
00811
00812
00813
00814 #define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
00815 stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
00816 { \
00817 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
00818 } \
00819 int i2d_##fname(const stname *a, unsigned char **out) \
00820 { \
00821 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
00822 }
00823
00824 #define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \
00825 stname * stname##_dup(stname *x) \
00826 { \
00827 return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \
00828 }
00829
00830 #define IMPLEMENT_ASN1_FUNCTIONS_const(name) \
00831 IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name)
00832
00833 #define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \
00834 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
00835 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
00836
00837
00838
00839 DECLARE_ASN1_ITEM(ASN1_BOOLEAN)
00840 DECLARE_ASN1_ITEM(ASN1_TBOOLEAN)
00841 DECLARE_ASN1_ITEM(ASN1_FBOOLEAN)
00842 DECLARE_ASN1_ITEM(ASN1_SEQUENCE)
00843 DECLARE_ASN1_ITEM(CBIGNUM)
00844 DECLARE_ASN1_ITEM(BIGNUM)
00845 DECLARE_ASN1_ITEM(LONG)
00846 DECLARE_ASN1_ITEM(ZLONG)
00847
00848 DECLARE_STACK_OF(ASN1_VALUE)
00849
00850
00851
00852 int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
00853 void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
00854 int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
00855 int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
00856
00857 void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
00858 int ASN1_template_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_TEMPLATE *tt);
00859 int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it,
00860 int tag, int aclass, char opt, ASN1_TLC *ctx);
00861
00862 int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
00863 int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt);
00864 void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
00865
00866 int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
00867 int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
00868
00869 int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it);
00870 int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it);
00871
00872 ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
00873
00874 const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr);
00875
00876 int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it);
00877
00878 void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it);
00879 void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
00880 int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it);
00881 int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, const ASN1_ITEM *it);
00882
00883 #ifdef __cplusplus
00884 }
00885 #endif
00886 #endif