package org.bouncycastle.asn1.cmp;

import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.DERObject;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.ASN1TaggedObject;
import org.bouncycastle.asn1.DERTaggedObject;

public class CertRepMessage
    extends ASN1Encodable
{
    private ASN1Sequence caPubs;
    private ASN1Sequence response;

    private CertRepMessage(ASN1Sequence seq)
    {
        int index = 0;

        if (seq.size() > 1)
        {
            caPubs = ASN1Sequence.getInstance((ASN1TaggedObject)seq.getObjectAt(index++), true);
        }

        response = ASN1Sequence.getInstance(seq.getObjectAt(index));
    }

    public static CertRepMessage getInstance(Object o)
    {
        if (o instanceof CertRepMessage)
        {
            return (CertRepMessage)o;
        }

        if (o instanceof ASN1Sequence)
        {
            return new CertRepMessage((ASN1Sequence)o);
        }

        throw new IllegalArgumentException("Invalid object: " + o.getClass().getName());
    }

    public CMPCertificate[] getCaPubs()
    {
        if (caPubs == null)
        {
            return null;
        }

        CMPCertificate[] results = new CMPCertificate[caPubs.size()];

        for (int i = 0; i != results.length; i++)
        {
            results[i] = CMPCertificate.getInstance(caPubs.getObjectAt(i));
        }

        return results;
    }

    public CertResponse[] getResponse()
    {
        CertResponse[] results = new CertResponse[response.size()];

        for (int i = 0; i != results.length; i++)
        {
            results[i] = CertResponse.getInstance(response.getObjectAt(i));
        }

        return results;
    }

    /**
     * <pre>
     * CertRepMessage ::= SEQUENCE {
     *                          caPubs       [1] SEQUENCE SIZE (1..MAX) OF CMPCertificate
     *                                                                             OPTIONAL,
     *                          response         SEQUENCE OF CertResponse
     * }
     * </pre>
     * @return a basic ASN.1 object representation.
     */
    public DERObject toASN1Object()
    {
        ASN1EncodableVector v = new ASN1EncodableVector();

        if (caPubs != null)
        {
            v.add(new DERTaggedObject(true, 1, caPubs));
        }

        v.add(response);

        return new DERSequence(v);
    }
}

@@ -158,32 +158,79 @@
 1.ASN1Sequence;%0A
+import org.bouncycastle.asn1.ASN1TaggedObject;%0A
 import org.bounc
@@ -299,55 +299,8 @@
 ce;%0A
-import org.bouncycastle.asn1.ASN1TaggedObject;%0A
 impo
@@ -1129,32 +1129,770 @@
 Name());%0A    %7D%0A%0A
+    public CertRepMessage(CMPCertificate%5B%5D caPubs, CertResponse%5B%5D response)%0A    %7B%0A        if (response == null)%0A        %7B%0A            throw new IllegalArgumentException(%22'response' cannot be null%22);%0A        %7D%0A%0A        if (caPubs != null)%0A        %7B%0A            ASN1EncodableVector v = new ASN1EncodableVector();%0A            for (int i = 0; i %3C caPubs.length; i++)%0A            %7B%0A                v.add(caPubs%5Bi%5D);%0A            %7D%0A            this.caPubs = new DERSequence(v);%0A        %7D%0A%0A        %7B%0A            ASN1EncodableVector v = new ASN1EncodableVector();%0A            for (int i = 0; i %3C response.length; i++)%0A            %7B%0A                v.add(response%5Bi%5D);%0A            %7D%0A            this.response = new DERSequence(v);%0A        %7D%0A    %7D%0A%0A
     public CMPCe

Add missing constructors