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.ess.OtherCertID;
07: import org.bouncycastle.asn1.ess.OtherSigningCertificate;
08: import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
09:
10: import java.io.IOException;
11:
12: public class OtherSigningCertificateUnitTest extends ASN1UnitTest {
13: public String getName() {
14: return "OtherSigningCertificate";
15: }
16:
17: public void performTest() throws Exception {
18: AlgorithmIdentifier algId = new AlgorithmIdentifier(
19: new DERObjectIdentifier("1.2.2.3"));
20: byte[] digest = new byte[20];
21: OtherCertID otherCertID = new OtherCertID(algId, digest);
22:
23: OtherSigningCertificate otherCert = new OtherSigningCertificate(
24: otherCertID);
25:
26: checkConstruction(otherCert, otherCertID);
27:
28: otherCert = OtherSigningCertificate.getInstance(null);
29:
30: if (otherCert != null) {
31: fail("null getInstance() failed.");
32: }
33:
34: try {
35: OtherCertID.getInstance(new Object());
36:
37: fail("getInstance() failed to detect bad object.");
38: } catch (IllegalArgumentException e) {
39: // expected
40: }
41: }
42:
43: private void checkConstruction(OtherSigningCertificate otherCert,
44: OtherCertID otherCertID) throws IOException {
45: checkValues(otherCert, otherCertID);
46:
47: otherCert = OtherSigningCertificate.getInstance(otherCert);
48:
49: checkValues(otherCert, otherCertID);
50:
51: ASN1InputStream aIn = new ASN1InputStream(otherCert
52: .toASN1Object().getEncoded());
53:
54: ASN1Sequence seq = (ASN1Sequence) aIn.readObject();
55:
56: otherCert = OtherSigningCertificate.getInstance(seq);
57:
58: checkValues(otherCert, otherCertID);
59: }
60:
61: private void checkValues(OtherSigningCertificate otherCert,
62: OtherCertID otherCertID) {
63: if (otherCert.getCerts().length != 1) {
64: fail("getCerts() length wrong");
65: }
66: checkMandatoryField("getCerts()[0]", otherCertID, otherCert
67: .getCerts()[0]);
68: }
69:
70: public static void main(String[] args) {
71: runTest(new OtherSigningCertificateUnitTest());
72: }
73: }
|