ObjFW  Diff

Differences From Artifact [da258fe124]:

To Artifact [6b1da7829e]:


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
361


362
363
364

365
366

367
368
369
370


371
372

373
374
375


376
377

378
379
380

381
382

383
384
385


386
387
388
389

390
391
392
393
394
395
396
397
398
399
400


401
402

403
404
405


406
407
408

409
410
411


412
413

414
415
416


417
418
419


420
421
422
423
424
425
426
427
428
429
430
431


432
433

434
435
436


437
438
439

440
441
442


443
444

445
446
447


448
449
450
451

452
453
454
455
456
457
458
459
460
461
462


463
464

465
466
467


468
469
470

471
472
473


474
475
476
477
478
479
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "TestsAppDelegate.h"


static OFString *module = @"OFData+ASN1DERParsing";


@implementation TestsAppDelegate (OFASN1DERParsingTests)
- (void)ASN1DERParsingTests
{
	void *pool = objc_autoreleasePoolPush();
	OFASN1BitString *bitString;
	OFArray *array;
	OFSet *set;
	OFEnumerator *enumerator;

	/* Boolean */
	TEST(@"Parsing of boolean",
	    ![[[OFData dataWithItems: "\x01\x01\x00"
			       count: 3] objectByParsingASN1DER] boolValue] &&


	    [[[OFData dataWithItems: "\x01\x01\xFF"
			      count: 3] objectByParsingASN1DER] boolValue])

	EXPECT_EXCEPTION(@"Detection of invalid boolean #1",
	    OFInvalidFormatException,


	    [[OFData dataWithItems: "\x01\x01\x01"
			     count: 3] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of invalid boolean #2",
	    OFInvalidFormatException,
	    [[OFData dataWithItems: "\x01\x02\x00\x00"
			     count: 4] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of invalid boolean #3",
	    OFInvalidFormatException,
	    [[OFData dataWithItems: "\x01\x00"
			     count: 2] objectByParsingASN1DER])



	EXPECT_EXCEPTION(@"Detection of truncated boolean",
	    OFTruncatedDataException,


	    [[OFData dataWithItems: "\x01\x01"
			     count: 2] objectByParsingASN1DER])


	/* Integer */
	TEST(@"Parsing of integer",

	    [[[OFData dataWithItems: "\x02\x00"
			      count: 2] objectByParsingASN1DER]
	    longLongValue] == 0 &&
	    [[[OFData dataWithItems: "\x02\x01\x01"
			      count: 3] objectByParsingASN1DER]
	    longLongValue] == 1 &&
	    [[[OFData dataWithItems: "\x02\x02\x01\x04"
			      count: 4] objectByParsingASN1DER]
	    longLongValue] == 260 &&
	    [[[OFData dataWithItems: "\x02\x01\xFF"
			      count: 3] objectByParsingASN1DER]
	    longLongValue] == -1 &&
	    [[[OFData dataWithItems: "\x02\x03\xFF\x00\x00"
			      count: 5] objectByParsingASN1DER]
	    longLongValue] == -65536 &&
	    (unsigned long long)[[[OFData dataWithItems: "\x02\x09\x00\xFF\xFF"
							 "\xFF\xFF\xFF\xFF\xFF"
							 "\xFF"
						  count: 11]
	    objectByParsingASN1DER] longLongValue] == ULLONG_MAX)

	EXPECT_EXCEPTION(@"Detection of invalid integer #1",
	    OFInvalidFormatException,


	    [[OFData dataWithItems: "\x02\x02\x00\x00"
			     count: 4] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of invalid integer #2",
	    OFInvalidFormatException,
	    [[OFData dataWithItems: "\x02\x02\x00\x7F"
			     count: 4] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of invalid integer #3",
	    OFInvalidFormatException,
	    [[OFData dataWithItems: "\x02\x02\xFF\x80"
			     count: 4] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of out of range integer",
	    OFOutOfRangeException,


	    [[OFData dataWithItems: "\x02\x09\x01"
				    "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
			     count: 11] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of truncated integer",
	    OFTruncatedDataException,


	    [[OFData dataWithItems: "\x02\x02\x00"
			     count: 3] objectByParsingASN1DER])


	/* Bit string */



	TEST(@"Parsing of bit string",
	    (bitString = [[OFData dataWithItems: "\x03\x01\x00"
					  count: 3] objectByParsingASN1DER]) &&
	    [bitString.bitStringValue isEqual: [OFData dataWithItems: ""
							       count: 0]] &&
	    bitString.bitStringLength == 0 &&

	    (bitString = [[OFData dataWithItems: "\x03\x0D\x01Hello World\x80"
					  count: 15] objectByParsingASN1DER]) &&
	    [bitString.bitStringValue
	    isEqual: [OFData dataWithItems: "Hello World\x80"
				     count: 12]] &&
	    bitString.bitStringLength == 95 &&

	    (bitString = [[OFData dataWithItems: "\x03\x81\x80\x00xxxxxxxxxxxxx"
						 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
						 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
						 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
						 "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
					 count: 131] objectByParsingASN1DER]) &&
	    [bitString.bitStringValue
	    isEqual: [OFData dataWithItems: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
					    "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
					    "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
					    "xxxxxxxxxxxxxxxxxxxxxxxxx"
				     count: 127]] &&
	    bitString.bitStringLength == 127 * 8)

	EXPECT_EXCEPTION(@"Detection of invalid bit string #1",
	    OFInvalidFormatException,


	    [[OFData dataWithItems: "\x03\x00"
			     count: 2] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of invalid bit string #2",
	    OFInvalidFormatException,
	    [[OFData dataWithItems: "\x03\x01\x01"
			     count: 3] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of out of range bit string",
	    OFOutOfRangeException,


	    [[OFData dataWithItems: "\x03\x89"
				    "\x01\x01\x01\x01\x01\x01\x01\x01\x01"
			     count: 11] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of truncated bit string",
	    OFTruncatedDataException,


	    [[OFData dataWithItems: "\x03\x01"
			     count: 2] objectByParsingASN1DER])

	/* Octet string */
	TEST(@"Parsing of octet string",
	    [[[[OFData dataWithItems: "\x04\x0CHello World!"
			       count: 14] objectByParsingASN1DER]
	    octetStringValue] isEqual: [OFData dataWithItems: "Hello World!"
						       count: 12]] &&
	    [[[[OFData dataWithItems: "\x04\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				      "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				      "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				      "xxxxxxxxxxxxxxxxxxxx"
			       count: 131] objectByParsingASN1DER]
	    octetStringValue] isEqual:
	    [OFData dataWithItems: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				   "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				   "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
			    count: 128]])

	EXPECT_EXCEPTION(@"Detection of out of range octet string",
	    OFOutOfRangeException,
	    [[OFData dataWithItems: "\x04\x89"
				    "\x01\x01\x01\x01\x01\x01\x01\x01\x01"
			     count: 11] objectByParsingASN1DER])

	EXPECT_EXCEPTION(@"Detection of truncated octet string",
	    OFTruncatedDataException,
	    [[OFData dataWithItems: "\x04\x01"
			     count: 2] objectByParsingASN1DER])

	/* Null */
	TEST(@"Parsing of null",
	    [[[OFData dataWithItems: "\x05\x00"
			      count: 2] objectByParsingASN1DER]
	    isEqual: [OFNull null]])

	EXPECT_EXCEPTION(@"Detection of invalid null",
	    OFInvalidFormatException,
	    [[OFData dataWithItems: "\x05\x01\x00"
			     count: 3] objectByParsingASN1DER])

	/* Object Identifier */
	TEST(@"Parsing of Object Identifier",
	    (array = [[[OFData dataWithItems: "\x06\x01\x27"
				       count: 3] objectByParsingASN1DER]
	    subidentifiers]) && array.count == 2 &&
	    [[array objectAtIndex: 0] unsignedLongLongValue] == 0 &&
	    [[array objectAtIndex: 1] unsignedLongLongValue] == 39 &&
	    (array = [[[OFData dataWithItems: "\x06\x01\x4F"
				       count: 3] objectByParsingASN1DER]
	    subidentifiers]) && array.count == 2 &&
	    [[array objectAtIndex: 0] unsignedLongLongValue] == 1 &&
	    [[array objectAtIndex: 1] unsignedLongLongValue] == 39 &&
	    (array = [[[OFData dataWithItems: "\x06\x02\x88\x37"
				       count: 4] objectByParsingASN1DER]
	    subidentifiers]) && array.count == 2 &&
	    [[array objectAtIndex: 0] unsignedLongLongValue] == 2 &&
	    [[array objectAtIndex: 1] unsignedLongLongValue] == 999 &&
	    (array = [[[OFData dataWithItems: "\x06\x09\x2A\x86\x48\x86\xF7\x0D"
					      "\x01\x01\x0B"
				       count: 11] objectByParsingASN1DER]
	    subidentifiers]) && array.count == 7 &&
	    [[array objectAtIndex: 0] unsignedLongLongValue] == 1 &&
	    [[array objectAtIndex: 1] unsignedLongLongValue] == 2 &&
	    [[array objectAtIndex: 2] unsignedLongLongValue] == 840 &&
	    [[array objectAtIndex: 3] unsignedLongLongValue] == 113549 &&
	    [[array objectAtIndex: 4] unsignedLongLongValue] == 1 &&
	    [[array objectAtIndex: 5] unsignedLongLongValue] == 1 &&
	    [[array objectAtIndex: 6] unsignedLongLongValue] == 11)

	EXPECT_EXCEPTION(@"Detection of invalid Object Identifier #1",
	    OFInvalidFormatException,
	    [[OFData dataWithItems: "\x06\x01\x81"
			     count: 3] objectByParsingASN1DER])

	EXPECT_EXCEPTION(@"Detection of invalid Object Identifier #2",
	    OFInvalidFormatException,
	    [[OFData dataWithItems: "\x06\x02\x80\x01"
			     count: 4] objectByParsingASN1DER])

	EXPECT_EXCEPTION(@"Detection of out of range Object Identifier",
	    OFOutOfRangeException,
	    [[OFData dataWithItems: "\x06\x0A\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
				    "\xFF\x7F"
			     count: 12] objectByParsingASN1DER])

	EXPECT_EXCEPTION(@"Detection of truncated Object Identifier",
	    OFTruncatedDataException,
	    [[OFData dataWithItems: "\x06\x02\x00"
			     count: 3] objectByParsingASN1DER])

	/* Enumerated */
	TEST(@"Parsing of enumerated",
	    [[[OFData dataWithItems: "\x0A\x00"
			     count: 2] objectByParsingASN1DER] longLongValue] ==
	    0 &&
	    [[[OFData dataWithItems: "\x0A\x01\x01"
			     count: 3] objectByParsingASN1DER] longLongValue] ==
	    1 &&
	    [[[OFData dataWithItems: "\x0A\x02\x01\x04"
			     count: 4] objectByParsingASN1DER] longLongValue] ==
	    260 &&
	    [[[OFData dataWithItems: "\x0A\x01\xFF"
			     count: 3] objectByParsingASN1DER] longLongValue] ==
	    -1 &&
	    [[[OFData dataWithItems: "\x0A\x03\xFF\x00\x00"
			     count: 5] objectByParsingASN1DER] longLongValue] ==
	    -65536 &&
	    (unsigned long long)[[[OFData dataWithItems: "\x0A\x09\x00\xFF\xFF"
							 "\xFF\xFF\xFF\xFF\xFF"
							 "\xFF"
						  count: 11]
	    objectByParsingASN1DER] longLongValue] == ULLONG_MAX)

	EXPECT_EXCEPTION(@"Detection of invalid enumerated #1",
	    OFInvalidFormatException,
	    [[OFData dataWithItems: "\x0A\x02\x00\x00"
			     count: 4] objectByParsingASN1DER])

	EXPECT_EXCEPTION(@"Detection of invalid enumerated #2",
	    OFInvalidFormatException,
	    [[OFData dataWithItems: "\x0A\x02\x00\x7F"
			     count: 4] objectByParsingASN1DER])

	EXPECT_EXCEPTION(@"Detection of invalid enumerated #3",
	    OFInvalidFormatException,

	    [[OFData dataWithItems: "\x0A\x02\xFF\x80"
			     count: 4] objectByParsingASN1DER])

	EXPECT_EXCEPTION(@"Detection of out of range enumerated",
	    OFOutOfRangeException,
	    [[OFData dataWithItems: "\x0A\x09\x01"
				    "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
			     count: 11] objectByParsingASN1DER])

	EXPECT_EXCEPTION(@"Detection of truncated enumerated",
	    OFTruncatedDataException,
	    [[OFData dataWithItems: "\x0A\x02\x00"
			     count: 3] objectByParsingASN1DER])

	/* UTF-8 string */
	TEST(@"Parsing of UTF-8 string",
	    [[[OFData dataWithItems: "\x0C\x0EHällo Wörld!"
			       count: 16] objectByParsingASN1DER]
	    isEqual: @"Hällo Wörld!"] &&
	    [[[OFData dataWithItems: "\x0C\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				     "xxxxxxxxxxxxxxxxx"
			      count: 131] objectByParsingASN1DER]

	    isEqual: @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
		     @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
		     @"xxxxxxxxxxxxxxxx"])


	EXPECT_EXCEPTION(@"Detection of out of range UTF-8 string",






	    OFOutOfRangeException,







































































































































































	    [[OFData dataWithItems: "\x0C\x89"
				    "\x01\x01\x01\x01\x01\x01\x01\x01\x01"
			     count: 11] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of truncated UTF-8 string",
	    OFTruncatedDataException,


	    [[OFData dataWithItems: "\x0C\x01"
			     count: 2] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of truncated length",
	    OFTruncatedDataException,

	    [[OFData dataWithItems: "\x0C\x83\x01\x01"
			     count: 4] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of invalid / inefficient length #1",
	    OFInvalidFormatException,


	    [[OFData dataWithItems: "\x0C\x81\x7F"
			     count: 3] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of invalid / inefficient length #2",
	    OFInvalidFormatException,

	    [[OFData dataWithItems: "\x0C\x82\x00\x80xxxxxxxxxxxxxxxxxxxxxxxxxx"
				    "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				    "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				    "xxxxxxxxxxxxxxxxxx"
			     count: 132] objectByParsingASN1DER])



	/* Sequence */


	TEST(@"Parsing of sequence",
	    (array = [[OFData dataWithItems: "\x30\x00"
				      count: 2] objectByParsingASN1DER]) &&
	    [array isKindOfClass: [OFArray class]] && array.count == 0 &&


	    (array = [[OFData dataWithItems: "\x30\x09\x02\x01\x7B\x0C\x04Test"
				      count: 11] objectByParsingASN1DER]) &&
	    [array isKindOfClass: [OFArray class]] && array.count == 2 &&

	    [[array objectAtIndex: 0] longLongValue] == 123 &&
	    [[array objectAtIndex: 1] isEqual: @"Test"])

	EXPECT_EXCEPTION(@"Detection of truncated sequence #1",
	    OFTruncatedDataException,


	    [[OFData dataWithItems: "\x30\x01"
			     count: 2] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of truncated sequence #2",
	    OFTruncatedDataException,

	    [[OFData dataWithItems: "\x30\x04\x02\x01\x01\x00\x00"
			     count: 7] objectByParsingASN1DER])




	/* Set */
	TEST(@"Parsing of set",
	    (set = [[OFData dataWithItems: "\x31\x00"
				    count: 2] objectByParsingASN1DER]) &&
	    [set isKindOfClass: [OFSet class]] && set.count == 0 &&


	    (set = [[OFData dataWithItems: "\x31\x09\x02\x01\x7B\x0C\x04Test"
				    count: 11] objectByParsingASN1DER]) &&
	    [set isKindOfClass: [OFSet class]] && set.count == 2 &&

	    (enumerator = [set objectEnumerator]) &&
	    [[enumerator nextObject] longLongValue] == 123 &&

	    [[enumerator nextObject] isEqual: @"Test"])

	EXPECT_EXCEPTION(@"Detection of invalid set",
	    OFInvalidFormatException,


	    [[OFData dataWithItems: "\x31\x06\x02\x01\x02\x02\x01\x01"
			     count: 8] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of truncated set #1",
	    OFTruncatedDataException,


	    [[OFData dataWithItems: "\x31\x01"
			     count: 2] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of truncated set #2",
	    OFTruncatedDataException,

	    [[OFData dataWithItems: "\x31\x04\x02\x01\x01\x00\x00"
			     count: 7] objectByParsingASN1DER])


	/* NumericString */
	TEST(@"Parsing of NumericString",


	    [[[[OFData dataWithItems: "\x12\x0B" "12345 67890"
			       count: 13] objectByParsingASN1DER]
	    numericStringValue] isEqual: @"12345 67890"] &&
	    [[[[OFData dataWithItems: "\x12\x81\x80" "0000000000000000000000000"

				      "0000000000000000000000000000000000000000"
				      "0000000000000000000000000000000000000000"
				      "00000000000000000000000"
			       count: 131] objectByParsingASN1DER]
	    numericStringValue] isEqual: @"000000000000000000000000000000000000"
					 @"000000000000000000000000000000000000"
					 @"000000000000000000000000000000000000"
					 @"00000000000000000000"])

	EXPECT_EXCEPTION(@"Detection of invalid NumericString",
	    OFInvalidEncodingException,


	    [[OFData dataWithItems: "\x12\x02."
			     count: 4] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of out of range NumericString",
	    OFOutOfRangeException,


	    [[OFData dataWithItems: "\x12\x89"
				    "\x01\x01\x01\x01\x01\x01\x01\x01\x01"
			     count: 11] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of truncated NumericString",
	    OFTruncatedDataException,


	    [[OFData dataWithItems: "\x12\x01"
			     count: 2] objectByParsingASN1DER])


	/* PrintableString */
	TEST(@"Parsing of PrintableString",


	    [[[[OFData dataWithItems: "\x13\x0CHello World."
			       count: 14] objectByParsingASN1DER]
	    printableStringValue] isEqual: @"Hello World."] &&


	    [[[[OFData dataWithItems: "\x13\x81\x80 '()+,-./:=?abcdefghijklmnop"
				      "qrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '()"
				      "+,-./:=?abcdefghijklmnopqrstuvwxyzABCDEF"
				      "GHIJKLMNOPQRSTUVWXYZ"
			       count: 131] objectByParsingASN1DER]
	    printableStringValue] isEqual: @" '()+,-./:=?abcdefghijklmnopqrstuv"
					   @"wxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '()"
					   @"+,-./:=?abcdefghijklmnopqrstuvwxyz"
					   @"ABCDEFGHIJKLMNOPQRSTUVWXYZ"])

	EXPECT_EXCEPTION(@"Detection of invalid PrintableString",
	    OFInvalidEncodingException,


	    [[OFData dataWithItems: "\x13\x02;"
			     count: 4] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of out of range PrintableString",
	    OFOutOfRangeException,


	    [[OFData dataWithItems: "\x13\x89"
				    "\x01\x01\x01\x01\x01\x01\x01\x01\x01"
			     count: 11] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of truncated PrintableString",
	    OFTruncatedDataException,


	    [[OFData dataWithItems: "\x13\x01"
			     count: 2] objectByParsingASN1DER])


	/* IA5String */
	TEST(@"Parsing of IA5String",


	    [[[[OFData dataWithItems: "\x16\x0CHello World!"
			       count: 14] objectByParsingASN1DER]
	    IA5StringValue] isEqual: @"Hello World!"] &&
	    [[[[OFData dataWithItems: "\x16\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxx"

				      "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				      "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				      "xxxxxxxxxxxxxxxxxxxx"
			       count: 131] objectByParsingASN1DER]
	    IA5StringValue] isEqual: @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				     @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				     @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				     @"xxxxxxxx"])

	EXPECT_EXCEPTION(@"Detection of invalid IA5String",
	    OFInvalidEncodingException,


	    [[OFData dataWithItems: "\x16\x02ä"
			     count: 4] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of out of range IA5String",
	    OFOutOfRangeException,


	    [[OFData dataWithItems: "\x16\x89"
				    "\x01\x01\x01\x01\x01\x01\x01\x01\x01"
			     count: 11] objectByParsingASN1DER])


	EXPECT_EXCEPTION(@"Detection of truncated IA5String",
	    OFTruncatedDataException,


	    [[OFData dataWithItems: "\x16\x01"
			     count: 2] objectByParsingASN1DER])

	objc_autoreleasePoolPop(pool);
}
@end







|
>

|
>

|
|

<
<
<
<
<
|
<
<
|
|
>
>

|
|
|
|
>
>

|
>

|
<

|
>

|
<

|
>
>

<
|
>
>

|
>
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
|
|
|
|
|
>
>

|
>

|
<

|
>

|
<

|
>
|
|
|
>
>


|
>
|
|
|
>
>

|
>
|
|
>
>
>
|
|
|
|
<
|
>
|
|
|
|
<
|
>
|
|
|
|
|
|
|
|
|
|
<
|
|
|
|
|
>
>

|
>

<
|

|
>
|
|
|
>
>


|
>
|
|
|
>
>

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
|
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

<
<
<
<
|
<
<
<
<
|
<
<
>
|
|
<
<
<
|
<
<

<
<
<
<
|
<
<
|
<
<
<




>
|
|
|
>
|
|
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


|
>
|
|
|
>
>

|
>

<
<
>

|
>
|
|
|
>
>

|
>

<
<
>




|
>
|
>
|
>
>
|
|
|
|
>
>
|
|
|
>
|
|
|
|
|
>
>

|
>

<
<
>

|
>
|
>
>
|
|
|
|
|
>
>
|
|
|
>
|
|
>
|
|
|
|
>
>

|
>
|
|
|
>
>

|
>

<
<
>

|
>
|
|
|
>
>
|
|
|
|
>
|
|
|
|
<
|
|
<
|
|
|
>
>

|
>
|
|
|
>
>


|
>
|
|
|
>
>

|
>
|
|
|
>
>
|
|
|
>
>
|
|
<
|
|
<
|
|
<
|
|
|
>
>

|
>
|
|
|
>
>


|
>
|
|
|
>
>

|
>
|
|
|
>
>
|
|
|
|
>
|
|
|
|
<
|
|
<
|
|
|
>
>

|
>
|
|
|
>
>


|
>
|
|
|
>
>

|
|
<


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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385


386
387
388
389
390
391
392
393
394
395
396
397
398


399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431


432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470


471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488

489
490

491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527

528
529

530
531

532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570

571
572

573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597

598
599
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "ObjFW.h"
#import "ObjFWTest.h"

@interface OFASN1DERParsingTests: OTTestCase
@end

@implementation OFASN1DERParsingTests
- (void)testBoolean
{





	OTAssertFalse(


	    [[[OFData dataWithItems: "\x01\x01\x00"
			      count: 3] objectByParsingASN1DER] boolValue]);

	OTAssertTrue(
	    [[[OFData dataWithItems: "\x01\x01\xFF"
			      count: 3] objectByParsingASN1DER] boolValue]);
}

- (void)testInvalidBooleanFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x01\x01\x01"
			     count: 3] objectByParsingASN1DER],
	    OFInvalidFormatException);

	OTAssertThrowsSpecific(

	    [[OFData dataWithItems: "\x01\x02\x00\x00"
			     count: 4] objectByParsingASN1DER],
	    OFInvalidFormatException);

	OTAssertThrowsSpecific(

	    [[OFData dataWithItems: "\x01\x00"
			     count: 2] objectByParsingASN1DER],
	    OFInvalidFormatException);
}


- (void)testTruncatedBooleanFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x01\x01"
			     count: 2] objectByParsingASN1DER],
	    OFTruncatedDataException);
}

- (void)testInteger
{
	OTAssertEqual([[[OFData dataWithItems: "\x02\x00" count: 2]
	    objectByParsingASN1DER] longLongValue], 0);

	OTAssertEqual([[[OFData dataWithItems: "\x02\x01\x01" count: 3]
	    objectByParsingASN1DER] longLongValue], 1);

	OTAssertEqual([[[OFData dataWithItems: "\x02\x02\x01\x04" count: 4]
	    objectByParsingASN1DER] longLongValue], 260);

	OTAssertEqual([[[OFData dataWithItems: "\x02\x01\xFF" count: 3]
	    objectByParsingASN1DER] longLongValue], -1);

	OTAssertEqual([[[OFData dataWithItems: "\x02\x03\xFF\x00\x00" count: 5]
	    objectByParsingASN1DER] longLongValue], -65536);

	OTAssertEqual((unsigned long long)[[[OFData
	    dataWithItems: "\x02\x09\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"

		    count: 11] objectByParsingASN1DER] longLongValue],
	    ULLONG_MAX);
}

- (void)testInvalidIntegerFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x02\x02\x00\x00"
			     count: 4] objectByParsingASN1DER],
	    OFInvalidFormatException);

	OTAssertThrowsSpecific(

	    [[OFData dataWithItems: "\x02\x02\x00\x7F"
			     count: 4] objectByParsingASN1DER],
	    OFInvalidFormatException);

	OTAssertThrowsSpecific(

	    [[OFData dataWithItems: "\x02\x02\xFF\x80"
			     count: 4] objectByParsingASN1DER],
	    OFInvalidFormatException);
}

- (void)testOutOfRangeIntegerFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x02\x09\x01"
				    "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
			     count: 11] objectByParsingASN1DER],
	    OFOutOfRangeException);
}

- (void)testTruncatedIntegerFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x02\x02\x00"
			     count: 3] objectByParsingASN1DER],
	    OFTruncatedDataException);
}

- (void)testBitString
{
	OFASN1BitString *bitString;

	bitString = [[OFData dataWithItems: "\x03\x01\x00"
				     count: 3] objectByParsingASN1DER];
	OTAssertEqualObjects(bitString.bitStringValue, [OFData data]);

	OTAssertEqual(bitString.bitStringLength, 0);

	bitString = [[OFData dataWithItems: "\x03\x0D\x01Hello World\x80"
				     count: 15] objectByParsingASN1DER];
	OTAssertEqualObjects(bitString.bitStringValue,
	    [OFData dataWithItems: "Hello World\x80" count: 12]);

	OTAssertEqual(bitString.bitStringLength, 95);

	bitString = [[OFData dataWithItems: "\x03\x81\x80\x00xxxxxxxxxxxxxxxxxx"
					    "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
					    "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
					    "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
					    "xxxxxxx"
				     count: 131] objectByParsingASN1DER];
	OTAssertEqualObjects(bitString.bitStringValue,
	    [OFData dataWithItems: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				   "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				   "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

			    count: 127]);
	OTAssertEqual(bitString.bitStringLength, 127 * 8);
}

- (void)testInvalidBitStringFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x03\x00"
			     count: 2] objectByParsingASN1DER],
	    OFInvalidFormatException);


	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x03\x01\x01"
			     count: 3] objectByParsingASN1DER],
	    OFInvalidFormatException);
}

- (void)testOutOfRangeBitStringFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x03\x89"
				    "\x01\x01\x01\x01\x01\x01\x01\x01\x01"
			     count: 11] objectByParsingASN1DER],
	    OFOutOfRangeException);
}

- (void)testTruncatedBitStringFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x03\x01"




















































































			     count: 2] objectByParsingASN1DER],


	    OFTruncatedDataException);


}



























- (void)testOctetString




{


	OTAssertEqualObjects([[[OFData
	    dataWithItems: "\x04\x0CHello World!"
		    count: 14] objectByParsingASN1DER] octetStringValue],



	    [OFData dataWithItems: "Hello World!" count: 12]);







	OTAssertEqualObjects(


	    [[[OFData dataWithItems: "\x04\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"



				     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				     "xxxxxxxxxxxxxxxxx"
			      count: 131] objectByParsingASN1DER]
	    octetStringValue],
	    [OFData dataWithItems: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				   "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				   "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
			    count: 128]);
}

- (void)testOutOfRangeOctetStringFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x04\x89"
				    "\x01\x01\x01\x01\x01\x01\x01\x01\x01"
			     count: 11] objectByParsingASN1DER],
	    OFOutOfRangeException);
}

- (void)testTruncatedOctetStringFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x04\x01"
			     count: 2] objectByParsingASN1DER],
	    OFTruncatedDataException);
}

- (void)testNull
{
	OTAssertEqualObjects([[OFData dataWithItems: "\x05\x00" count: 2]
	    objectByParsingASN1DER], [OFNull null]);
}

- (void)testInvalidNullFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x05\x01\x00"
			     count: 3] objectByParsingASN1DER],
	    OFInvalidFormatException);
}

- (void)testObjectIdentifier
{
	OFArray *array;

	array = [[[OFData dataWithItems: "\x06\x01\x27" count: 3]
	    objectByParsingASN1DER] subidentifiers];
	OTAssertEqual(array.count, 2);
	OTAssertEqual([[array objectAtIndex: 0] unsignedLongLongValue], 0);
	OTAssertEqual([[array objectAtIndex: 1] unsignedLongLongValue], 39);

	array = [[[OFData dataWithItems: "\x06\x01\x4F" count: 3]
	    objectByParsingASN1DER] subidentifiers];
	OTAssertEqual(array.count, 2);
	OTAssertEqual([[array objectAtIndex: 0] unsignedLongLongValue], 1);
	OTAssertEqual([[array objectAtIndex: 1] unsignedLongLongValue], 39);

	array = [[[OFData dataWithItems: "\x06\x02\x88\x37" count: 4]
	    objectByParsingASN1DER] subidentifiers];
	OTAssertEqual(array.count, 2);
	OTAssertEqual([[array objectAtIndex: 0] unsignedLongLongValue], 2);
	OTAssertEqual([[array objectAtIndex: 1] unsignedLongLongValue], 999);

	array = [[[OFData
	    dataWithItems: "\x06\x09\x2A\x86\x48\x86\xF7\x0D\x01\x01\x0B"
		    count: 11] objectByParsingASN1DER] subidentifiers];
	OTAssertEqual(array.count, 7);
	OTAssertEqual([[array objectAtIndex: 0] unsignedLongLongValue], 1);
	OTAssertEqual([[array objectAtIndex: 1] unsignedLongLongValue], 2);
	OTAssertEqual([[array objectAtIndex: 2] unsignedLongLongValue], 840);
	OTAssertEqual([[array objectAtIndex: 3] unsignedLongLongValue], 113549);
	OTAssertEqual([[array objectAtIndex: 4] unsignedLongLongValue], 1);
	OTAssertEqual([[array objectAtIndex: 5] unsignedLongLongValue], 1);
	OTAssertEqual([[array objectAtIndex: 6] unsignedLongLongValue], 11);
}

- (void)testInvalidObjectIdentifierFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x06\x01\x81"
			     count: 3] objectByParsingASN1DER],
	    OFInvalidFormatException);

	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x06\x02\x80\x01"
			     count: 4] objectByParsingASN1DER],
	    OFInvalidFormatException);
}

- (void)testOutOfRangeObjectIdentifier
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x06\x0A\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
				    "\xFF\x7F"
			     count: 12] objectByParsingASN1DER],
	    OFOutOfRangeException);
}

- (void)testTruncatedObjectIdentifierFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x06\x02\x00"
			     count: 3] objectByParsingASN1DER],
	    OFTruncatedDataException);
}

- (void)testEnumerated
{
	OTAssertEqual([[[OFData dataWithItems: "\x0A\x00" count: 2]
	    objectByParsingASN1DER] longLongValue], 0);

	OTAssertEqual([[[OFData dataWithItems: "\x0A\x01\x01" count: 3]
	    objectByParsingASN1DER] longLongValue], 1);

	OTAssertEqual([[[OFData dataWithItems: "\x0A\x02\x01\x04" count: 4]
	    objectByParsingASN1DER] longLongValue], 260);

	OTAssertEqual([[[OFData dataWithItems: "\x0A\x01\xFF" count: 3]
	    objectByParsingASN1DER] longLongValue], -1);

	OTAssertEqual([[[OFData dataWithItems: "\x0A\x03\xFF\x00\x00" count: 5]
	    objectByParsingASN1DER] longLongValue], -65536);

	OTAssertEqual((unsigned long long)[[[OFData
	    dataWithItems: "\x0A\x09\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
		    count: 11] objectByParsingASN1DER] longLongValue],
	    ULLONG_MAX);
}

- (void)testInvalidEnumeratedFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x0A\x02\x00\x00"
			     count: 4] objectByParsingASN1DER],
	    OFInvalidFormatException);

	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x0A\x02\x00\x7F"
			     count: 4] objectByParsingASN1DER],
	    OFInvalidFormatException);

	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x0A\x02\xFF\x80"
			     count: 4] objectByParsingASN1DER],
	    OFInvalidFormatException);
}

- (void)testOutOfRangeEnumeratedFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x0A\x09\x01"
				    "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
			     count: 11] objectByParsingASN1DER],
	    OFOutOfRangeException);
}

- (void)testTruncatedEnumeratedFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x0A\x02\x00"
			     count: 3] objectByParsingASN1DER],
	    OFTruncatedDataException);
}

- (void)testUTF8String
{
	OTAssertEqualObjects(
	    [[OFData dataWithItems: "\x0C\x0EHällo Wörld!"
			     count: 16] objectByParsingASN1DER],
	    @"Hällo Wörld!");

	OTAssertEqualObjects(
	    [[OFData dataWithItems: "\x0C\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				    "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				    "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				    "xxxxxxxxxxxxxx"
			     count: 131] objectByParsingASN1DER],
	    @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
	    @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
}

- (void)testOutOfRangeUTF8StringFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x0C\x89"
				    "\x01\x01\x01\x01\x01\x01\x01\x01\x01"
			     count: 11] objectByParsingASN1DER],
	    OFOutOfRangeException);
}

- (void)testTruncatedUTF8StringFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x0C\x01"
			     count: 2] objectByParsingASN1DER],
	    OFTruncatedDataException);



	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x0C\x83\x01\x01"
			     count: 4] objectByParsingASN1DER],
	    OFTruncatedDataException);
}

- (void)testInvalidUTF8StringFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x0C\x81\x7F"
			     count: 3] objectByParsingASN1DER],
	    OFInvalidFormatException);



	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x0C\x82\x00\x80xxxxxxxxxxxxxxxxxxxxxxxxxx"
				    "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				    "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
				    "xxxxxxxxxxxxxxxxxx"
			     count: 132] objectByParsingASN1DER],
	    OFInvalidFormatException);
}

- (void)testSequence
{
	OFArray *array;

	array = [[OFData dataWithItems: "\x30\x00"
				 count: 2] objectByParsingASN1DER];
	OTAssertTrue([array isKindOfClass: [OFArray class]]);
	OTAssertEqual(array.count, 0);

	array = [[OFData dataWithItems: "\x30\x09\x02\x01\x7B\x0C\x04Test"
				 count: 11] objectByParsingASN1DER];
	OTAssertTrue([array isKindOfClass: [OFArray class]]);
	OTAssertEqual(array.count, 2);
	OTAssertEqual([[array objectAtIndex: 0] longLongValue], 123);
	OTAssertEqualObjects([array objectAtIndex: 1], @"Test");
}

