001: package org.bouncycastle.asn1.test;
002:
003: import org.bouncycastle.asn1.ASN1InputStream;
004: import org.bouncycastle.asn1.ASN1Sequence;
005: import org.bouncycastle.asn1.DERInteger;
006: import org.bouncycastle.asn1.isismtt.x509.ProcurationSyntax;
007: import org.bouncycastle.asn1.x500.DirectoryString;
008: import org.bouncycastle.asn1.x509.GeneralName;
009: import org.bouncycastle.asn1.x509.GeneralNames;
010: import org.bouncycastle.asn1.x509.IssuerSerial;
011: import org.bouncycastle.asn1.x509.X509Name;
012:
013: import java.io.IOException;
014:
015: public class ProcurationSyntaxUnitTest extends ASN1UnitTest {
016: public String getName() {
017: return "ProcurationSyntax";
018: }
019:
020: public void performTest() throws Exception {
021: String country = "AU";
022: DirectoryString typeOfSubstitution = new DirectoryString(
023: "substitution");
024: GeneralName thirdPerson = new GeneralName(new X509Name(
025: "CN=thirdPerson"));
026: IssuerSerial certRef = new IssuerSerial(new GeneralNames(
027: new GeneralName(new X509Name("CN=test"))),
028: new DERInteger(1));
029:
030: ProcurationSyntax procuration = new ProcurationSyntax(country,
031: typeOfSubstitution, thirdPerson);
032:
033: checkConstruction(procuration, country, typeOfSubstitution,
034: thirdPerson, null);
035:
036: procuration = new ProcurationSyntax(country,
037: typeOfSubstitution, certRef);
038:
039: checkConstruction(procuration, country, typeOfSubstitution,
040: null, certRef);
041:
042: procuration = new ProcurationSyntax(null, typeOfSubstitution,
043: certRef);
044:
045: checkConstruction(procuration, null, typeOfSubstitution, null,
046: certRef);
047:
048: procuration = new ProcurationSyntax(country, null, certRef);
049:
050: checkConstruction(procuration, country, null, null, certRef);
051:
052: procuration = ProcurationSyntax.getInstance(null);
053:
054: if (procuration != null) {
055: fail("null getInstance() failed.");
056: }
057:
058: try {
059: ProcurationSyntax.getInstance(new Object());
060:
061: fail("getInstance() failed to detect bad object.");
062: } catch (IllegalArgumentException e) {
063: // expected
064: }
065: }
066:
067: private void checkConstruction(ProcurationSyntax procuration,
068: String country, DirectoryString typeOfSubstitution,
069: GeneralName thirdPerson, IssuerSerial certRef)
070: throws IOException {
071: checkValues(procuration, country, typeOfSubstitution,
072: thirdPerson, certRef);
073:
074: procuration = ProcurationSyntax.getInstance(procuration);
075:
076: checkValues(procuration, country, typeOfSubstitution,
077: thirdPerson, certRef);
078:
079: ASN1InputStream aIn = new ASN1InputStream(procuration
080: .toASN1Object().getEncoded());
081:
082: ASN1Sequence seq = (ASN1Sequence) aIn.readObject();
083:
084: procuration = ProcurationSyntax.getInstance(seq);
085:
086: checkValues(procuration, country, typeOfSubstitution,
087: thirdPerson, certRef);
088: }
089:
090: private void checkValues(ProcurationSyntax procuration,
091: String country, DirectoryString typeOfSubstitution,
092: GeneralName thirdPerson, IssuerSerial certRef) {
093: checkOptionalField("country", country, procuration.getCountry());
094: checkOptionalField("typeOfSubstitution", typeOfSubstitution,
095: procuration.getTypeOfSubstitution());
096: checkOptionalField("thirdPerson", thirdPerson, procuration
097: .getThirdPerson());
098: checkOptionalField("certRef", certRef, procuration.getCertRef());
099: }
100:
101: public static void main(String[] args) {
102: runTest(new ProcurationSyntaxUnitTest());
103: }
104: }
|