All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.asn1.test.CMCUnsignedDataTest Maven / Gradle / Ivy

Go to download

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. Note: this package includes the NTRU encryption algorithms.

There is a newer version: 1.70
Show newest version
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