01: package org.bouncycastle.asn1.test;
02:
03: import java.io.IOException;
04:
05: import org.bouncycastle.asn1.DERBitString;
06: import org.bouncycastle.asn1.DERT61String;
07: import org.bouncycastle.asn1.DERUniversalString;
08: import org.bouncycastle.util.test.SimpleTest;
09:
10: /**
11: * X.690 test example
12: */
13: public class StringTest extends SimpleTest {
14: public String getName() {
15: return "String";
16: }
17:
18: public void performTest() throws IOException {
19: DERBitString bs = new DERBitString(new byte[] { (byte) 0x01,
20: (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89,
21: (byte) 0xab, (byte) 0xcd, (byte) 0xef });
22:
23: if (!bs.getString().equals("#0309000123456789ABCDEF")) {
24: fail("DERBitString.getString() result incorrect");
25: }
26:
27: if (!bs.toString().equals("#0309000123456789ABCDEF")) {
28: fail("DERBitString.toString() result incorrect");
29: }
30:
31: bs = new DERBitString(new byte[] { (byte) 0xfe, (byte) 0xdc,
32: (byte) 0xba, (byte) 0x98, (byte) 0x76, (byte) 0x54,
33: (byte) 0x32, (byte) 0x10 });
34:
35: if (!bs.getString().equals("#030900FEDCBA9876543210")) {
36: fail("DERBitString.getString() result incorrect");
37: }
38:
39: if (!bs.toString().equals("#030900FEDCBA9876543210")) {
40: fail("DERBitString.toString() result incorrect");
41: }
42:
43: DERUniversalString us = new DERUniversalString(new byte[] {
44: (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67,
45: (byte) 0x89, (byte) 0xab, (byte) 0xcd, (byte) 0xef });
46:
47: if (!us.getString().equals("#1C080123456789ABCDEF")) {
48: fail("DERUniversalString.getString() result incorrect");
49: }
50:
51: if (!us.toString().equals("#1C080123456789ABCDEF")) {
52: fail("DERUniversalString.toString() result incorrect");
53: }
54:
55: us = new DERUniversalString(new byte[] { (byte) 0xfe,
56: (byte) 0xdc, (byte) 0xba, (byte) 0x98, (byte) 0x76,
57: (byte) 0x54, (byte) 0x32, (byte) 0x10 });
58:
59: if (!us.getString().equals("#1C08FEDCBA9876543210")) {
60: fail("DERUniversalString.getString() result incorrect");
61: }
62:
63: if (!us.toString().equals("#1C08FEDCBA9876543210")) {
64: fail("DERUniversalString.toString() result incorrect");
65: }
66:
67: byte[] t61Bytes = new byte[] { -1, -2, -3, -4, -5, -6, -7, -8 };
68: String t61String = new String(t61Bytes, "iso-8859-1");
69: DERT61String t61 = new DERT61String(t61Bytes);
70:
71: if (!t61.getString().equals(t61String)) {
72: fail("DERT61String.getString() result incorrect");
73: }
74:
75: if (!t61.toString().equals(t61String)) {
76: fail("DERT61String.toString() result incorrect");
77: }
78: }
79:
80: public static void main(String[] args) {
81: runTest(new StringTest());
82: }
83: }
|