aboutsummaryrefslogtreecommitdiffstats
path: root/tests/19-param-OK.asn1.-P
blob: 83be07d774fe229f6e037397fdbcc46452e9fed0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/*** <<< INCLUDES [Certificate] >>> ***/

#include <OBJECT_IDENTIFIER.h>
#include <BIT_STRING.h>
#include <INTEGER.h>
#include <Name.h>
#include <constr_SEQUENCE.h>

/*** <<< DEPS [Certificate] >>> ***/

extern asn1_TYPE_descriptor_t asn1_DEF_Certificate;

/*** <<< TYPE-DECLS [Certificate] >>> ***/


typedef struct Certificate {
	struct toBeSigned {
		INTEGER_t	 version;
		OBJECT_IDENTIFIER_t	 signature;
		Name_t	 issuer;
		
		/* Context for parsing across buffer boundaries */
		ber_dec_ctx_t _ber_dec_ctx;
	} toBeSigned;
	OBJECT_IDENTIFIER_t	 algorithm;
	BIT_STRING_t	 signature;
	
	/* Context for parsing across buffer boundaries */
	ber_dec_ctx_t _ber_dec_ctx;
} Certificate_t;

/*** <<< CODE [Certificate] >>> ***/

static int
memb_signature_1_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
			asn_app_consume_bytes_f *app_errlog, void *app_key) {
	const BIT_STRING_t *st = sptr;
	size_t size;
	
	if(!sptr) {
		_ASN_ERRLOG(app_errlog, app_key,
			"%s: value not given (%s:%d)",
			td->name, __FILE__, __LINE__);
		return -1;
	}
	
	if(st->size > 0) {
		/* Size in bits */
		size = 8 * (st->size - 1) - (st->buf[0] & 0x7);
	} else {
		size = 0;
	}
	
	if((size <= 256)) {
		/* Constraint check succeeded */
		return 0;
	} else {
		_ASN_ERRLOG(app_errlog, app_key,
			"%s: constraint failed (%s:%d)",
			td->name, __FILE__, __LINE__);
		return -1;
	}
}


/*** <<< STAT-DEFS [Certificate] >>> ***/

static asn1_TYPE_member_t asn1_MBR_toBeSigned[] = {
	{ ATF_NOFLAGS, 0, offsetof(struct toBeSigned, version),
		.tag = (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)),
		.tag_mode = 0,
		.type = (void *)&asn1_DEF_INTEGER,
		.memb_constraints = 0,	/* Defer to actual type */
		.name = "version"
		},
	{ ATF_NOFLAGS, 0, offsetof(struct toBeSigned, signature),
		.tag = (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)),
		.tag_mode = 0,
		.type = (void *)&asn1_DEF_OBJECT_IDENTIFIER,
		.memb_constraints = 0,	/* Defer to actual type */
		.name = "signature"
		},
	{ ATF_NOFLAGS, 0, offsetof(struct toBeSigned, issuer),
		.tag = (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)),
		.tag_mode = 0,
		.type = (void *)&asn1_DEF_Name,
		.memb_constraints = 0,	/* Defer to actual type */
		.name = "issuer"
		},
};
static ber_tlv_tag_t asn1_DEF_toBeSigned_tags[] = {
	(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static asn1_TYPE_tag2member_t asn1_DEF_toBeSigned_tag2el[] = {
    { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 0 }, /* version at 21 */
    { (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)), 1, 0, 0 }, /* signature at 22 */
    { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), 2, 0, 0 }, /* issuer at 24 */
};
static asn1_SEQUENCE_specifics_t asn1_DEF_toBeSigned_specs = {
	sizeof(struct toBeSigned),
	offsetof(struct toBeSigned, _ber_dec_ctx),
	asn1_DEF_toBeSigned_tag2el,
	3,	/* Count of tags in the map */
	-1,	/* Start extensions */
	-1	/* Stop extensions */
};
static /* Use -fall-defs-global to expose */
asn1_TYPE_descriptor_t asn1_DEF_toBeSigned = {
	"toBeSigned",
	SEQUENCE_constraint,
	SEQUENCE_decode_ber,
	SEQUENCE_encode_der,
	SEQUENCE_print,
	SEQUENCE_free,
	0,	/* Use generic outmost tag fetcher */
	asn1_DEF_toBeSigned_tags,
	sizeof(asn1_DEF_toBeSigned_tags)
		/sizeof(asn1_DEF_toBeSigned_tags[0]), /* 1 */
	asn1_DEF_toBeSigned_tags,	/* Same as above */
	sizeof(asn1_DEF_toBeSigned_tags)
		/sizeof(asn1_DEF_toBeSigned_tags[0]), /* 1 */
	1,	/* Whether CONSTRUCTED */
	asn1_MBR_toBeSigned,
	3,	/* Elements count */
	&asn1_DEF_toBeSigned_specs	/* Additional specs */
};

