// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.cert.crmf;

import org.bouncycastle.asn1.cmp.CertRepMessage;
import java.util.ArrayList;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.asn1.cmp.CMPCertificate;
import org.bouncycastle.asn1.cmp.CertResponse;
import java.util.List;

public class CertificateRepMessageBuilder
{
    private final List<CertResponse> responses;
    private final CMPCertificate[] caCerts;
    
    public CertificateRepMessageBuilder(final X509CertificateHolder... array) {
        this.responses = new ArrayList<CertResponse>();
        this.caCerts = new CMPCertificate[array.length];
        for (int i = 0; i != array.length; ++i) {
            this.caCerts[i] = new CMPCertificate(array[i].toASN1Structure());
        }
    }
    
    public CertificateRepMessageBuilder addCertificateResponse(final CertificateResponse certificateResponse) {
        this.responses.add(certificateResponse.toASN1Structure());
        return this;
    }
    
    public CertificateRepMessage build() {
        CertRepMessage certRepMessage;
        if (this.caCerts.length != 0) {
            certRepMessage = new CertRepMessage(this.caCerts, this.responses.toArray(new CertResponse[0]));
        }
        else {
            certRepMessage = new CertRepMessage(null, this.responses.toArray(new CertResponse[0]));
        }
        this.responses.clear();
        return new CertificateRepMessage(certRepMessage);
    }
}