- (void)testTruncatedSequenceFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x30\x01"
			     count: 2] objectByParsingASN1DER],
	    OFTruncatedDataException);



	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x30\x04\x02\x01\x01\x00\x00"
			     count: 7] objectByParsingASN1DER],
	    OFTruncatedDataException);
}
- (void)testSet
{
	OFSet *set;

	set = [[OFData dataWithItems: "\x31\x00"
			       count: 2] objectByParsingASN1DER];
	OTAssertTrue([set isKindOfClass: [OFSet class]]);
	OTAssertEqual(set.count, 0);

	set = [[OFData dataWithItems: "\x31\x09\x02\x01\x7B\x0C\x04Test"
			       count: 11] objectByParsingASN1DER];
	OTAssertTrue([set isKindOfClass: [OFSet class]]);
	OTAssertEqual(set.count, 2);

	OTAssertEqualObjects(set,
	    ([OFSet setWithObjects: [OFNumber numberWithLongLong: 123],
	    @"Test", nil]));
}

- (void)testInvalidSetFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x31\x06\x02\x01\x02\x02\x01\x01"
			     count: 8] objectByParsingASN1DER],
	    OFInvalidFormatException);
}

- (void)testTruncatedSetFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x31\x01"
			     count: 2] objectByParsingASN1DER],
	    OFTruncatedDataException);



	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x31\x04\x02\x01\x01\x00\x00"
			     count: 7] objectByParsingASN1DER],
	    OFTruncatedDataException);
}

