blob: 639ded028f045e5a86e40b80abe485d77d2f84a9 [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
11
12/*** <<< FUNC-DECLS [PrimitiveType] >>> ***/
13
14extern asn1_TYPE_descriptor_t asn1_DEF_PrimitiveType;
15asn_constr_check_f PrimitiveType_constraint;
16ber_type_decoder_f PrimitiveType_decode_ber;
17der_type_encoder_f PrimitiveType_encode_der;
18asn_struct_print_f PrimitiveType_print;
19asn_struct_free_f PrimitiveType_free;
20
21/*** <<< STAT-DEFS [PrimitiveType] >>> ***/
22
23static ber_tlv_tag_t asn1_DEF_PrimitiveType_tags[] = {
24 (ASN_TAG_CLASS_UNIVERSAL | (4 << 2))
25};
26asn1_TYPE_descriptor_t asn1_DEF_PrimitiveType = {
27 "PrimitiveType",
28 PrimitiveType_constraint,
29 PrimitiveType_decode_ber,
30 PrimitiveType_encode_der,
31 PrimitiveType_print,
32 PrimitiveType_free,
33 0, /* Use generic outmost tag fetcher */
34 asn1_DEF_PrimitiveType_tags,
35 sizeof(asn1_DEF_PrimitiveType_tags)
Lev Walkin64399722004-08-11 07:17:22 +000036 /sizeof(asn1_DEF_PrimitiveType_tags[0]), /* 1 */
Lev Walkin5bbff1e2004-06-28 21:13:22 +000037 1, /* Tags to skip */
38 -0, /* Unknown yet */
39 0 /* No specifics */
40};
41
42int
43PrimitiveType_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
44 asn_app_consume_bytes_f *app_errlog, void *app_key) {
45
46 /* Make the underlying type checker permanent */
47 td->check_constraints = asn1_DEF_OCTET_STRING.check_constraints;
48 return td->check_constraints
49 (td, sptr, app_errlog, app_key);
50}
51
52/*
53 * This type is implemented using OCTET_STRING,
54 * so adjust the DEF appropriately.
55 */
56static void
57inherit_TYPE_descriptor(asn1_TYPE_descriptor_t *td) {
58 td->ber_decoder = asn1_DEF_OCTET_STRING.ber_decoder;
59 td->der_encoder = asn1_DEF_OCTET_STRING.der_encoder;
60 td->free_struct = asn1_DEF_OCTET_STRING.free_struct;
61 td->print_struct = asn1_DEF_OCTET_STRING.print_struct;
62 td->last_tag_form = asn1_DEF_OCTET_STRING.last_tag_form;
63 td->specifics = asn1_DEF_OCTET_STRING.specifics;
64}
65
66ber_dec_rval_t
67PrimitiveType_decode_ber(asn1_TYPE_descriptor_t *td,
68 void **structure, void *bufptr, size_t size, int tag_mode) {
69 inherit_TYPE_descriptor(td);
70 return td->ber_decoder(td, structure,
71 bufptr, size, tag_mode);
72}
73
74der_enc_rval_t
75PrimitiveType_encode_der(asn1_TYPE_descriptor_t *td,
76 void *structure, int tag_mode, ber_tlv_tag_t tag,
77 asn_app_consume_bytes_f *cb, void *app_key) {
78 inherit_TYPE_descriptor(td);
79 return td->der_encoder(td, structure, tag_mode, tag, cb, app_key);
80}
81
82int
83PrimitiveType_print(asn1_TYPE_descriptor_t *td, const void *struct_ptr,
84 int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
85 inherit_TYPE_descriptor(td);
86 return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
87}
88
89void
90PrimitiveType_free(asn1_TYPE_descriptor_t *td,
91 void *struct_ptr, int contents_only) {
92 inherit_TYPE_descriptor(td);
93 td->free_struct(td, struct_ptr, contents_only);
94}
95
96
Lev Walkinb47ddce2004-08-11 05:25:47 +000097/*** <<< INCLUDES [ConstructedType] >>> ***/
Lev Walkin5bbff1e2004-06-28 21:13:22 +000098
Lev Walkin5bbff1e2004-06-28 21:13:22 +000099#include <PrimitiveType.h>
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000100#include <constr_SEQUENCE.h>
101
Lev Walkinb47ddce2004-08-11 05:25:47 +0000102/*** <<< DEPS [ConstructedType] >>> ***/
103
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000104extern asn1_TYPE_descriptor_t asn1_DEF_ConstructedType;
105
106/*** <<< TYPE-DECLS [ConstructedType] >>> ***/
107
108
109typedef struct ConstructedType {
110 PrimitiveType_t field;
111
112 /* Context for parsing across buffer boundaries */
113 ber_dec_ctx_t _ber_dec_ctx;
114} ConstructedType_t;
115
116/*** <<< STAT-DEFS [ConstructedType] >>> ***/
117
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000118static asn1_SEQUENCE_element_t asn1_DEF_ConstructedType_elements[] = {
119 { offsetof(struct ConstructedType, field), 0,
120 (ASN_TAG_CLASS_CONTEXT | (5 << 2)),
121 -1, /* IMPLICIT tag at current level */
122 (void *)&asn1_DEF_PrimitiveType,
123 "field"
124 },
125};
126static ber_tlv_tag_t asn1_DEF_ConstructedType_tags[] = {
127 (ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
128};
129static asn1_TYPE_tag2member_t asn1_DEF_ConstructedType_tag2el[] = {
130 { (ASN_TAG_CLASS_CONTEXT | (5 << 2)), 0, 0, 0 }, /* field at 18 */
131};
132static asn1_SEQUENCE_specifics_t asn1_DEF_ConstructedType_specs = {
133 sizeof(struct ConstructedType),
134 offsetof(struct ConstructedType, _ber_dec_ctx),
135 asn1_DEF_ConstructedType_elements,
136 1, /* Elements count */
137 asn1_DEF_ConstructedType_tag2el,
138 1, /* Count of tags in the map */
139 -1, /* Start extensions */
140 -1 /* Stop extensions */
141};
142asn1_TYPE_descriptor_t asn1_DEF_ConstructedType = {
143 "ConstructedType",
144 SEQUENCE_constraint,
145 SEQUENCE_decode_ber,
146 SEQUENCE_encode_der,
147 SEQUENCE_print,
148 SEQUENCE_free,
149 0, /* Use generic outmost tag fetcher */
150 asn1_DEF_ConstructedType_tags,
151 sizeof(asn1_DEF_ConstructedType_tags)
Lev Walkin64399722004-08-11 07:17:22 +0000152 /sizeof(asn1_DEF_ConstructedType_tags[0]), /* 1 */
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000153 1, /* Tags to skip */
154 1, /* Whether CONSTRUCTED */
155 &asn1_DEF_ConstructedType_specs /* Additional specs */
156};
157
158
Lev Walkinb47ddce2004-08-11 05:25:47 +0000159/*** <<< INCLUDES [T] >>> ***/
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000160
161#include <ConstructedType.h>
162
163/*** <<< TYPE-DECLS [T] >>> ***/
164
165
166typedef ConstructedType_t T_t;
167
168
169/*** <<< FUNC-DECLS [T] >>> ***/
170
171extern asn1_TYPE_descriptor_t asn1_DEF_T;
172asn_constr_check_f T_constraint;
173ber_type_decoder_f T_decode_ber;
174der_type_encoder_f T_encode_der;
175asn_struct_print_f T_print;
176asn_struct_free_f T_free;
177
178/*** <<< STAT-DEFS [T] >>> ***/
179
180static ber_tlv_tag_t asn1_DEF_T_tags[] = {
181 (ASN_TAG_CLASS_CONTEXT | (3 << 2))
182};
183asn1_TYPE_descriptor_t asn1_DEF_T = {
184 "T",
185 T_constraint,
186 T_decode_ber,
187 T_encode_der,
188 T_print,
189 T_free,
190 0, /* Use generic outmost tag fetcher */
191 asn1_DEF_T_tags,
192 sizeof(asn1_DEF_T_tags)
Lev Walkin64399722004-08-11 07:17:22 +0000193 /sizeof(asn1_DEF_T_tags[0]), /* 1 */
Lev Walkin5bbff1e2004-06-28 21:13:22 +0000194 1, /* Tags to skip */
195 -0, /* Unknown yet */
196 0 /* No specifics */
197};
198
199int
200T_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
201 asn_app_consume_bytes_f *app_errlog, void *app_key) {
202
203 /* Make the underlying type checker permanent */
204 td->check_constraints = asn1_DEF_ConstructedType.check_constraints;
205 return td->check_constraints
206 (td, sptr, app_errlog, app_key);
207}
208
209/*
210 * This type is implemented using ConstructedType,
211 * so adjust the DEF appropriately.
212 */
213static void
214inherit_TYPE_descriptor(asn1_TYPE_descriptor_t *td) {
215 td->ber_decoder = asn1_DEF_ConstructedType.ber_decoder;
216 td->der_encoder = asn1_DEF_ConstructedType.der_encoder;
217 td->free_struct = asn1_DEF_ConstructedType.free_struct;
218 td->print_struct = asn1_DEF_ConstructedType.print_struct;
219 td->last_tag_form = asn1_DEF_ConstructedType.last_tag_form;
220 td->specifics = asn1_DEF_ConstructedType.specifics;
221}
222
223ber_dec_rval_t
224T_decode_ber(asn1_TYPE_descriptor_t *td,
225 void **structure, void *bufptr, size_t size, int tag_mode) {
226 inherit_TYPE_descriptor(td);
227 return td->ber_decoder(td, structure,
228 bufptr, size, tag_mode);
229}
230
231der_enc_rval_t
232T_encode_der(asn1_TYPE_descriptor_t *td,
233 void *structure, int tag_mode, ber_tlv_tag_t tag,
234 asn_app_consume_bytes_f *cb, void *app_key) {
235 inherit_TYPE_descriptor(td);
236 return td->der_encoder(td, structure, tag_mode, tag, cb, app_key);
237}
238
239int
240T_print(asn1_TYPE_descriptor_t *td, const void *struct_ptr,
241 int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
242 inherit_TYPE_descriptor(td);
243 return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
244}
245
246void
247T_free(asn1_TYPE_descriptor_t *td,
248 void *struct_ptr, int contents_only) {
249 inherit_TYPE_descriptor(td);
250 td->free_struct(td, struct_ptr, contents_only);
251}
252