org.bouncycastle.asn1.test.CMCUnsignedDataTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-ext-debug-jdk15on Show documentation
Show all versions of bcprov-ext-debug-jdk15on Show documentation
The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.8 with debug enabled.
package org.bouncycastle.asn1.test;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.cmc.BodyPartID;
import org.bouncycastle.asn1.cmc.BodyPartPath;
import org.bouncycastle.asn1.cmc.CMCUnsignedData;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.util.test.SimpleTest;
public class CMCUnsignedDataTest
extends SimpleTest
{
public static void main(String[] args)
{
runTest(new CMCUnsignedDataTest());
}
public String getName()
{
return "CMCUnsignedDataTest";
}
public void performTest()
throws Exception
{
// Encode then decode
CMCUnsignedData data = new CMCUnsignedData(new BodyPartPath(new BodyPartID(10L)), PKCSObjectIdentifiers.certBag, new DEROctetString("Cats".getBytes()));
byte[] b = data.getEncoded();
CMCUnsignedData result = CMCUnsignedData.getInstance(data);
isEquals(data.getBodyPartPath(), result.getBodyPartPath());
isEquals(data.getIdentifier(), result.getIdentifier());
isEquals(data.getContent(), result.getContent());
// Sequence length must be 3
try
{
CMCUnsignedData.getInstance(new DERSequence(new ASN1Integer(10)));
fail("Must fail, sequence must be 3");
}
catch (Exception ex)
{
isEquals(ex.getClass(), IllegalArgumentException.class);
}
try
{
CMCUnsignedData.getInstance(new DERSequence(new ASN1Encodable[]{new ASN1Integer(10), new ASN1Integer(10), new ASN1Integer(10), new ASN1Integer(10)}));
fail("Must fail, sequence must be 3");
}
catch (Exception ex)
{
isEquals(ex.getClass(), IllegalArgumentException.class);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy