01: package org.bouncycastle.asn1.test;
02:
03: import org.bouncycastle.asn1.ASN1InputStream;
04: import org.bouncycastle.asn1.ASN1Sequence;
05: import org.bouncycastle.asn1.DERObjectIdentifier;
06: import org.bouncycastle.asn1.DERSequence;
07: import org.bouncycastle.asn1.isismtt.x509.AdmissionSyntax;
08: import org.bouncycastle.asn1.isismtt.x509.Admissions;
09: import org.bouncycastle.asn1.isismtt.x509.NamingAuthority;
10: import org.bouncycastle.asn1.isismtt.x509.ProfessionInfo;
11: import org.bouncycastle.asn1.x500.DirectoryString;
12: import org.bouncycastle.asn1.x509.GeneralName;
13: import org.bouncycastle.asn1.x509.X509Name;
14:
15: import java.io.IOException;
16:
17: public class AdmissionSyntaxUnitTest extends ASN1UnitTest {
18: public String getName() {
19: return "AdmissionSyntax";
20: }
21:
22: public void performTest() throws Exception {
23: GeneralName name = new GeneralName(new X509Name(
24: "CN=hello world"));
25: ASN1Sequence admissions = new DERSequence(new Admissions(name,
26: new NamingAuthority(new DERObjectIdentifier("1.2.3"),
27: "url", new DirectoryString("fred")),
28: new ProfessionInfo[0]));
29: AdmissionSyntax syntax = new AdmissionSyntax(name, admissions);
30:
31: checkConstruction(syntax, name, admissions);
32:
33: syntax = AdmissionSyntax.getInstance(null);
34:
35: if (syntax != null) {
36: fail("null getInstance() failed.");
37: }
38:
39: try {
40: AdmissionSyntax.getInstance(new Object());
41:
42: fail("getInstance() failed to detect bad object.");
43: } catch (IllegalArgumentException e) {
44: // expected
45: }
46: }
47:
48: private void checkConstruction(AdmissionSyntax syntax,
49: GeneralName authority, ASN1Sequence admissions)
50: throws IOException {
51: checkValues(syntax, authority, admissions);
52:
53: syntax = AdmissionSyntax.getInstance(syntax);
54:
55: checkValues(syntax, authority, admissions);
56:
57: ASN1InputStream aIn = new ASN1InputStream(syntax.toASN1Object()
58: .getEncoded());
59:
60: ASN1Sequence info = (ASN1Sequence) aIn.readObject();
61:
62: syntax = AdmissionSyntax.getInstance(info);
63:
64: checkValues(syntax, authority, admissions);
65: }
66:
67: private void checkValues(AdmissionSyntax syntax,
68: GeneralName authority, ASN1Sequence admissions) {
69: checkMandatoryField("admissionAuthority", authority, syntax
70: .getAdmissionAuthority());
71:
72: Admissions[] adm = syntax.getContentsOfAdmissions();
73:
74: if (adm.length != 1
75: || !adm[0].equals(admissions.getObjectAt(0))) {
76: fail("admissions check failed");
77: }
78: }
79:
80: public static void main(String[] args) {
81: runTest(new AdmissionSyntaxUnitTest());
82: }
83: }
|