org.bouncycastle.asn1.test.DecryptedPOPTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-jdk15to18 Show documentation
Show all versions of bcprov-jdk15to18 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.
package org.bouncycastle.asn1.test;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.cmc.BodyPartID;
import org.bouncycastle.asn1.cmc.DecryptedPOP;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.test.SimpleTest;
public class DecryptedPOPTest
extends SimpleTest
{
public static void main(String[] args)
{
runTest(new DecryptedPOPTest());
}
public String getName()
{
return "DecryptedPOPTest";
}
public void performTest()
throws Exception
{
AlgorithmIdentifier algId = new AlgorithmIdentifier(new ASN1ObjectIdentifier("1.9.8.7.6")); // Not real!
DecryptedPOP pop = new DecryptedPOP(new BodyPartID(10L), algId, "cats".getBytes());
byte[] b = pop.getEncoded();
DecryptedPOP popResult = DecryptedPOP.getInstance(b);
isEquals("Bodypart id", popResult.getBodyPartID(), pop.getBodyPartID());
isTrue("The POP", Arrays.areEqual(popResult.getThePOP(), pop.getThePOP()));
isEquals("POP Result", popResult.getThePOPAlgID(), pop.getThePOPAlgID());
try
{
DecryptedPOP.getInstance(new DERSequence(new BodyPartID(10L)));
fail("Sequence must be 3 elements long");
}
catch (Throwable t)
{
isEquals(t.getClass(), IllegalArgumentException.class);
}
}
}