| OLD | NEW |
| 1 /* asn1t.h */ | 1 /* asn1t.h */ |
| 2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
| 3 * project 2000. | 3 * project 2000. |
| 4 */ | 4 */ |
| 5 /* ==================================================================== | 5 /* ==================================================================== |
| 6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | 6 * Copyright (c) 2000-2005 The OpenSSL Project. All rights reserved. |
| 7 * | 7 * |
| 8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
| 10 * are met: | 10 * are met: |
| 11 * | 11 * |
| 12 * 1. Redistributions of source code must retain the above copyright | 12 * 1. Redistributions of source code must retain the above copyright |
| 13 * notice, this list of conditions and the following disclaimer. | 13 * notice, this list of conditions and the following disclaimer. |
| 14 * | 14 * |
| 15 * 2. Redistributions in binary form must reproduce the above copyright | 15 * 2. Redistributions in binary form must reproduce the above copyright |
| 16 * notice, this list of conditions and the following disclaimer in | 16 * notice, this list of conditions and the following disclaimer in |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 ASN1_ITEM_start(tname) \ | 211 ASN1_ITEM_start(tname) \ |
| 212 ASN1_ITYPE_SEQUENCE,\ | 212 ASN1_ITYPE_SEQUENCE,\ |
| 213 V_ASN1_SEQUENCE,\ | 213 V_ASN1_SEQUENCE,\ |
| 214 tname##_seq_tt,\ | 214 tname##_seq_tt,\ |
| 215 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ | 215 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ |
| 216 &tname##_aux,\ | 216 &tname##_aux,\ |
| 217 sizeof(stname),\ | 217 sizeof(stname),\ |
| 218 #stname \ | 218 #stname \ |
| 219 ASN1_ITEM_end(tname) | 219 ASN1_ITEM_end(tname) |
| 220 | 220 |
| 221 #define ASN1_NDEF_SEQUENCE_END_cb(stname, tname) \ |
| 222 ;\ |
| 223 ASN1_ITEM_start(tname) \ |
| 224 ASN1_ITYPE_NDEF_SEQUENCE,\ |
| 225 V_ASN1_SEQUENCE,\ |
| 226 tname##_seq_tt,\ |
| 227 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ |
| 228 &tname##_aux,\ |
| 229 sizeof(stname),\ |
| 230 #stname \ |
| 231 ASN1_ITEM_end(tname) |
| 232 |
| 221 | 233 |
| 222 /* This pair helps declare a CHOICE type. We can do: | 234 /* This pair helps declare a CHOICE type. We can do: |
| 223 * | 235 * |
| 224 * ASN1_CHOICE(chname) = { | 236 * ASN1_CHOICE(chname) = { |
| 225 * ... CHOICE options ... | 237 * ... CHOICE options ... |
| 226 * ASN1_CHOICE_END(chname) | 238 * ASN1_CHOICE_END(chname) |
| 227 * | 239 * |
| 228 * This will produce an ASN1_ITEM called chname_it | 240 * This will produce an ASN1_ITEM called chname_it |
| 229 * for a structure called chname. The structure | 241 * for a structure called chname. The structure |
| 230 * definition must look like this: | 242 * definition must look like this: |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, const unsigned char ** in, lo
ng length); | 656 typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, const unsigned char ** in, lo
ng length); |
| 645 typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in); | 657 typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in); |
| 646 | 658 |
| 647 typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, c
onst ASN1_ITEM *it, | 659 typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, c
onst ASN1_ITEM *it, |
| 648 int tag, int aclass, char opt, ASN1_TLC
*ctx); | 660 int tag, int aclass, char opt, ASN1_TLC
*ctx); |
| 649 | 661 |
| 650 typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM
*it, int tag, int aclass); | 662 typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM
*it, int tag, int aclass); |
| 651 typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it); | 663 typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it); |
| 652 typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it); | 664 typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it); |
| 653 | 665 |
| 666 typedef int ASN1_ex_print_func(BIO *out, ASN1_VALUE **pval, |
| 667 int indent, const char *fname, |
| 668 const ASN1_PCTX *pctx); |
| 669 |
| 654 typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, int *puty
pe, const ASN1_ITEM *it); | 670 typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, int *puty
pe, const ASN1_ITEM *it); |
| 655 typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont, int
len, int utype, char *free_cont, const ASN1_ITEM *it); | 671 typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont, int
len, int utype, char *free_cont, const ASN1_ITEM *it); |
| 672 typedef int ASN1_primitive_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *i
t, int indent, const ASN1_PCTX *pctx); |
| 656 | 673 |
| 657 typedef struct ASN1_COMPAT_FUNCS_st { | 674 typedef struct ASN1_COMPAT_FUNCS_st { |
| 658 ASN1_new_func *asn1_new; | 675 ASN1_new_func *asn1_new; |
| 659 ASN1_free_func *asn1_free; | 676 ASN1_free_func *asn1_free; |
| 660 ASN1_d2i_func *asn1_d2i; | 677 ASN1_d2i_func *asn1_d2i; |
| 661 ASN1_i2d_func *asn1_i2d; | 678 ASN1_i2d_func *asn1_i2d; |
| 662 } ASN1_COMPAT_FUNCS; | 679 } ASN1_COMPAT_FUNCS; |
| 663 | 680 |
| 664 typedef struct ASN1_EXTERN_FUNCS_st { | 681 typedef struct ASN1_EXTERN_FUNCS_st { |
| 665 void *app_data; | 682 void *app_data; |
| 666 ASN1_ex_new_func *asn1_ex_new; | 683 ASN1_ex_new_func *asn1_ex_new; |
| 667 ASN1_ex_free_func *asn1_ex_free; | 684 ASN1_ex_free_func *asn1_ex_free; |
| 668 ASN1_ex_free_func *asn1_ex_clear; | 685 ASN1_ex_free_func *asn1_ex_clear; |
| 669 ASN1_ex_d2i *asn1_ex_d2i; | 686 ASN1_ex_d2i *asn1_ex_d2i; |
| 670 ASN1_ex_i2d *asn1_ex_i2d; | 687 ASN1_ex_i2d *asn1_ex_i2d; |
| 688 ASN1_ex_print_func *asn1_ex_print; |
| 671 } ASN1_EXTERN_FUNCS; | 689 } ASN1_EXTERN_FUNCS; |
| 672 | 690 |
| 673 typedef struct ASN1_PRIMITIVE_FUNCS_st { | 691 typedef struct ASN1_PRIMITIVE_FUNCS_st { |
| 674 void *app_data; | 692 void *app_data; |
| 675 unsigned long flags; | 693 unsigned long flags; |
| 676 ASN1_ex_new_func *prim_new; | 694 ASN1_ex_new_func *prim_new; |
| 677 ASN1_ex_free_func *prim_free; | 695 ASN1_ex_free_func *prim_free; |
| 678 ASN1_ex_free_func *prim_clear; | 696 ASN1_ex_free_func *prim_clear; |
| 679 ASN1_primitive_c2i *prim_c2i; | 697 ASN1_primitive_c2i *prim_c2i; |
| 680 ASN1_primitive_i2c *prim_i2c; | 698 ASN1_primitive_i2c *prim_i2c; |
| 699 ASN1_primitive_print *prim_print; |
| 681 } ASN1_PRIMITIVE_FUNCS; | 700 } ASN1_PRIMITIVE_FUNCS; |
| 682 | 701 |
| 683 /* This is the ASN1_AUX structure: it handles various | 702 /* This is the ASN1_AUX structure: it handles various |
| 684 * miscellaneous requirements. For example the use of | 703 * miscellaneous requirements. For example the use of |
| 685 * reference counts and an informational callback. | 704 * reference counts and an informational callback. |
| 686 * | 705 * |
| 687 * The "informational callback" is called at various | 706 * The "informational callback" is called at various |
| 688 * points during the ASN1 encoding and decoding. It can | 707 * points during the ASN1 encoding and decoding. It can |
| 689 * be used to provide minor customisation of the structures | 708 * be used to provide minor customisation of the structures |
| 690 * used. This is most useful where the supplied routines | 709 * used. This is most useful where the supplied routines |
| 691 * *almost* do the right thing but need some extra help | 710 * *almost* do the right thing but need some extra help |
| 692 * at a few points. If the callback returns zero then | 711 * at a few points. If the callback returns zero then |
| 693 * it is assumed a fatal error has occurred and the | 712 * it is assumed a fatal error has occurred and the |
| 694 * main operation should be abandoned. | 713 * main operation should be abandoned. |
| 695 * | 714 * |
| 696 * If major changes in the default behaviour are required | 715 * If major changes in the default behaviour are required |
| 697 * then an external type is more appropriate. | 716 * then an external type is more appropriate. |
| 698 */ | 717 */ |
| 699 | 718 |
| 700 typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it); | 719 typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it, |
| 720 » » » » void *exarg); |
| 701 | 721 |
| 702 typedef struct ASN1_AUX_st { | 722 typedef struct ASN1_AUX_st { |
| 703 void *app_data; | 723 void *app_data; |
| 704 int flags; | 724 int flags; |
| 705 int ref_offset; /* Offset of reference value */ | 725 int ref_offset; /* Offset of reference value */ |
| 706 int ref_lock; /* Lock type to use */ | 726 int ref_lock; /* Lock type to use */ |
| 707 ASN1_aux_cb *asn1_cb; | 727 ASN1_aux_cb *asn1_cb; |
| 708 int enc_offset; /* Offset of ASN1_ENCODING structure */ | 728 int enc_offset; /* Offset of ASN1_ENCODING structure */ |
| 709 } ASN1_AUX; | 729 } ASN1_AUX; |
| 710 | 730 |
| 731 /* For print related callbacks exarg points to this structure */ |
| 732 typedef struct ASN1_PRINT_ARG_st { |
| 733 BIO *out; |
| 734 int indent; |
| 735 const ASN1_PCTX *pctx; |
| 736 } ASN1_PRINT_ARG; |
| 737 |
| 738 /* For streaming related callbacks exarg points to this structure */ |
| 739 typedef struct ASN1_STREAM_ARG_st { |
| 740 /* BIO to stream through */ |
| 741 BIO *out; |
| 742 /* BIO with filters appended */ |
| 743 BIO *ndef_bio; |
| 744 /* Streaming I/O boundary */ |
| 745 unsigned char **boundary; |
| 746 } ASN1_STREAM_ARG; |
| 747 |
| 711 /* Flags in ASN1_AUX */ | 748 /* Flags in ASN1_AUX */ |
| 712 | 749 |
| 713 /* Use a reference count */ | 750 /* Use a reference count */ |
| 714 #define ASN1_AFLG_REFCOUNT 1 | 751 #define ASN1_AFLG_REFCOUNT 1 |
| 715 /* Save the encoding of structure (useful for signatures) */ | 752 /* Save the encoding of structure (useful for signatures) */ |
| 716 #define ASN1_AFLG_ENCODING 2 | 753 #define ASN1_AFLG_ENCODING 2 |
| 717 /* The Sequence length is invalid */ | 754 /* The Sequence length is invalid */ |
| 718 #define ASN1_AFLG_BROKEN 4 | 755 #define ASN1_AFLG_BROKEN 4 |
| 719 | 756 |
| 720 /* operation values for asn1_cb */ | 757 /* operation values for asn1_cb */ |
| 721 | 758 |
| 722 #define ASN1_OP_NEW_PRE 0 | 759 #define ASN1_OP_NEW_PRE 0 |
| 723 #define ASN1_OP_NEW_POST 1 | 760 #define ASN1_OP_NEW_POST 1 |
| 724 #define ASN1_OP_FREE_PRE 2 | 761 #define ASN1_OP_FREE_PRE 2 |
| 725 #define ASN1_OP_FREE_POST 3 | 762 #define ASN1_OP_FREE_POST 3 |
| 726 #define ASN1_OP_D2I_PRE 4 | 763 #define ASN1_OP_D2I_PRE 4 |
| 727 #define ASN1_OP_D2I_POST 5 | 764 #define ASN1_OP_D2I_POST 5 |
| 728 #define ASN1_OP_I2D_PRE 6 | 765 #define ASN1_OP_I2D_PRE 6 |
| 729 #define ASN1_OP_I2D_POST 7 | 766 #define ASN1_OP_I2D_POST 7 |
| 767 #define ASN1_OP_PRINT_PRE 8 |
| 768 #define ASN1_OP_PRINT_POST 9 |
| 769 #define ASN1_OP_STREAM_PRE 10 |
| 770 #define ASN1_OP_STREAM_POST 11 |
| 771 #define ASN1_OP_DETACHED_PRE 12 |
| 772 #define ASN1_OP_DETACHED_POST 13 |
| 730 | 773 |
| 731 /* Macro to implement a primitive type */ | 774 /* Macro to implement a primitive type */ |
| 732 #define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0) | 775 #define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0) |
| 733 #define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \ | 776 #define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \ |
| 734 ASN1_ITEM_start(itname) \ | 777 ASN1_ITEM_start(itname) \ |
| 735 ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0
, NULL, ex, #itname \ | 778 ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0
, NULL, ex, #itname \ |
| 736 ASN1_ITEM_end(itname) | 779 ASN1_ITEM_end(itname) |
| 737 | 780 |
| 738 /* Macro to implement a multi string type */ | 781 /* Macro to implement a multi string type */ |
| 739 #define IMPLEMENT_ASN1_MSTRING(itname, mask) \ | 782 #define IMPLEMENT_ASN1_MSTRING(itname, mask) \ |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 | 818 |
| 776 /* Macro to implement standard functions in terms of ASN1_ITEM structures */ | 819 /* Macro to implement standard functions in terms of ASN1_ITEM structures */ |
| 777 | 820 |
| 778 #define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname,
stname, stname) | 821 #define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname,
stname, stname) |
| 779 | 822 |
| 780 #define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_f
name(stname, itname, itname) | 823 #define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_f
name(stname, itname, itname) |
| 781 | 824 |
| 782 #define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \ | 825 #define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \ |
| 783 IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, it
name) | 826 IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, it
name) |
| 784 | 827 |
| 828 #define IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(stname) \ |
| 829 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(static, stname, stname, st
name) |
| 830 |
| 785 #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \ | 831 #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \ |
| 786 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname) | 832 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname) |
| 787 | 833 |
| 834 #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(pre, stname, itname, fname) \ |
| 835 pre stname *fname##_new(void) \ |
| 836 { \ |
| 837 return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \ |
| 838 } \ |
| 839 pre void fname##_free(stname *a) \ |
| 840 { \ |
| 841 ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \ |
| 842 } |
| 843 |
| 788 #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \ | 844 #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \ |
| 789 stname *fname##_new(void) \ | 845 stname *fname##_new(void) \ |
| 790 { \ | 846 { \ |
| 791 return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \ | 847 return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \ |
| 792 } \ | 848 } \ |
| 793 void fname##_free(stname *a) \ | 849 void fname##_free(stname *a) \ |
| 794 { \ | 850 { \ |
| 795 ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \ | 851 ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \ |
| 796 } | 852 } |
| 797 | 853 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 827 { \ | 883 { \ |
| 828 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname
));\ | 884 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname
));\ |
| 829 } | 885 } |
| 830 | 886 |
| 831 #define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \ | 887 #define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \ |
| 832 stname * stname##_dup(stname *x) \ | 888 stname * stname##_dup(stname *x) \ |
| 833 { \ | 889 { \ |
| 834 return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \ | 890 return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \ |
| 835 } | 891 } |
| 836 | 892 |
| 893 #define IMPLEMENT_ASN1_PRINT_FUNCTION(stname) \ |
| 894 IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, stname, stname) |
| 895 |
| 896 #define IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, itname, fname) \ |
| 897 int fname##_print_ctx(BIO *out, stname *x, int indent, \ |
| 898 const ASN1_PCTX *pctx) \ |
| 899 { \ |
| 900 return ASN1_item_print(out, (ASN1_VALUE *)x, indent, \ |
| 901 ASN1_ITEM_rptr(itname), pctx); \ |
| 902 } |
| 903 |
| 837 #define IMPLEMENT_ASN1_FUNCTIONS_const(name) \ | 904 #define IMPLEMENT_ASN1_FUNCTIONS_const(name) \ |
| 838 IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name) | 905 IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name) |
| 839 | 906 |
| 840 #define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \ | 907 #define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \ |
| 841 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ | 908 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ |
| 842 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) | 909 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) |
| 843 | 910 |
| 844 /* external definitions for primitive types */ | 911 /* external definitions for primitive types */ |
| 845 | 912 |
| 846 DECLARE_ASN1_ITEM(ASN1_BOOLEAN) | 913 DECLARE_ASN1_ITEM(ASN1_BOOLEAN) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 | 951 |
| 885 void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it); | 952 void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it); |
| 886 void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it); | 953 void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it); |
| 887 int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN
1_ITEM *it); | 954 int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN
1_ITEM *it); |
| 888 int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, const A
SN1_ITEM *it); | 955 int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, const A
SN1_ITEM *it); |
| 889 | 956 |
| 890 #ifdef __cplusplus | 957 #ifdef __cplusplus |
| 891 } | 958 } |
| 892 #endif | 959 #endif |
| 893 #endif | 960 #endif |
| OLD | NEW |