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

org.bouncycastle.cert.crmf.CertificateRepMessageBuilder Maven / Gradle / Ivy

Go to download

The Bouncy Castle Java APIs for CMS, PKCS, EAC, TSP, CMP, CRMF, OCSP, and certificate generation. This jar contains APIs for JDK 1.4. The APIs can be used in conjunction with a JCE/JCA provider such as the one provided with the Bouncy Castle Cryptography APIs.

There is a newer version: 1.79
Show newest version
package org.bouncycastle.cert.crmf;

import java.util.ArrayList;
import java.util.List;

import org.bouncycastle.asn1.cmp.CMPCertificate;
import org.bouncycastle.asn1.cmp.CertRepMessage;
import org.bouncycastle.asn1.cmp.CertResponse;
import org.bouncycastle.cert.X509CertificateHolder;

/**
 * Builder for a CertRepMessage.
 */
public class CertificateRepMessageBuilder
{
    private final List  responses = new ArrayList ();
    private final CMPCertificate[] caCerts;

    /**
     * Base constructor which can accept 0 or more certificates representing the CA plus its chain.
     *
     * @param caCerts the CA public key and it's support certificates (optional)
     */
    public CertificateRepMessageBuilder(X509CertificateHolder[] caCerts)
    {
        this.caCerts = new CMPCertificate[caCerts.length];

        for (int i = 0; i != caCerts.length; i++)
        {
            this.caCerts[i] = new CMPCertificate(caCerts[i].toASN1Structure());
        }
    }

    public CertificateRepMessageBuilder(X509CertificateHolder caCert)
    {
        this.caCerts = new CMPCertificate[1];
        this.caCerts[0] = new CMPCertificate(caCert.toASN1Structure());
    }

    public CertificateRepMessageBuilder addCertificateResponse(CertificateResponse response)
    {
        responses.add(response.toASN1Structure());

        return this;
    }

    public CertificateRepMessage build()
    {
        CertRepMessage repMessage;
        if (caCerts.length != 0)
        {
            repMessage = new CertRepMessage(caCerts, (CertResponse[])responses.toArray(new CertResponse[0]));
        }
        else
        {
            // older versions of CertRepMessage need null if no caCerts.
            repMessage = new CertRepMessage(null, (CertResponse[])responses.toArray(new CertResponse[0]));
        }

        responses.clear();

        return new CertificateRepMessage(repMessage);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy