blob: ad54f87481c9edcf11dbd520f97ec681165341bb [file] [log] [blame]
Lev Walkin5bbff1e2004-06-28 21:13:22 +00001
Lev Walkinb47ddce2004-08-11 05:25:47 +00002/*** <<< INCLUDES [PrimitiveType] >>> ***/
Lev Walkin5bbff1e2004-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
Lev Walkin5bbff1e2004-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
Lev Walkin2e3055d2004-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);
52 return td->ber_decoder(td, structure,
53 bufptr, size, tag_mode);
54}
55
56der_enc_rval_t
57PrimitiveType_encode_der(asn1_TYPE_descriptor_t *td,
58 void *structure, int tag_mode, ber_tlv_tag_t tag,
59 asn_app_consume_bytes_f *cb, void *app_key) {
60 PrimitiveType_inherit_TYPE_descriptor(td);
61 return td->der_encoder(td, structure, tag_mode, tag, cb, app_key);
62}
63
64int
65PrimitiveType_print(asn1_TYPE_descriptor_t *td, const void *struct_ptr,
66 int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
67 PrimitiveType_inherit_TYPE_descriptor(td);
68 return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
69}
70
71void
72PrimitiveType_free(asn1_TYPE_descriptor_t *td,
73 void *struct_ptr, int contents_only) {
74 PrimitiveType_inherit_TYPE_descriptor(td);
75 td->free_struct(td, struct_ptr, contents_only);
76}
77
78
Lev Walkin5bbff1e2004-06-28 21:13:22 +000079/*** <<< STAT-DEFS [PrimitiveType] >>> ***/
80
81static ber_tlv_tag_t asn1_DEF_PrimitiveType_tags[] = {
82 (ASN_TAG_CLASS_UNIVERSAL | (4 << 2))
83};
84asn1_TYPE_descriptor_t asn1_DEF_PrimitiveType = {
85 "PrimitiveType",
86 PrimitiveType_constraint,
87 PrimitiveType_decode_ber,
88 PrimitiveType_encode_der,
89 PrimitiveType_print,
90 PrimitiveType_free,
91 0, /* Use generic outmost tag fetcher */
92 asn1_DEF_PrimitiveType_tags,
93 sizeof(asn1_DEF_PrimitiveType_tags)
Lev Walkin64399722004-08-11 07:17:22 +000094 /sizeof(asn1_DEF_PrimitiveType_tags[0]), /* 1 */
Lev Walkin5bbff1e2004-06-28 21:13:22 +000095 1, /* Tags to skip */
96 -0, /* Unknown yet */
Lev Walkin2e3055d2004-08-20 13:36:32 +000097 0, 0, /* No members */
Lev Walkin5bbff1e2004-06-28 21:13:22 +000098 0 /* No specifics */
99};
100
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000101
Lev Walkinb47ddce2004-08-11 05:25:47 +0000102/*** <<< INCLUDES [ConstructedType] >>> ***/
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000103
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000104#include <PrimitiveType.h>
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000105#include <constr_SEQUENCE.h>
106
Lev Walkinb47ddce2004-08-11 05:25:47 +0000107/*** <<< DEPS [ConstructedType] >>> ***/
108
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000109extern asn1_TYPE_descriptor_t asn1_DEF_ConstructedType;
110
111/*** <<< TYPE-DECLS [ConstructedType] >>> ***/
112
113
114typedef struct ConstructedType {
115 PrimitiveType_t field;
116
117 /* Context for parsing across buffer boundaries */
118 ber_dec_ctx_t _ber_dec_ctx;
119} ConstructedType_t;
120
121/*** <<< STAT-DEFS [ConstructedType] >>> ***/
122
Lev Walkin2e3055d2004-08-20 13:36:32 +0000123static asn1_TYPE_member_t asn1_MBR_ConstructedType[] = {
124 { 0, offsetof(struct ConstructedType, field),
125 .tag = (ASN_TAG_CLASS_CONTEXT | (5 << 2)),
126 .tag_mode = -1, /* IMPLICIT tag at current level */
127 .type = (void *)&asn1_DEF_PrimitiveType,
128 .memb_constraints = 0, /* Defer to actual type */
129 .name = "field"
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000130 },
131};
132static ber_tlv_tag_t asn1_DEF_ConstructedType_tags[] = {
133 (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
134};
135static asn1_TYPE_tag2member_t asn1_DEF_ConstructedType_tag2el[] = {
136 { (ASN_TAG_CLASS_CONTEXT | (5 << 2)), 0, 0, 0 }, /* field at 18 */
137};
138static asn1_SEQUENCE_specifics_t asn1_DEF_ConstructedType_specs = {
139 sizeof(struct ConstructedType),
140 offsetof(struct ConstructedType, _ber_dec_ctx),
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000141 asn1_DEF_ConstructedType_tag2el,
142 1, /* Count of tags in the map */
143 -1, /* Start extensions */
144 -1 /* Stop extensions */
145};
146asn1_TYPE_descriptor_t asn1_DEF_ConstructedType = {
147 "ConstructedType",
148 SEQUENCE_constraint,
149 SEQUENCE_decode_ber,
150 SEQUENCE_encode_der,
151 SEQUENCE_print,
152 SEQUENCE_free,
153 0, /* Use generic outmost tag fetcher */
154 asn1_DEF_ConstructedType_tags,
155 sizeof(asn1_DEF_ConstructedType_tags)
Lev Walkin64399722004-08-11 07:17:22 +0000156 /sizeof(asn1_DEF_ConstructedType_tags[0]), /* 1 */
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000157 1, /* Tags to skip */
158 1, /* Whether CONSTRUCTED */
Lev Walkin2e3055d2004-08-20 13:36:32 +0000159 asn1_MBR_ConstructedType,
160 1, /* Elements count */
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000161 &asn1_DEF_ConstructedType_specs /* Additional specs */
162};
163
164
Lev Walkinb47ddce2004-08-11 05:25:47 +0000165/*** <<< INCLUDES [T] >>> ***/
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000166
167#include <ConstructedType.h>
168
169/*** <<< TYPE-DECLS [T] >>> ***/
170
171
172typedef ConstructedType_t T_t;
173
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000174/*** <<< FUNC-DECLS [T] >>> ***/
175
176extern asn1_TYPE_descriptor_t asn1_DEF_T;
177asn_constr_check_f T_constraint;
178ber_type_decoder_f T_decode_ber;
179der_type_encoder_f T_encode_der;
180asn_struct_print_f T_print;
181asn_struct_free_f T_free;
182
Lev Walkin2e3055d2004-08-20 13:36:32 +0000183/*** <<< CODE [T] >>> ***/
184
185int
186T_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
187 asn_app_consume_bytes_f *app_errlog, void *app_key) {
188
189 /* Make the underlying type checker permanent */
190 td->check_constraints = asn1_DEF_ConstructedType.check_constraints;
191 return td->check_constraints
192 (td, sptr, app_errlog, app_key);
193}
194
195/*
196 * This type is implemented using ConstructedType,
197 * so adjust the DEF appropriately.
198 */
199static void
200T_inherit_TYPE_descriptor(asn1_TYPE_descriptor_t *td) {
201 td->ber_decoder = asn1_DEF_ConstructedType.ber_decoder;
202 td->der_encoder = asn1_DEF_ConstructedType.der_encoder;
203 td->free_struct = asn1_DEF_ConstructedType.free_struct;
204 td->print_struct = asn1_DEF_ConstructedType.print_struct;
205 td->last_tag_form = asn1_DEF_ConstructedType.last_tag_form;
206 td->elements = asn1_DEF_ConstructedType.elements;
207 td->elements_count = asn1_DEF_ConstructedType.elements_count;
208 td->specifics = asn1_DEF_ConstructedType.specifics;
209}
210
211ber_dec_rval_t
212T_decode_ber(asn1_TYPE_descriptor_t *td,
213 void **structure, void *bufptr, size_t size, int tag_mode) {
214 T_inherit_TYPE_descriptor(td);
215 return td->ber_decoder(td, structure,
216 bufptr, size, tag_mode);
217}
218
219der_enc_rval_t
220T_encode_der(asn1_TYPE_descriptor_t *td,
221 void *structure, int tag_mode, ber_tlv_tag_t tag,
222 asn_app_consume_bytes_f *cb, void *app_key) {
223 T_inherit_TYPE_descriptor(td);
224 return td->der_encoder(td, structure, tag_mode, tag, cb, app_key);
225}
226
227int
228T_print(asn1_TYPE_descriptor_t *td, const void *struct_ptr,
229 int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
230 T_inherit_TYPE_descriptor(td);
231 return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
232}
233
234void
235T_free(asn1_TYPE_descriptor_t *td,
236 void *struct_ptr, int contents_only) {
237 T_inherit_TYPE_descriptor(td);
238 td->free_struct(td, struct_ptr, contents_only);
239}
240
241
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000242/*** <<< STAT-DEFS [T] >>> ***/
243
244static ber_tlv_tag_t asn1_DEF_T_tags[] = {
245 (ASN_TAG_CLASS_CONTEXT | (3 << 2))
246};
247asn1_TYPE_descriptor_t asn1_DEF_T = {
248 "T",
249 T_constraint,
250 T_decode_ber,
251 T_encode_der,
252 T_print,
253 T_free,
254 0, /* Use generic outmost tag fetcher */
255 asn1_DEF_T_tags,
256 sizeof(asn1_DEF_T_tags)
Lev Walkin64399722004-08-11 07:17:22 +0000257 /sizeof(asn1_DEF_T_tags[0]), /* 1 */
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000258 1, /* Tags to skip */
259 -0, /* Unknown yet */
Lev Walkin2e3055d2004-08-20 13:36:32 +0000260 0, 0, /* Defined elsewhere */
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000261 0 /* No specifics */
262};
263