01: package org.bouncycastle.asn1.test;
02:
03: import org.bouncycastle.asn1.DERObjectIdentifier;
04: import org.bouncycastle.asn1.x509.X509Extensions;
05: import org.bouncycastle.asn1.x509.X509ExtensionsGenerator;
06: import org.bouncycastle.util.test.SimpleTest;
07:
08: public class X509ExtensionsTest extends SimpleTest {
09: private static final DERObjectIdentifier OID_2 = new DERObjectIdentifier(
10: "1.2.2");
11: private static final DERObjectIdentifier OID_3 = new DERObjectIdentifier(
12: "1.2.3");
13: private static final DERObjectIdentifier OID_1 = new DERObjectIdentifier(
14: "1.2.1");
15:
16: public String getName() {
17: return "X509Extensions";
18: }
19:
20: public void performTest() throws Exception {
21: X509ExtensionsGenerator gen = new X509ExtensionsGenerator();
22:
23: gen.addExtension(OID_1, true, new byte[20]);
24: gen.addExtension(OID_2, true, new byte[20]);
25:
26: X509Extensions ext1 = gen.generate();
27: X509Extensions ext2 = gen.generate();
28:
29: if (!ext1.equals(ext2)) {
30: fail("equals test failed");
31: }
32:
33: gen.reset();
34:
35: gen.addExtension(OID_2, true, new byte[20]);
36: gen.addExtension(OID_1, true, new byte[20]);
37:
38: ext2 = gen.generate();
39:
40: if (ext1.equals(ext2)) {
41: fail("inequality test failed");
42: }
43:
44: if (!ext1.equivalent(ext2)) {
45: fail("equivalence true failed");
46: }
47:
48: gen.reset();
49:
50: gen.addExtension(OID_1, true, new byte[22]);
51: gen.addExtension(OID_2, true, new byte[20]);
52:
53: ext2 = gen.generate();
54:
55: if (ext1.equals(ext2)) {
56: fail("inequality 1 failed");
57: }
58:
59: if (ext1.equivalent(ext2)) {
60: fail("non-equivalence 1 failed");
61: }
62:
63: gen.reset();
64:
65: gen.addExtension(OID_3, true, new byte[20]);
66: gen.addExtension(OID_2, true, new byte[20]);
67:
68: ext2 = gen.generate();
69:
70: if (ext1.equals(ext2)) {
71: fail("inequality 2 failed");
72: }
73:
74: if (ext1.equivalent(ext2)) {
75: fail("non-equivalence 2 failed");
76: }
77:
78: try {
79: gen.addExtension(OID_2, true, new byte[20]);
80: fail("repeated oid");
81: } catch (IllegalArgumentException e) {
82: if (!e.getMessage().equals("extension 1.2.2 already added")) {
83: fail("wrong exception on repeated oid: "
84: + e.getMessage());
85: }
86: }
87: }
88:
89: public static void main(String[] args) {
90: runTest(new X509ExtensionsTest());
91: }
92: }
|