diff options
author | Roberto Tyley <roberto.tyley@gmail.com> | 2014-07-15 01:38:01 +0400 |
---|---|---|
committer | Roberto Tyley <roberto.tyley@gmail.com> | 2014-07-26 11:23:17 +0400 |
commit | 7cb752aaf746dc0b473afeb9e892b7fbc12666c5 (patch) | |
tree | cc4f91ddc18332b5adbe82e3fcb040d976c90105 /core/src/test/java/org/spongycastle/asn1/test/OtherSigningCertificateUnitTest.java | |
parent | 551830f8ea5177042af2c7dd1fc90888bc67387d (diff) |
Execute become-spongy.sh
https://github.com/rtyley/spongycastle/blob/3040af/become-spongy.sh
Diffstat (limited to 'core/src/test/java/org/spongycastle/asn1/test/OtherSigningCertificateUnitTest.java')
-rw-r--r-- | core/src/test/java/org/spongycastle/asn1/test/OtherSigningCertificateUnitTest.java | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/core/src/test/java/org/spongycastle/asn1/test/OtherSigningCertificateUnitTest.java b/core/src/test/java/org/spongycastle/asn1/test/OtherSigningCertificateUnitTest.java new file mode 100644 index 00000000..96c67256 --- /dev/null +++ b/core/src/test/java/org/spongycastle/asn1/test/OtherSigningCertificateUnitTest.java @@ -0,0 +1,86 @@ +package org.spongycastle.asn1.test; + +import java.io.IOException; + +import org.spongycastle.asn1.ASN1InputStream; +import org.spongycastle.asn1.ASN1ObjectIdentifier; +import org.spongycastle.asn1.ASN1Sequence; +import org.spongycastle.asn1.ess.OtherCertID; +import org.spongycastle.asn1.ess.OtherSigningCertificate; +import org.spongycastle.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()); + } +} |