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