1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.michaelo.tomcat.asn1;
17
18 import net.sf.michaelo.tomcat.realm.asn1.OtherNameAsn1Parser;
19 import net.sf.michaelo.tomcat.realm.asn1.OtherNameParseResult;
20
21 import org.apache.tomcat.util.buf.Asn1Parser;
22 import org.hamcrest.CoreMatchers;
23 import org.hamcrest.MatcherAssert;
24 import org.junit.Assert;
25 import org.junit.Test;
26
27 public class OtherNameAsn1ParserTest {
28
29 @Test(expected = NullPointerException.class)
30 public void testNullOtherName() throws Exception {
31 OtherNameAsn1Parser.parse(null);
32 }
33
34 @Test(expected = IllegalArgumentException.class)
35 public void testEmptyOtherName() {
36 OtherNameAsn1Parser.parse(new byte[0]);
37 }
38
39 @Test
40 public void testNotStartingSequence() {
41 byte[] otherName = {(byte) 0x31};
42
43 try {
44 OtherNameAsn1Parser.parse(otherName);
45 Assert.fail("Exception expected");
46 } catch (IllegalArgumentException e) {
47 MatcherAssert.assertThat(
48 e.getMessage(), CoreMatchers.equalTo("Expected to find value [48] but found value [49]"));
49 }
50 }
51
52 @Test(expected = ArrayIndexOutOfBoundsException.class)
53 public void testNullLength() {
54 byte[] otherName = {(byte) 0x30};
55
56 OtherNameAsn1Parser.parse(otherName);
57 }
58
59 @Test(expected = ArrayIndexOutOfBoundsException.class)
60 public void testIndefiniteLength() {
61 byte[] otherName = {(byte) 0x30, (byte) 0x80};
62
63 OtherNameAsn1Parser.parse(otherName);
64 }
65
66 @Test(expected = ArrayIndexOutOfBoundsException.class)
67 public void testMoreThanTwoByteLength() {
68 byte[] otherName = {(byte) 0x30, (byte) 0x83};
69
70 try {
71 OtherNameAsn1Parser.parse(otherName);
72 Assert.fail("Exception expected");
73 } catch (IllegalArgumentException e) {
74 MatcherAssert.assertThat(
75 e.getMessage(), CoreMatchers.equalTo("Type length above 64 KiB ist not supported"));
76 }
77 }
78
79 @Test(expected = ArrayIndexOutOfBoundsException.class)
80 public void testTwoByteLength1() {
81 byte[] otherName = {(byte) 0x30, (byte) 0x82};
82
83 OtherNameAsn1Parser.parse(otherName);
84 }
85
86 @Test
87 public void testTwoByteLength2() {
88 byte[] otherName = {(byte) 0x30, (byte) 0x81, (byte) 0x80};
89
90 try {
91 OtherNameAsn1Parser.parse(otherName);
92 Assert.fail("Exception expected");
93 } catch (IllegalArgumentException e) {
94 MatcherAssert.assertThat(
95 e.getMessage(),
96 CoreMatchers.equalTo(
97 "Invalid length [128] bytes reported when the input data length is [0] bytes"));
98 }
99 }
100
101 @Test
102 public void testHalfByteLength() {
103 byte[] otherName = {(byte) 0x30, (byte) 0x7F};
104
105 try {
106 OtherNameAsn1Parser.parse(otherName);
107 Assert.fail("Exception expected");
108 } catch (IllegalArgumentException e) {
109 MatcherAssert.assertThat(
110 e.getMessage(),
111 CoreMatchers.equalTo(
112 "Invalid length [127] bytes reported when the input data length is [0] bytes"));
113 }
114 }
115
116 @Test
117 public void testThreeByteLength1() {
118 byte[] otherName = {(byte) 0x30, (byte) 0x82, (byte) 0xFF, (byte) 0x7F};
119
120 try {
121 OtherNameAsn1Parser.parse(otherName);
122 Assert.fail("Exception expected");
123 } catch (IllegalArgumentException e) {
124 MatcherAssert.assertThat(
125 e.getMessage(),
126 CoreMatchers.equalTo(
127 "Invalid length [65,407] bytes reported when the input data length is [0] bytes"));
128 }
129 }
130
131 @Test
132 public void testThreeByteLength2() {
133 byte[] otherName = {(byte) 0x30, (byte) 0x82, (byte) 0xFF, (byte) 0xFF};
134
135 try {
136 OtherNameAsn1Parser.parse(otherName);
137 Assert.fail("Exception expected");
138 } catch (IllegalArgumentException e) {
139 MatcherAssert.assertThat(
140 e.getMessage(),
141 CoreMatchers.startsWith(
142 "Invalid length [65,535] bytes reported when the input data length is [0] bytes"));
143 }
144 }
145
146 @Test(expected = ArrayIndexOutOfBoundsException.class)
147 public void testParseZeroLengthSequence() {
148 byte[] otherName = {(byte) 0x30, (byte) 0x00};
149
150 OtherNameAsn1Parser.parse(otherName);
151 }
152
153 @Test(expected = ArrayIndexOutOfBoundsException.class)
154 public void testParseZeroLengthOid() {
155 byte[] otherName = {(byte) 0x30, (byte) 0x02, (byte) 0x06, (byte) 0x00};
156
157 OtherNameAsn1Parser.parse(otherName);
158 }
159
160 @Test
161 public void testParseNotStartingOid() {
162 byte[] otherName = {(byte) 0x30, (byte) 0x02, (byte) 0x05, (byte) 0x00};
163
164 try {
165 OtherNameAsn1Parser.parse(otherName);
166 Assert.fail("Exception expected");
167 } catch (IllegalArgumentException e) {
168 MatcherAssert.assertThat(
169 e.getMessage(), CoreMatchers.equalTo("Expected to find value [6] but found value [5]"));
170 }
171 }
172
173 @Test(expected = ArrayIndexOutOfBoundsException.class)
174 public void testParseInvalidOidLength() {
175 byte[] otherName = {(byte) 0x30, (byte) 0x03, (byte) 0x06, (byte) 0x05, (byte) 0x01};
176
177 OtherNameAsn1Parser.parse(otherName);
178 }
179
180 @Test
181 public void testParseTruncatedOidLength() {
182 byte[] otherName = {
183 (byte) 0x30,
184 (byte) 0x04 ,
185 (byte) 0x06,
186 (byte) 0x03,
187 (byte) 0x01,
188 (byte) 0x01,
189 (byte) 0x01
190 };
191
192 try {
193 OtherNameAsn1Parser.parse(otherName);
194 Assert.fail("Exception expected");
195 } catch (IllegalArgumentException e) {
196 MatcherAssert.assertThat(
197 e.getMessage(),
198 CoreMatchers.equalTo("Invalid length [4] bytes reported when the input data length is [5] bytes"));
199 }
200 }
201
202 @Test(expected = ArrayIndexOutOfBoundsException.class)
203 public void testParseNoValue() {
204 byte[] otherName = {(byte) 0x30, (byte) 0x03, (byte) 0x06, (byte) 0x01, (byte) 0x01};
205
206 OtherNameAsn1Parser.parse(otherName);
207 }
208
209 @Test
210 public void testParseUniversalTagValue() {
211 byte[] otherName = {(byte) 0x30, (byte) 0x04, (byte) 0x06, (byte) 0x01, (byte) 0x01, (byte) 0x0C};
212
213 try {
214 OtherNameAsn1Parser.parse(otherName);
215 Assert.fail("Exception expected");
216 } catch (IllegalArgumentException e) {
217 MatcherAssert.assertThat(
218 e.getMessage(), CoreMatchers.equalTo("Expected to find value [160] but found value [12]"));
219 }
220 }
221
222 @Test
223 public void testParseContextSpecificTagValue() {
224 byte[] otherName = {(byte) 0x30, (byte) 0x04, (byte) 0x06, (byte) 0x01, (byte) 0x01, (byte) (0x0C | 0x80)};
225
226 try {
227 OtherNameAsn1Parser.parse(otherName);
228 Assert.fail("Exception expected");
229 } catch (IllegalArgumentException e) {
230 MatcherAssert.assertThat(
231 e.getMessage(), CoreMatchers.equalTo("Expected to find value [160] but found value [140]"));
232 }
233 }
234
235 @Test
236 public void testParseWrongTagNumberInValue() {
237 byte[] otherName = {(byte) 0x30, (byte) 0x04, (byte) 0x06, (byte) 0x01, (byte) 0x01, (byte) 0xA1};
238
239 try {
240 OtherNameAsn1Parser.parse(otherName);
241 Assert.fail("Exception expected");
242 } catch (IllegalArgumentException e) {
243 MatcherAssert.assertThat(
244 e.getMessage(), CoreMatchers.equalTo("Expected to find value [160] but found value [161]"));
245 }
246 }
247
248 @Test(expected = ArrayIndexOutOfBoundsException.class)
249 public void testParseInvalidConstructedValue1() {
250 byte[] otherName = {(byte) 0x30, (byte) 0x05, (byte) 0x06, (byte) 0x01, (byte) 0x01, (byte) 0xA0, (byte) 0x02};
251
252 OtherNameAsn1Parser.parse(otherName);
253 }
254
255 @Test
256 public void testParseInvalidConstructedValue2() {
257 byte[] otherName = {
258 (byte) 0x30,
259 (byte) 0x05,
260 (byte) 0x06,
261 (byte) 0x01,
262 (byte) 0x01,
263 (byte) 0xA0,
264 (byte) 0x00,
265 (byte) 0x0C,
266 (byte) 0x03,
267 (byte) 'Y',
268 (byte) 'E',
269 (byte) 'S'
270 };
271
272 try {
273 OtherNameAsn1Parser.parse(otherName);
274 Assert.fail("Exception expected");
275 } catch (IllegalArgumentException e) {
276 MatcherAssert.assertThat(
277 e.getMessage(),
278 CoreMatchers.equalTo("Invalid length [5] bytes reported when the input data length is [10] bytes"));
279 }
280 }
281
282 @Test(expected = ArrayIndexOutOfBoundsException.class)
283 public void testParseInvalidConstructedValue3() {
284 byte[] otherName = {
285 (byte) 0x30,
286 (byte) 0x0C,
287 (byte) 0x06,
288 (byte) 0x01,
289 (byte) 0x01,
290 (byte) 0xA0,
291 (byte) 0x06,
292 (byte) 0xA0,
293 (byte) 0x05,
294 (byte) 0x0C,
295 (byte) 0x03,
296 (byte) 'Y',
297 (byte) 'E',
298 (byte) 'S'
299 };
300
301 OtherNameAsn1Parser.parse(otherName);
302 }
303
304 @Test
305 public void testParseInvalidConstructedValue4() throws Exception {
306 byte[] otherName = {
307 (byte) 0x30,
308 (byte) 0x0C,
309 (byte) 0x06,
310 (byte) 0x01,
311 (byte) 0x01,
312 (byte) 0xA0,
313 (byte) 0x07,
314 (byte) 0xA0,
315 (byte) 0x04,
316 (byte) 0x0C,
317 (byte) 0x03,
318 (byte) 'Y',
319 (byte) 'E',
320 (byte) 'S'
321 };
322
323 OtherNameParseResult result = OtherNameAsn1Parser.parse(otherName);
324 Assert.assertArrayEquals(new byte[] {0x01}, result.getTypeId());
325 Assert.assertArrayEquals(new byte[] {(byte) 0x0C, (byte) 0x03, (byte) 'Y', (byte) 'E'}, result.getValue());
326 }
327
328 @Test
329 public void testParseInvalidConstructedValue5() {
330 byte[] otherName = {
331 (byte) 0x30,
332 (byte) 0x0C,
333 (byte) 0x06,
334 (byte) 0x01,
335 (byte) 0x01,
336 (byte) 0xA0,
337 (byte) 0x07,
338 (byte) 0xA0,
339 (byte) 0x00,
340 (byte) 0x0C,
341 (byte) 0x03,
342 (byte) 'Y',
343 (byte) 'E',
344 (byte) 'S'
345 };
346
347 OtherNameParseResult result = OtherNameAsn1Parser.parse(otherName);
348 Assert.assertArrayEquals(new byte[] {0x01}, result.getTypeId());
349 Assert.assertArrayEquals(new byte[0], result.getValue());
350 }
351
352 @Test
353 public void testParseOtherName() throws Exception {
354 byte[] otherName = {
355 (byte) 0x30,
356 (byte) 0x0A,
357 (byte) 0x06,
358 (byte) 0x01,
359 (byte) 0x01,
360 (byte) 0xA0,
361 (byte) 0x05,
362 (byte) 0x0C,
363 (byte) 0x03,
364 (byte) 'Y',
365 (byte) 'E',
366 (byte) 'S'
367 };
368
369 OtherNameParseResult result = OtherNameAsn1Parser.parse(otherName);
370 Assert.assertArrayEquals(new byte[] {0x01}, result.getTypeId());
371 Assert.assertArrayEquals(
372 new byte[] {(byte) 0x0C, (byte) 0x03, (byte) 'Y', (byte) 'E', (byte) 'S'}, result.getValue());
373 }
374
375 @Test
376 public void testParseConstructedTagValueJDK6776681() throws Exception {
377 byte[] otherName = {
378 (byte) 0x30,
379 (byte) 0x0C,
380 (byte) 0x06,
381 (byte) 0x01,
382 (byte) 0x01,
383 (byte) 0xA0,
384 (byte) 0x07,
385 (byte) (0xC | 0x10),
386 (byte) 0x05,
387 (byte) 0x0C,
388 (byte) 0x03,
389 (byte) 'Y',
390 (byte) 'E',
391 (byte) 'S'
392 };
393
394 OtherNameParseResult result = OtherNameAsn1Parser.parse(otherName);
395 Assert.assertArrayEquals(new byte[] {0x01}, result.getTypeId());
396 Assert.assertArrayEquals(
397 new byte[] {
398 (byte) (0xC | 0x10), (byte) 0x05, (byte) 0x0C, (byte) 0x03, (byte) 'Y', (byte) 'E', (byte) 'S'
399 },
400 result.getValue());
401 }
402
403 @Test
404 public void testParseContextSpecificTagValueJDK6776681() throws Exception {
405 byte[] otherName = {
406 (byte) 0x30,
407 (byte) 0x0C,
408 (byte) 0x06,
409 (byte) 0x01,
410 (byte) 0x01,
411 (byte) 0xA0,
412 (byte) 0x07,
413 (byte) (0xC | 0x80),
414 (byte) 0x05,
415 (byte) 0x0C,
416 (byte) 0x03,
417 (byte) 'Y',
418 (byte) 'E',
419 (byte) 'S'
420 };
421
422 OtherNameParseResult result = OtherNameAsn1Parser.parse(otherName);
423 Assert.assertArrayEquals(new byte[] {0x01}, result.getTypeId());
424 Assert.assertArrayEquals(
425 new byte[] {
426 (byte) (0xC | 0x80), (byte) 0x05, (byte) 0x0C, (byte) 0x03, (byte) 'Y', (byte) 'E', (byte) 'S'
427 },
428 result.getValue());
429 }
430
431 @Test
432 public void testParseWrongTagNumberValueJDK6776681() throws Exception {
433 byte[] otherName = {
434 (byte) 0x30,
435 (byte) 0x0C,
436 (byte) 0x06,
437 (byte) 0x01,
438 (byte) 0x01,
439 (byte) 0xA0,
440 (byte) 0x07,
441 (byte) 0xA1,
442 (byte) 0x05,
443 (byte) 0x0C,
444 (byte) 0x03,
445 (byte) 'Y',
446 (byte) 'E',
447 (byte) 'S'
448 };
449
450 OtherNameParseResult result = OtherNameAsn1Parser.parse(otherName);
451 Assert.assertArrayEquals(new byte[] {0x01}, result.getTypeId());
452 Assert.assertArrayEquals(
453 new byte[] {(byte) 0xA1, (byte) 0x05, (byte) 0x0C, (byte) 0x03, (byte) 'Y', (byte) 'E', (byte) 'S'},
454 result.getValue());
455 }
456
457 @Test(expected = ArrayIndexOutOfBoundsException.class)
458 public void testParseInvalidConstructedValueJDK6776681() {
459 byte[] otherName = {
460 (byte) 0x30,
461 (byte) 0x07,
462 (byte) 0x06,
463 (byte) 0x01,
464 (byte) 0x01,
465 (byte) 0xA0,
466 (byte) 0x02,
467 (byte) 0xA0,
468 (byte) 0x02
469 };
470
471 OtherNameAsn1Parser.parse(otherName);
472 }
473
474 @Test
475 public void testParseOtherNameJDK6776681() throws Exception {
476 byte[] otherName = {
477 (byte) 0x30,
478 (byte) 0x0C,
479 (byte) 0x06,
480 (byte) 0x01,
481 (byte) 0x01,
482 (byte) 0xA0,
483 (byte) 0x07,
484 (byte) 0xA0,
485 (byte) 0x05,
486 (byte) 0x0C,
487 (byte) 0x03,
488 (byte) 'Y',
489 (byte) 'E',
490 (byte) 'S'
491 };
492
493 OtherNameParseResult result = OtherNameAsn1Parser.parse(otherName);
494 Assert.assertArrayEquals(new byte[] {0x01}, result.getTypeId());
495 Assert.assertArrayEquals(
496 new byte[] {(byte) 0x0C, (byte) 0x03, (byte) 'Y', (byte) 'E', (byte) 'S'}, result.getValue());
497 }
498
499 @Test
500 public void testParseOtherNameLongSequence() throws Exception {
501 byte[] otherName = {
502 (byte) 0x30,
503 (byte) 0x82,
504 (byte) 0x01,
505 (byte) 0x01,
506 (byte) 0x06,
507 (byte) 0x64,
508 (byte) 0x02,
509 (byte) 0x01,
510 (byte) 0x01,
511 (byte) 0x01,
512 (byte) 0x01,
513 (byte) 0x01,
514 (byte) 0x01,
515 (byte) 0x01,
516 (byte) 0x01,
517 (byte) 0x01,
518 (byte) 0x01,
519 (byte) 0x01,
520 (byte) 0x01,
521 (byte) 0x01,
522 (byte) 0x01,
523 (byte) 0x01,
524 (byte) 0x01,
525 (byte) 0x01,
526 (byte) 0x01,
527 (byte) 0x01,
528 (byte) 0x01,
529 (byte) 0x01,
530 (byte) 0x01,
531 (byte) 0x01,
532 (byte) 0x01,
533 (byte) 0x01,
534 (byte) 0x01,
535 (byte) 0x01,
536 (byte) 0x01,
537 (byte) 0x01,
538 (byte) 0x01,
539 (byte) 0x01,
540 (byte) 0x01,
541 (byte) 0x01,
542 (byte) 0x01,
543 (byte) 0x01,
544 (byte) 0x01,
545 (byte) 0x01,
546 (byte) 0x01,
547 (byte) 0x01,
548 (byte) 0x01,
549 (byte) 0x01,
550 (byte) 0x01,
551 (byte) 0x01,
552 (byte) 0x01,
553 (byte) 0x01,
554 (byte) 0x01,
555 (byte) 0x01,
556 (byte) 0x01,
557 (byte) 0x01,
558 (byte) 0x01,
559 (byte) 0x01,
560 (byte) 0x01,
561 (byte) 0x01,
562 (byte) 0x01,
563 (byte) 0x01,
564 (byte) 0x01,
565 (byte) 0x01,
566 (byte) 0x01,
567 (byte) 0x01,
568 (byte) 0x01,
569 (byte) 0x01,
570 (byte) 0x01,
571 (byte) 0x01,
572 (byte) 0x01,
573 (byte) 0x01,
574 (byte) 0x01,
575 (byte) 0x01,
576 (byte) 0x01,
577 (byte) 0x01,
578 (byte) 0x01,
579 (byte) 0x01,
580 (byte) 0x01,
581 (byte) 0x01,
582 (byte) 0x01,
583 (byte) 0x01,
584 (byte) 0x01,
585 (byte) 0x01,
586 (byte) 0x01,
587 (byte) 0x01,
588 (byte) 0x01,
589 (byte) 0x01,
590 (byte) 0x01,
591 (byte) 0x01,
592 (byte) 0x01,
593 (byte) 0x01,
594 (byte) 0x01,
595 (byte) 0x01,
596 (byte) 0x01,
597 (byte) 0x01,
598 (byte) 0x01,
599 (byte) 0x01,
600 (byte) 0x01,
601 (byte) 0x01,
602 (byte) 0x01,
603 (byte) 0x01,
604 (byte) 0x01,
605 (byte) 0x01,
606 (byte) 0x01,
607 (byte) 0x02,
608 (byte) 0xA0,
609 (byte) 0x81,
610 (byte) 0x98,
611 (byte) 0xA0,
612 (byte) 0x81,
613 (byte) 0x95,
614 (byte) 0x0C,
615 (byte) 0x81,
616 (byte) 0x92,
617 (byte) 'Y',
618 (byte) 'E',
619 (byte) 'E',
620 (byte) 'E',
621 (byte) 'E',
622 (byte) 'E',
623 (byte) 'E',
624 (byte) 'E',
625 (byte) 'E',
626 (byte) 'E',
627 (byte) 'E',
628 (byte) 'E',
629 (byte) 'E',
630 (byte) 'E',
631 (byte) 'E',
632 (byte) 'E',
633 (byte) 'E',
634 (byte) 'E',
635 (byte) 'E',
636 (byte) 'E',
637 (byte) 'E',
638 (byte) 'E',
639 (byte) 'E',
640 (byte) 'E',
641 (byte) 'E',
642 (byte) 'E',
643 (byte) 'E',
644 (byte) 'E',
645 (byte) 'E',
646 (byte) 'E',
647 (byte) 'E',
648 (byte) 'E',
649 (byte) 'E',
650 (byte) 'E',
651 (byte) 'E',
652 (byte) 'E',
653 (byte) 'E',
654 (byte) 'E',
655 (byte) 'E',
656 (byte) 'E',
657 (byte) 'E',
658 (byte) 'E',
659 (byte) 'E',
660 (byte) 'E',
661 (byte) 'E',
662 (byte) 'E',
663 (byte) 'E',
664 (byte) 'E',
665 (byte) 'E',
666 (byte) 'E',
667 (byte) 'E',
668 (byte) 'E',
669 (byte) 'E',
670 (byte) 'E',
671 (byte) 'E',
672 (byte) 'E',
673 (byte) 'E',
674 (byte) 'E',
675 (byte) 'E',
676 (byte) 'E',
677 (byte) 'E',
678 (byte) 'E',
679 (byte) 'E',
680 (byte) 'E',
681 (byte) 'E',
682 (byte) 'E',
683 (byte) 'E',
684 (byte) 'E',
685 (byte) 'E',
686 (byte) 'E',
687 (byte) 'E',
688 (byte) 'E',
689 (byte) 'E',
690 (byte) 'E',
691 (byte) 'E',
692 (byte) 'E',
693 (byte) 'E',
694 (byte) 'E',
695 (byte) 'E',
696 (byte) 'E',
697 (byte) 'E',
698 (byte) 'E',
699 (byte) 'E',
700 (byte) 'E',
701 (byte) 'E',
702 (byte) 'E',
703 (byte) 'E',
704 (byte) 'E',
705 (byte) 'E',
706 (byte) 'E',
707 (byte) 'E',
708 (byte) 'E',
709 (byte) 'E',
710 (byte) 'E',
711 (byte) 'E',
712 (byte) 'E',
713 (byte) 'E',
714 (byte) 'E',
715 (byte) 'E',
716 (byte) 'E',
717 (byte) 'E',
718 (byte) 'E',
719 (byte) 'E',
720 (byte) 'E',
721 (byte) 'E',
722 (byte) 'E',
723 (byte) 'E',
724 (byte) 'E',
725 (byte) 'E',
726 (byte) 'E',
727 (byte) 'E',
728 (byte) 'E',
729 (byte) 'E',
730 (byte) 'E',
731 (byte) 'E',
732 (byte) 'E',
733 (byte) 'E',
734 (byte) 'E',
735 (byte) 'E',
736 (byte) 'E',
737 (byte) 'E',
738 (byte) 'E',
739 (byte) 'E',
740 (byte) 'E',
741 (byte) 'E',
742 (byte) 'E',
743 (byte) 'E',
744 (byte) 'E',
745 (byte) 'E',
746 (byte) 'E',
747 (byte) 'E',
748 (byte) 'E',
749 (byte) 'E',
750 (byte) 'E',
751 (byte) 'E',
752 (byte) 'E',
753 (byte) 'E',
754 (byte) 'E',
755 (byte) 'E',
756 (byte) 'E',
757 (byte) 'E',
758 (byte) 'E',
759 (byte) 'E',
760 (byte) 'E',
761 (byte) 'E',
762 (byte) 'S'
763 };
764
765 OtherNameParseResult result = OtherNameAsn1Parser.parse(otherName);
766 byte[] typeId = result.getTypeId();
767 Assert.assertEquals(100, typeId.length);
768 Assert.assertEquals(2, typeId[0]);
769 Assert.assertEquals(2, typeId[typeId.length - 1]);
770 byte[] value = result.getValue();
771 Assert.assertEquals(149, value.length);
772 Asn1Parser parser = new Asn1Parser(value);
773 String str = parser.parseUTF8String();
774 Assert.assertEquals(
775 "YEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEES",
776 str);
777 }
778
779 @Test
780 public void testParseOtherNameLongSequenceJDK6776681() throws Exception {
781 byte[] otherName = {
782 (byte) 0x30,
783 (byte) 0x81,
784 (byte) 0xFE,
785 (byte) 0x06,
786 (byte) 0x64,
787 (byte) 0x02,
788 (byte) 0x01,
789 (byte) 0x01,
790 (byte) 0x01,
791 (byte) 0x01,
792 (byte) 0x01,
793 (byte) 0x01,
794 (byte) 0x01,
795 (byte) 0x01,
796 (byte) 0x01,
797 (byte) 0x01,
798 (byte) 0x01,
799 (byte) 0x01,
800 (byte) 0x01,
801 (byte) 0x01,
802 (byte) 0x01,
803 (byte) 0x01,
804 (byte) 0x01,
805 (byte) 0x01,
806 (byte) 0x01,
807 (byte) 0x01,
808 (byte) 0x01,
809 (byte) 0x01,
810 (byte) 0x01,
811 (byte) 0x01,
812 (byte) 0x01,
813 (byte) 0x01,
814 (byte) 0x01,
815 (byte) 0x01,
816 (byte) 0x01,
817 (byte) 0x01,
818 (byte) 0x01,
819 (byte) 0x01,
820 (byte) 0x01,
821 (byte) 0x01,
822 (byte) 0x01,
823 (byte) 0x01,
824 (byte) 0x01,
825 (byte) 0x01,
826 (byte) 0x01,
827 (byte) 0x01,
828 (byte) 0x01,
829 (byte) 0x01,
830 (byte) 0x01,
831 (byte) 0x01,
832 (byte) 0x01,
833 (byte) 0x01,
834 (byte) 0x01,
835 (byte) 0x01,
836 (byte) 0x01,
837 (byte) 0x01,
838 (byte) 0x01,
839 (byte) 0x01,
840 (byte) 0x01,
841 (byte) 0x01,
842 (byte) 0x01,
843 (byte) 0x01,
844 (byte) 0x01,
845 (byte) 0x01,
846 (byte) 0x01,
847 (byte) 0x01,
848 (byte) 0x01,
849 (byte) 0x01,
850 (byte) 0x01,
851 (byte) 0x01,
852 (byte) 0x01,
853 (byte) 0x01,
854 (byte) 0x01,
855 (byte) 0x01,
856 (byte) 0x01,
857 (byte) 0x01,
858 (byte) 0x01,
859 (byte) 0x01,
860 (byte) 0x01,
861 (byte) 0x01,
862 (byte) 0x01,
863 (byte) 0x01,
864 (byte) 0x01,
865 (byte) 0x01,
866 (byte) 0x01,
867 (byte) 0x01,
868 (byte) 0x01,
869 (byte) 0x01,
870 (byte) 0x01,
871 (byte) 0x01,
872 (byte) 0x01,
873 (byte) 0x01,
874 (byte) 0x01,
875 (byte) 0x01,
876 (byte) 0x01,
877 (byte) 0x01,
878 (byte) 0x01,
879 (byte) 0x01,
880 (byte) 0x01,
881 (byte) 0x01,
882 (byte) 0x01,
883 (byte) 0x01,
884 (byte) 0x01,
885 (byte) 0x01,
886 (byte) 0x02,
887 (byte) 0xA0,
888 (byte) 0x81,
889 (byte) 0x95,
890 (byte) 0x0C,
891 (byte) 0x81,
892 (byte) 0x92,
893 (byte) 'Y',
894 (byte) 'E',
895 (byte) 'E',
896 (byte) 'E',
897 (byte) 'E',
898 (byte) 'E',
899 (byte) 'E',
900 (byte) 'E',
901 (byte) 'E',
902 (byte) 'E',
903 (byte) 'E',
904 (byte) 'E',
905 (byte) 'E',
906 (byte) 'E',
907 (byte) 'E',
908 (byte) 'E',
909 (byte) 'E',
910 (byte) 'E',
911 (byte) 'E',
912 (byte) 'E',
913 (byte) 'E',
914 (byte) 'E',
915 (byte) 'E',
916 (byte) 'E',
917 (byte) 'E',
918 (byte) 'E',
919 (byte) 'E',
920 (byte) 'E',
921 (byte) 'E',
922 (byte) 'E',
923 (byte) 'E',
924 (byte) 'E',
925 (byte) 'E',
926 (byte) 'E',
927 (byte) 'E',
928 (byte) 'E',
929 (byte) 'E',
930 (byte) 'E',
931 (byte) 'E',
932 (byte) 'E',
933 (byte) 'E',
934 (byte) 'E',
935 (byte) 'E',
936 (byte) 'E',
937 (byte) 'E',
938 (byte) 'E',
939 (byte) 'E',
940 (byte) 'E',
941 (byte) 'E',
942 (byte) 'E',
943 (byte) 'E',
944 (byte) 'E',
945 (byte) 'E',
946 (byte) 'E',
947 (byte) 'E',
948 (byte) 'E',
949 (byte) 'E',
950 (byte) 'E',
951 (byte) 'E',
952 (byte) 'E',
953 (byte) 'E',
954 (byte) 'E',
955 (byte) 'E',
956 (byte) 'E',
957 (byte) 'E',
958 (byte) 'E',
959 (byte) 'E',
960 (byte) 'E',
961 (byte) 'E',
962 (byte) 'E',
963 (byte) 'E',
964 (byte) 'E',
965 (byte) 'E',
966 (byte) 'E',
967 (byte) 'E',
968 (byte) 'E',
969 (byte) 'E',
970 (byte) 'E',
971 (byte) 'E',
972 (byte) 'E',
973 (byte) 'E',
974 (byte) 'E',
975 (byte) 'E',
976 (byte) 'E',
977 (byte) 'E',
978 (byte) 'E',
979 (byte) 'E',
980 (byte) 'E',
981 (byte) 'E',
982 (byte) 'E',
983 (byte) 'E',
984 (byte) 'E',
985 (byte) 'E',
986 (byte) 'E',
987 (byte) 'E',
988 (byte) 'E',
989 (byte) 'E',
990 (byte) 'E',
991 (byte) 'E',
992 (byte) 'E',
993 (byte) 'E',
994 (byte) 'E',
995 (byte) 'E',
996 (byte) 'E',
997 (byte) 'E',
998 (byte) 'E',
999 (byte) 'E',
1000 (byte) 'E',
1001 (byte) 'E',
1002 (byte) 'E',
1003 (byte) 'E',
1004 (byte) 'E',
1005 (byte) 'E',
1006 (byte) 'E',
1007 (byte) 'E',
1008 (byte) 'E',
1009 (byte) 'E',
1010 (byte) 'E',
1011 (byte) 'E',
1012 (byte) 'E',
1013 (byte) 'E',
1014 (byte) 'E',
1015 (byte) 'E',
1016 (byte) 'E',
1017 (byte) 'E',
1018 (byte) 'E',
1019 (byte) 'E',
1020 (byte) 'E',
1021 (byte) 'E',
1022 (byte) 'E',
1023 (byte) 'E',
1024 (byte) 'E',
1025 (byte) 'E',
1026 (byte) 'E',
1027 (byte) 'E',
1028 (byte) 'E',
1029 (byte) 'E',
1030 (byte) 'E',
1031 (byte) 'E',
1032 (byte) 'E',
1033 (byte) 'E',
1034 (byte) 'E',
1035 (byte) 'E',
1036 (byte) 'E',
1037 (byte) 'E',
1038 (byte) 'S'
1039 };
1040
1041 OtherNameParseResult result = OtherNameAsn1Parser.parse(otherName);
1042 byte[] typeId = result.getTypeId();
1043 Assert.assertEquals(100, typeId.length);
1044 Assert.assertEquals(2, typeId[0]);
1045 Assert.assertEquals(2, typeId[typeId.length - 1]);
1046 byte[] value = result.getValue();
1047 Assert.assertEquals(149, value.length);
1048 Asn1Parser parser = new Asn1Parser(value);
1049 String str = parser.parseUTF8String();
1050 Assert.assertEquals(
1051 "YEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEES",
1052 str);
1053 }
1054 }