- (void)testNumericString
{
	OTAssertEqualObjects([[[OFData
	    dataWithItems: "\x12\x0B" "12345 67890"
		    count: 13] objectByParsingASN1DER] numericStringValue],
	    @"12345 67890");

	OTAssertEqualObjects([[[OFData
	    dataWithItems: "\x12\x81\x80" "000000000000000000000000000000000000"
			   "000000000000000000000000000000000000000000000000000"
			   "00000000000000000000000000000000000000000"
		    count: 131] objectByParsingASN1DER] numericStringValue],

	    @"00000000000000000000000000000000000000000000000000000000000000000"
	    @"000000000000000000000000000000000000000000000000000000000000000");

}

- (void)testInvalidNumericStringFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x12\x02."
			     count: 4] objectByParsingASN1DER],
	    OFInvalidEncodingException);
}

- (void)testOutOfRangeNumericStringFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x12\x89"
				    "\x01\x01\x01\x01\x01\x01\x01\x01\x01"
			     count: 11] objectByParsingASN1DER],
	    OFOutOfRangeException);
}

- (void)testTruncatedNumericStringFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x12\x01"
			     count: 2] objectByParsingASN1DER],
	    OFTruncatedDataException);
}

- (void)testPrintableString
{
	OTAssertEqualObjects([[[OFData
	    dataWithItems: "\x13\x0CHello World."
		    count: 14] objectByParsingASN1DER] printableStringValue],
	    @"Hello World.");

	OTAssertEqualObjects([[[OFData
	    dataWithItems: "\x13\x81\x80 '()+,-./:=?abcdefghijklmnopqrstuvwxyzA"
			   "BCDEFGHIJKLMNOPQRSTUVWXYZ '()+,-./:=?abcdefghijklmn"

			   "opqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
		    count: 131] objectByParsingASN1DER] printableStringValue],

	    @" '()+,-./:=?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
	    @"'()+,-./:=?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");

}

- (void)testInvalidPrintableStringFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x13\x02;"
			     count: 4] objectByParsingASN1DER],
	    OFInvalidEncodingException);
}

- (void)testOutOfRangePrintableStringFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x13\x89"
				    "\x01\x01\x01\x01\x01\x01\x01\x01\x01"
			     count: 11] objectByParsingASN1DER],
	    OFOutOfRangeException);
}

- (void)testTruncatedPrintableStringFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x13\x01"
			     count: 2] objectByParsingASN1DER],
	    OFTruncatedDataException);
}

- (void)testIA5String
{
	OTAssertEqualObjects([[[OFData
	    dataWithItems: "\x16\x0CHello World!"
		    count: 14] objectByParsingASN1DER] IA5StringValue],
	    @"Hello World!");

	OTAssertEqualObjects([[[OFData
	    dataWithItems: "\x16\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
			   "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
			   "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
		    count: 131] objectByParsingASN1DER] IA5StringValue],

	    @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
	    @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");

}

- (void)testInvalidIA5StringFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x16\x02ä"
			     count: 4] objectByParsingASN1DER],
	    OFInvalidEncodingException);
}

- (void)testOutOfRangeIA5StringFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x16\x89"
				    "\x01\x01\x01\x01\x01\x01\x01\x01\x01"
			     count: 11] objectByParsingASN1DER],
	    OFOutOfRangeException);
}

- (void)testTruncatedIA5StringFails
{
	OTAssertThrowsSpecific(
	    [[OFData dataWithItems: "\x16\x01"
			     count: 2] objectByParsingASN1DER],
	    OFTruncatedDataException);

}
@end