blob: 9104df85377d8b299c5d8f00a8330bc883c28a3b [file] [log] [blame]
vlm3df79662004-06-28 21:13:22 +00001
vlm6e1b13e2004-08-11 05:25:47 +00002/*** <<< INCLUDES [PrimitiveType] >>> ***/
vlm3df79662004-06-28 21:13:22 +00003
4#include <OCTET_STRING.h>
5
6/*** <<< TYPE-DECLS [PrimitiveType] >>> ***/
7
8
9typedef OCTET_STRING_t PrimitiveType_t;
10
vlm3df79662004-06-28 21:13:22 +000011/*** <<< FUNC-DECLS [PrimitiveType] >>> ***/
12
13extern asn1_TYPE_descriptor_t asn1_DEF_PrimitiveType;
14asn_constr_check_f PrimitiveType_constraint;
15ber_type_decoder_f PrimitiveType_decode_ber;
16der_type_encoder_f PrimitiveType_encode_der;
17asn_struct_print_f PrimitiveType_print;
18asn_struct_free_f PrimitiveType_free;
19
vlm21e46002004-08-20 13:36:32 +000020/*** <<< CODE [PrimitiveType] >>> ***/
21
22int
23PrimitiveType_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
24 asn_app_consume_bytes_f *app_errlog, void *app_key) {
25
26 /* Make the underlying type checker permanent */
27 td->check_constraints = asn1_DEF_OCTET_STRING.check_constraints;
28 return td->check_constraints
29 (td, sptr, app_errlog, app_key);
30}
31
32/*
33 * This type is implemented using OCTET_STRING,
34 * so adjust the DEF appropriately.
35 */
36static void
37PrimitiveType_inherit_TYPE_descriptor(asn1_TYPE_descriptor_t *td) {
38 td->ber_decoder = asn1_DEF_OCTET_STRING.ber_decoder;
39 td->der_encoder = asn1_DEF_OCTET_STRING.der_encoder;
40 td->free_struct = asn1_DEF_OCTET_STRING.free_struct;
41 td->print_struct = asn1_DEF_OCTET_STRING.print_struct;
42 td->last_tag_form = asn1_DEF_OCTET_STRING.last_tag_form;
43 td->elements = asn1_DEF_OCTET_STRING.elements;
44 td->elements_count = asn1_DEF_OCTET_STRING.elements_count;
45 td->specifics = asn1_DEF_OCTET_STRING.specifics;
46}
47
48ber_dec_rval_t
49PrimitiveType_decode_ber(asn1_TYPE_descriptor_t *td,
50 void **structure, void *bufptr, size_t size, int tag_mode) {
51 PrimitiveType_inherit_TYPE_descriptor(td);
vlm1308d2b2004-09-10 15:49:15 +000052 return td->ber_decoder(td, structure, bufptr, size, tag_mode);
vlm21e46002004-08-20 13:36:32 +000053}
54
55der_enc_rval_t
56PrimitiveType_encode_der(asn1_TYPE_descriptor_t *td,
57 void *structure, int tag_mode, ber_tlv_tag_t tag,
58 asn_app_consume_bytes_f *cb, void *app_key) {
59 PrimitiveType_inherit_TYPE_descriptor(td);
60 return td->der_encoder(td, structure, tag_mode, tag, cb, app_key);
61}
62
63int
64PrimitiveType_print(asn1_TYPE_descriptor_t *td, const void *struct_ptr,
65 int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
66 PrimitiveType_inherit_TYPE_descriptor(td);
67 return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
68}
69
70void
71PrimitiveType_free(asn1_TYPE_descriptor_t *td,
72 void *struct_ptr, int contents_only) {
73 PrimitiveType_inherit_TYPE_descriptor(td);
74 td->free_struct(td, struct_ptr, contents_only);
75}
76
77
vlm3df79662004-06-28 21:13:22 +000078/*** <<< STAT-DEFS [PrimitiveType] >>> ***/
79
80static ber_tlv_tag_t asn1_DEF_PrimitiveType_tags[] = {
81 (ASN_TAG_CLASS_UNIVERSAL | (4 << 2))
82};
83asn1_TYPE_descriptor_t asn1_DEF_PrimitiveType = {
84 "PrimitiveType",
85 PrimitiveType_constraint,
86 PrimitiveType_decode_ber,
87 PrimitiveType_encode_der,
88 PrimitiveType_print,
89 PrimitiveType_free,
90 0, /* Use generic outmost tag fetcher */
91 asn1_DEF_PrimitiveType_tags,
92 sizeof(asn1_DEF_PrimitiveType_tags)
vlm6e73a042004-08-11 07:17:22 +000093 /sizeof(asn1_DEF_PrimitiveType_tags[0]), /* 1 */
vlm72425de2004-09-13 08:31:01 +000094 asn1_DEF_PrimitiveType_tags, /* Same as above */
95 sizeof(asn1_DEF_PrimitiveType_tags)
96 /sizeof(asn1_DEF_PrimitiveType_tags[0]), /* 1 */
vlm3df79662004-06-28 21:13:22 +000097 -0, /* Unknown yet */
vlm21e46002004-08-20 13:36:32 +000098 0, 0, /* No members */
vlm3df79662004-06-28 21:13:22 +000099 0 /* No specifics */
100};
101
vlm3df79662004-06-28 21:13:22 +0000102
vlm6e1b13e2004-08-11 05:25:47 +0000103/*** <<< INCLUDES [ConstructedType] >>> ***/
vlm3df79662004-06-28 21:13:22 +0000104
vlm3df79662004-06-28 21:13:22 +0000105#include <PrimitiveType.h>
vlm3df79662004-06-28 21:13:22 +0000106#include <constr_SEQUENCE.h>
107
vlm6e1b13e2004-08-11 05:25:47 +0000108/*** <<< DEPS [ConstructedType] >>> ***/
109
vlm3df79662004-06-28 21:13:22 +0000110extern asn1_TYPE_descriptor_t asn1_DEF_ConstructedType;
111
112/*** <<< TYPE-DECLS [ConstructedType] >>> ***/
113
114
115typedef struct ConstructedType {
116 PrimitiveType_t field;
117
118 /* Context for parsing across buffer boundaries */
119 ber_dec_ctx_t _ber_dec_ctx;
120} ConstructedType_t;
121
122/*** <<< STAT-DEFS [ConstructedType] >>> ***/
123
vlm21e46002004-08-20 13:36:32 +0000124static asn1_TYPE_member_t asn1_MBR_ConstructedType[] = {
vlmddd5a7d2004-09-10 09:18:20 +0000125 { ATF_NOFLAGS, 0, offsetof(struct ConstructedType, field),
vlm21e46002004-08-20 13:36:32 +0000126 .tag = (ASN_TAG_CLASS_CONTEXT | (5 << 2)),
127 .tag_mode = -1, /* IMPLICIT tag at current level */
128 .type = (void *)&asn1_DEF_PrimitiveType,
129 .memb_constraints = 0, /* Defer to actual type */
130 .name = "field"
vlm3df79662004-06-28 21:13:22 +0000131 },
132};
133static ber_tlv_tag_t asn1_DEF_ConstructedType_tags[] = {
134 (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
135};
136static asn1_TYPE_tag2member_t asn1_DEF_ConstructedType_tag2el[] = {
137 { (ASN_TAG_CLASS_CONTEXT | (5 << 2)), 0, 0, 0 }, /* field at 18 */
138};
139static asn1_SEQUENCE_specifics_t asn1_DEF_ConstructedType_specs = {
140 sizeof(struct ConstructedType),
141 offsetof(struct ConstructedType, _ber_dec_ctx),
vlm3df79662004-06-28 21:13:22 +0000142 asn1_DEF_ConstructedType_tag2el,
143 1, /* Count of tags in the map */
144 -1, /* Start extensions */
145 -1 /* Stop extensions */
146};
147asn1_TYPE_descriptor_t asn1_DEF_ConstructedType = {
148 "ConstructedType",
149 SEQUENCE_constraint,
150 SEQUENCE_decode_ber,
151 SEQUENCE_encode_der,
152 SEQUENCE_print,
153 SEQUENCE_free,
154 0, /* Use generic outmost tag fetcher */
155 asn1_DEF_ConstructedType_tags,
156 sizeof(asn1_DEF_ConstructedType_tags)
vlm6e73a042004-08-11 07:17:22 +0000157 /sizeof(asn1_DEF_ConstructedType_tags[0]), /* 1 */
vlm72425de2004-09-13 08:31:01 +0000158 asn1_DEF_ConstructedType_tags, /* Same as above */
159 sizeof(asn1_DEF_ConstructedType_tags)
160 /sizeof(asn1_DEF_ConstructedType_tags[0]), /* 1 */
vlm3df79662004-06-28 21:13:22 +0000161 1, /* Whether CONSTRUCTED */
vlm21e46002004-08-20 13:36:32 +0000162 asn1_MBR_ConstructedType,
163 1, /* Elements count */
vlm3df79662004-06-28 21:13:22 +0000164 &asn1_DEF_ConstructedType_specs /* Additional specs */
165};
166
167
vlm6e1b13e2004-08-11 05:25:47 +0000168/*** <<< INCLUDES [T] >>> ***/
vlm3df79662004-06-28 21:13:22 +0000169
170#include <ConstructedType.h>
171
172/*** <<< TYPE-DECLS [T] >>> ***/
173
174
175typedef ConstructedType_t T_t;
176
vlm3df79662004-06-28 21:13:22 +0000177/*** <<< FUNC-DECLS [T] >>> ***/
178
179extern asn1_TYPE_descriptor_t asn1_DEF_T;
180asn_constr_check_f T_constraint;
181ber_type_decoder_f T_decode_ber;
182der_type_encoder_f T_encode_der;
183asn_struct_print_f T_print;
184asn_struct_free_f T_free;
185
vlm21e46002004-08-20 13:36:32 +0000186/*** <<< CODE [T] >>> ***/
187
188int
189T_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
190 asn_app_consume_bytes_f *app_errlog, void *app_key) {
191
192 /* Make the underlying type checker permanent */
193 td->check_constraints = asn1_DEF_ConstructedType.check_constraints;
194 return td->check_constraints
195 (td, sptr, app_errlog, app_key);
196}
197
198/*
199 * This type is implemented using ConstructedType,
200 * so adjust the DEF appropriately.
201 */
202static void
203T_inherit_TYPE_descriptor(asn1_TYPE_descriptor_t *td) {
204 td->ber_decoder = asn1_DEF_ConstructedType.ber_decoder;
205 td->der_encoder = asn1_DEF_ConstructedType.der_encoder;
206 td->free_struct = asn1_DEF_ConstructedType.free_struct;
207 td->print_struct = asn1_DEF_ConstructedType.print_struct;
208 td->last_tag_form = asn1_DEF_ConstructedType.last_tag_form;
209 td->elements = asn1_DEF_ConstructedType.elements;
210 td->elements_count = asn1_DEF_ConstructedType.elements_count;
211 td->specifics = asn1_DEF_ConstructedType.specifics;
212}
213
214ber_dec_rval_t
215T_decode_ber(asn1_TYPE_descriptor_t *td,
216 void **structure, void *bufptr, size_t size, int tag_mode) {
217 T_inherit_TYPE_descriptor(td);
vlm1308d2b2004-09-10 15:49:15 +0000218 return td->ber_decoder(td, structure, bufptr, size, tag_mode);
vlm21e46002004-08-20 13:36:32 +0000219}
220
221der_enc_rval_t
222T_encode_der(asn1_TYPE_descriptor_t *td,
223 void *structure, int tag_mode, ber_tlv_tag_t tag,
224 asn_app_consume_bytes_f *cb, void *app_key) {
225 T_inherit_TYPE_descriptor(td);
226 return td->der_encoder(td, structure, tag_mode, tag, cb, app_key);
227}
228
229int
230T_print(asn1_TYPE_descriptor_t *td, const void *struct_ptr,
231 int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
232 T_inherit_TYPE_descriptor(td);
233 return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
234}
235
236void
237T_free(asn1_TYPE_descriptor_t *td,
238 void *struct_ptr, int contents_only) {
239 T_inherit_TYPE_descriptor(td);
240 td->free_struct(td, struct_ptr, contents_only);
241}
242
243
vlm3df79662004-06-28 21:13:22 +0000244/*** <<< STAT-DEFS [T] >>> ***/
245
246static ber_tlv_tag_t asn1_DEF_T_tags[] = {
vlm72425de2004-09-13 08:31:01 +0000247 (ASN_TAG_CLASS_CONTEXT | (3 << 2)),
248 (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
vlm3df79662004-06-28 21:13:22 +0000249};
250asn1_TYPE_descriptor_t asn1_DEF_T = {
251 "T",
252 T_constraint,
253 T_decode_ber,
254 T_encode_der,
255 T_print,
256 T_free,
257 0, /* Use generic outmost tag fetcher */
258 asn1_DEF_T_tags,
259 sizeof(asn1_DEF_T_tags)
vlm72425de2004-09-13 08:31:01 +0000260 /sizeof(asn1_DEF_T_tags[0]) - 1, /* 1 */
261 asn1_DEF_T_tags, /* Same as above */
262 sizeof(asn1_DEF_T_tags)
263 /sizeof(asn1_DEF_T_tags[0]), /* 2 */
vlm3df79662004-06-28 21:13:22 +0000264 -0, /* Unknown yet */
vlm21e46002004-08-20 13:36:32 +0000265 0, 0, /* Defined elsewhere */
vlm3df79662004-06-28 21:13:22 +0000266 0 /* No specifics */
267};
268