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.8 and up. The APIs are designed primarily to be used in conjunction with the BC LTS provider but may also be used with other providers providing cryptographic services.

There is a newer version: 2.73.7
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 CertificateRepMessage.
 */
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 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 - 2025 Weber Informatics LLC | Privacy Policy