static asn1_TYPE_member_t asn1_MBR_Certificate[] = {
	{ ATF_NOFLAGS, 0, offsetof(struct Certificate, toBeSigned),
		.tag = (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)),
		.tag_mode = 0,
		.type = (void *)&asn1_DEF_toBeSigned,
		.memb_constraints = 0,	/* Defer to actual type */
		.name = "toBeSigned"
		},
	{ ATF_NOFLAGS, 0, offsetof(struct Certificate, algorithm),
		.tag = (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)),
		.tag_mode = 0,
		.type = (void *)&asn1_DEF_OBJECT_IDENTIFIER,
		.memb_constraints = 0,	/* Defer to actual type */
		.name = "algorithm"
		},
	{ ATF_NOFLAGS, 0, offsetof(struct Certificate, signature),
		.tag = (ASN_TAG_CLASS_UNIVERSAL | (3 << 2)),
		.tag_mode = 0,
		.type = (void *)&asn1_DEF_BIT_STRING,
		.memb_constraints = memb_signature_1_constraint,
		.name = "signature"
		},
};
static ber_tlv_tag_t asn1_DEF_Certificate_tags[] = {
	(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static asn1_TYPE_tag2member_t asn1_DEF_Certificate_tag2el[] = {
    { (ASN_TAG_CLASS_UNIVERSAL | (3 << 2)), 2, 0, 0 }, /* signature at 17 */
    { (ASN_TAG_CLASS_UNIVERSAL | (6 << 2)), 1, 0, 0 }, /* algorithm at 16 */
    { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), 0, 0, 0 }, /* toBeSigned at 21 */
};
static asn1_SEQUENCE_specifics_t asn1_DEF_Certificate_specs = {
	sizeof(struct Certificate),
	offsetof(struct Certificate, _ber_dec_ctx),
	asn1_DEF_Certificate_tag2el,
	3,	/* Count of tags in the map */
	-1,	/* Start extensions */
	-1	/* Stop extensions */
};
asn1_TYPE_descriptor_t asn1_DEF_Certificate = {
	"Certificate",
	SEQUENCE_constraint,
	SEQUENCE_decode_ber,
	SEQUENCE_encode_der,
	SEQUENCE_print,
	SEQUENCE_free,
	0,	/* Use generic outmost tag fetcher */
	asn1_DEF_Certificate_tags,
	sizeof(asn1_DEF_Certificate_tags)
		/sizeof(asn1_DEF_Certificate_tags[0]), /* 1 */
	asn1_DEF_Certificate_tags,	/* Same as above */
	sizeof(asn1_DEF_Certificate_tags)
		/sizeof(asn1_DEF_Certificate_tags[0]), /* 1 */
	1,	/* Whether CONSTRUCTED */
	asn1_MBR_Certificate,
	3,	/* Elements count */
	&asn1_DEF_Certificate_specs	/* Additional specs */
};


/*** <<< INCLUDES [Name] >>> ***/

#include <RelativeDistinguishedName.h>
#include <asn_SEQUENCE_OF.h>
#include <constr_SEQUENCE_OF.h>

/*** <<< DEPS [Name] >>> ***/

extern asn1_TYPE_descriptor_t asn1_DEF_Name;

/*** <<< TYPE-DECLS [Name] >>> ***/


typedef struct Name {
	A_SEQUENCE_OF(struct RelativeDistinguishedName) list;
	
	/* Context for parsing across buffer boundaries */
	ber_dec_ctx_t _ber_dec_ctx;
} Name_t;

/*** <<< STAT-DEFS [Name] >>> ***/

static asn1_TYPE_member_t asn1_MBR_Name[] = {
	{ ATF_NOFLAGS, 0, 0,
		.tag = (ASN_TAG_CLASS_UNIVERSAL | (17 << 2)),
		.tag_mode = 0,
		.type = (void *)&asn1_DEF_RelativeDistinguishedName,
		.memb_constraints = 0,	/* Defer to actual type */
		.name = ""
		},
};
static ber_tlv_tag_t asn1_DEF_Name_tags[] = {
	(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static asn1_SET_OF_specifics_t asn1_DEF_Name_specs = {
	sizeof(struct Name),
	offsetof(struct Name, _ber_dec_ctx),
};
asn1_TYPE_descriptor_t asn1_DEF_Name = {
	"Name",
	SEQUENCE_OF_constraint,
	SEQUENCE_OF_decode_ber,
	SEQUENCE_OF_encode_der,
	SEQUENCE_OF_print,
	SEQUENCE_OF_free,
	0,	/* Use generic outmost tag fetcher */
	asn1_DEF_Name_tags,
	sizeof(asn1_DEF_Name_tags)
		/sizeof(asn1_DEF_Name_tags[0]), /* 1 */
	asn1_DEF_Name_tags,	/* Same as above */
	sizeof(asn1_DEF_Name_tags)
		/sizeof(asn1_DEF_Name_tags[0]), /* 1 */
	1,	/* Whether CONSTRUCTED */
	asn1_MBR_Name,
	1,	/* Single element */
	&asn1_DEF_Name_specs	/* Additional specs */
};


/*** <<< INCLUDES [RelativeDistinguishedName] >>> ***/

#include <IA5String.h>
#include <asn_SET_OF.h>
#include <constr_SET_OF.h>

/*** <<< DEPS [RelativeDistinguishedName] >>> ***/

extern asn1_TYPE_descriptor_t asn1_DEF_RelativeDistinguishedName;

/*** <<< TYPE-DECLS [RelativeDistinguishedName] >>> ***/


typedef struct RelativeDistinguishedName {
	A_SET_OF(IA5String_t) list;
	
	/* Context for parsing across buffer boundaries */
	ber_dec_ctx_t _ber_dec_ctx;
} RelativeDistinguishedName_t;

/*** <<< CTABLES [RelativeDistinguishedName] >>> ***/

static int permitted_alphabet_table_1[256] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,	/*                  */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,	/*                  */
0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,	/*             ,-.  */
1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,	/* 0        9       */
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,	/*  ABCDEFGHIJKLMNO */
1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,	/* PQRSTUVWXYZ      */
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,	/*  abcdefghijklmno */
1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,	/* pqrstuvwxyz      */
};

static int check_permitted_alphabet_1(const void *sptr) {
	int *table = permitted_alphabet_table_1;
	/* The underlying type is IA5String */
	const IA5String_t *st = sptr;
	const uint8_t *ch = st->buf;
	const uint8_t *end = ch + st->size;
	
	for(; ch < end; ch++) {
		uint8_t cv = *ch;
		if(!table[cv]) return -1;
	}
	return 0;
}


/*** <<< CODE [RelativeDistinguishedName] >>> ***/

static int
memb_IA5String_2_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
			asn_app_consume_bytes_f *app_errlog, void *app_key) {
	const IA5String_t *st = sptr;
	
	if(!sptr) {
		_ASN_ERRLOG(app_errlog, app_key,
			"%s: value not given (%s:%d)",
			td->name, __FILE__, __LINE__);
		return -1;
	}
	
	
	if(!check_permitted_alphabet_1(sptr)) {
		/* Constraint check succeeded */
		return 0;
	} else {
		_ASN_ERRLOG(app_errlog, app_key,
			"%s: constraint failed (%s:%d)",
			td->name, __FILE__, __LINE__);
		return -1;
	}
}


/*** <<< STAT-DEFS [RelativeDistinguishedName] >>> ***/

static asn1_TYPE_member_t asn1_MBR_RelativeDistinguishedName[] = {
	{ ATF_NOFLAGS, 0, 0,
		.tag = (ASN_TAG_CLASS_UNIVERSAL | (22 << 2)),
		.tag_mode = 0,
		.type = (void *)&asn1_DEF_IA5String,
		.memb_constraints = memb_IA5String_2_constraint,
		.name = ""
		},
};
static ber_tlv_tag_t asn1_DEF_RelativeDistinguishedName_tags[] = {
	(ASN_TAG_CLASS_UNIVERSAL | (17 << 2))
};
static asn1_SET_OF_specifics_t asn1_DEF_RelativeDistinguishedName_specs = {
	sizeof(struct RelativeDistinguishedName),
	offsetof(struct RelativeDistinguishedName, _ber_dec_ctx),
};
asn1_TYPE_descriptor_t asn1_DEF_RelativeDistinguishedName = {
	"RelativeDistinguishedName",
	SET_OF_constraint,
	SET_OF_decode_ber,
	SET_OF_encode_der,
	SET_OF_print,
	SET_OF_free,
	0,	/* Use generic outmost tag fetcher */
	asn1_DEF_RelativeDistinguishedName_tags,
	sizeof(asn1_DEF_RelativeDistinguishedName_tags)
		/sizeof(asn1_DEF_RelativeDistinguishedName_tags[0]), /* 1 */
	asn1_DEF_RelativeDistinguishedName_tags,	/* Same as above */
	sizeof(asn1_DEF_RelativeDistinguishedName_tags)
		/sizeof(asn1_DEF_RelativeDistinguishedName_tags[0]), /* 1 */
	1,	/* Whether CONSTRUCTED */
	asn1_MBR_RelativeDistinguishedName,
	1,	/* Single element */
	&asn1_DEF_RelativeDistinguishedName_specs	/* Additional specs */
};