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

org.bouncycastle.asn1.test.GetCRLTest 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.7. Note: this package includes the IDEA and NTRU encryption algorithms.

There is a newer version: 1.70
Show newest version
package org.bouncycastle.asn1.test;

import java.util.Date;

import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1GeneralizedTime;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.cmc.GetCRL;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.asn1.x500.X500NameBuilder;
import org.bouncycastle.asn1.x500.style.BCStyle;
import org.bouncycastle.asn1.x509.GeneralName;
import org.bouncycastle.asn1.x509.ReasonFlags;
import org.bouncycastle.util.test.SimpleTest;

public class GetCRLTest
    extends SimpleTest
{

    public static void main(String[] args)
    {
        runTest(new GetCRLTest());
    }

    public String getName()
    {
        return "GetCRLTest";
    }

    public void performTest()
        throws Exception
    {

        {
            X500NameBuilder builder = new X500NameBuilder(BCStyle.INSTANCE);
            builder.addRDN(BCStyle.C, "AU");
            X500Name name = new X500Name(builder.build().toString());

            GetCRL crl = new GetCRL(
                name,
                new GeneralName(GeneralName.rfc822Name, "/"),
                new ASN1GeneralizedTime(new Date()),
                new ReasonFlags(ReasonFlags.affiliationChanged)
            );

            byte[] b = crl.getEncoded();

            GetCRL crlResp = GetCRL.getInstance(b);

            isEquals("IssuerName", crl.getIssuerName(), crlResp.getIssuerName());
            isEquals("cRLName", crl.getcRLName(), crlResp.getcRLName());
            isEquals("time", crl.getTime(), crlResp.getTime());
            isEquals("reasons", crl.getReasons(), crlResp.getReasons());

            try
            {
                GetCRL.getInstance(new DERSequence(new ASN1Encodable[0]));
                fail("Must not accept sequence less than 1");
            }
            catch (Throwable t)
            {
                isEquals("", t.getClass(), IllegalArgumentException.class);
            }

            try
            {
                GetCRL.getInstance(new DERSequence(new ASN1Encodable[5]));
                fail("Must not accept sequence larger than 5");
            }
            catch (Throwable t)
            {
                isEquals("", t.getClass(), IllegalArgumentException.class);
            }
        }

        { // Permutate on options test all possible combinations.

            X500NameBuilder builder = new X500NameBuilder(BCStyle.INSTANCE);
            builder.addRDN(BCStyle.C, "AU");
            X500Name name = new X500Name(builder.build().toString());
            GeneralName generalName = null;
            ASN1GeneralizedTime generalizedTime = null;
            ReasonFlags flags = null;

            for (int t = 0; t < 8; t++)
            {
                if ((t & 1) == 1)
                {
                    generalName = new GeneralName(GeneralName.rfc822Name, "/");
                }
                if ((t & 2) == 2)
                {
                    generalizedTime = new ASN1GeneralizedTime(new Date());
                }

                if ((t & 4) == 4)
                {
                    flags = new ReasonFlags(ReasonFlags.affiliationChanged);
                }


                GetCRL crl = new GetCRL(
                    name,
                    generalName,
                    generalizedTime,
                    flags
                );

                byte[] b = crl.getEncoded();

                GetCRL crlResp = GetCRL.getInstance(b);

                isEquals("IssuerName", crl.getIssuerName(), crlResp.getIssuerName());
                isEquals("cRLName", crl.getcRLName(), crlResp.getcRLName());
                isEquals("time", crl.getTime(), crlResp.getTime());
                isEquals("reasons", crl.getReasons(), crlResp.getReasons());

            }
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy