libisdn
|
00001 /* 00002 * ASN.1 codec, types 00003 * @internal 00004 */ 00005 #ifndef __ASN1_TYPES_H__ 00006 #define __ASN1_TYPES_H__ 00007 00008 #define ASN1_ELEMENT(x) ((struct asn1_object *)(x)) 00009 #define ASN1_COMPLEX_ELEMENT(x) ((struct asn1_complex *)(x)) 00010 00011 #define ASN1_SIBLINGS(x) ({ \ 00012 struct asn1_object *___c = (struct asn1_object *)(x); \ 00013 &___c->siblings; \ 00014 }) 00015 00016 #define ASN1_CHILDREN(x) ({ \ 00017 struct asn1_complex *___c = (struct asn1_complex *)(x); \ 00018 &___c->children; \ 00019 }) 00020 00021 struct asn1_list; 00022 struct asn1_list { 00023 struct asn1_list *next, *prev, *head; 00024 }; 00025 00026 struct asn1_header { 00027 char asn_class; 00028 char asn_type; 00029 char asn_complex; 00030 // char depth; 00031 int size; 00032 }; 00033 00034 struct asn1_object { 00035 struct asn1_header hdr; 00036 struct asn1_list siblings; 00037 }; 00038 00042 struct asn1_value { 00043 struct asn1_header hdr; 00044 struct asn1_list siblings; 00045 // int length; /*!< length of encoded value */ 00046 char value[]; 00047 }; 00048 00049 00053 struct asn1_null { 00054 struct asn1_header hdr; 00055 struct asn1_list siblings; /* siblings */ 00056 }; 00057 00061 struct asn1_boolean { 00062 struct asn1_header hdr; 00063 struct asn1_list siblings; /* siblings */ 00064 char value; 00065 }; 00066 00070 struct asn1_string { 00071 struct asn1_header hdr; 00072 struct asn1_list siblings; /* siblings */ 00073 int length; 00074 char value[]; 00075 }; 00076 00080 struct asn1_real { 00081 struct asn1_header hdr; 00082 struct asn1_list siblings; /* siblings */ 00083 float minval, maxval; 00084 float value; 00085 }; 00086 00090 struct asn1_integer { 00091 struct asn1_header hdr; 00092 struct asn1_list siblings; /* siblings */ 00093 int minval, maxval; 00094 int value; 00095 }; 00096 00097 #define ASN1_MAXOID 10 00098 00102 struct asn1_oid { 00103 struct asn1_header hdr; 00104 struct asn1_list siblings; /* siblings */ 00105 int value[ASN1_MAXOID]; 00106 int length; 00107 }; 00108 00112 struct asn1_enumerated { 00113 struct asn1_header hdr; 00114 struct asn1_list siblings; /* siblings */ 00115 int value; 00116 }; 00117 00118 00122 struct asn1_complex { 00123 struct asn1_header hdr; 00124 struct asn1_list siblings; /* siblings */ 00125 struct asn1_list children; /* children */ 00126 }; 00127 00128 00132 struct asn1_set { 00133 struct asn1_complex hdr; 00134 }; 00135 00139 struct asn1_sequence { 00140 struct asn1_complex hdr; 00141 }; 00142 00146 struct asn1_buffer { 00147 char *data; 00148 unsigned int size; 00149 unsigned int offset; 00150 #ifdef DEBUG 00151 int max_depth; 00152 #endif 00153 }; 00154 00155 typedef int (* decode_header_cb_t)(struct asn1_buffer *buf, struct asn1_header *hdr); 00156 typedef int (* encode_header_cb_t)(struct asn1_buffer *buf, const struct asn1_header *hdr); 00157 typedef int (* decode_value_cb_t)(struct asn1_buffer *buf, struct asn1_object *elem); 00158 typedef int (* encode_value_cb_t)(struct asn1_buffer *buf, struct asn1_object *elem); 00159 typedef int (* header_size_cb_t)(const struct asn1_header *hdr); 00160 00164 struct asn1_codec { 00165 const asn1_codec_t id; 00166 const char *name; 00167 decode_header_cb_t decode_header; 00168 encode_header_cb_t encode_header; 00169 decode_value_cb_t decode_value; 00170 encode_value_cb_t encode_value; 00171 header_size_cb_t header_size; 00172 }; 00173 00177 struct asn1_tree { 00178 const struct asn1_codec *codec; 00179 struct asn1_list root; 00180 }; 00181 00182 00183 #endif /* __ASN1_TYPES_H__ */