001package org.apache.commons.ssl.org.bouncycastle.asn1.cmp;
002
003import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1EncodableVector;
004import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Integer;
005import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object;
006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive;
007import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Sequence;
008import org.apache.commons.ssl.org.bouncycastle.asn1.DERSequence;
009
010public class PollRepContent
011    extends ASN1Object
012{
013    private ASN1Integer[] certReqId;
014    private ASN1Integer[] checkAfter;
015    private PKIFreeText[] reason;
016
017    private PollRepContent(ASN1Sequence seq)
018    {
019        certReqId = new ASN1Integer[seq.size()];
020        checkAfter = new ASN1Integer[seq.size()];
021        reason = new PKIFreeText[seq.size()];
022
023        for (int i = 0; i != seq.size(); i++)
024        {
025            ASN1Sequence s = ASN1Sequence.getInstance(seq.getObjectAt(i));
026
027            certReqId[i] = ASN1Integer.getInstance(s.getObjectAt(0));
028            checkAfter[i] = ASN1Integer.getInstance(s.getObjectAt(1));
029
030            if (s.size() > 2)
031            {
032                reason[i] = PKIFreeText.getInstance(s.getObjectAt(2));
033            }
034        }
035    }
036
037    public static PollRepContent getInstance(Object o)
038    {
039        if (o instanceof PollRepContent)
040        {
041            return (PollRepContent)o;
042        }
043
044        if (o != null)
045        {
046            return new PollRepContent(ASN1Sequence.getInstance(o));
047        }
048
049        return null;
050    }
051
052    public PollRepContent(ASN1Integer certReqId, ASN1Integer checkAfter)
053    {
054        this(certReqId, checkAfter, null);
055    }
056
057    public PollRepContent(ASN1Integer certReqId, ASN1Integer checkAfter, PKIFreeText reason)
058    {
059        this.certReqId = new ASN1Integer[1];
060        this.checkAfter = new ASN1Integer[1];
061        this.reason = new PKIFreeText[1];
062
063        this.certReqId[0] = certReqId;
064        this.checkAfter[0] = checkAfter;
065        this.reason[0] = reason;
066    }
067
068    public int size()
069    {
070        return certReqId.length;
071    }
072
073    public ASN1Integer getCertReqId(int index)
074    {
075        return certReqId[index];
076    }
077
078    public ASN1Integer getCheckAfter(int index)
079    {
080        return checkAfter[index];
081    }
082
083    public PKIFreeText getReason(int index)
084    {
085        return reason[index];
086    }
087
088    /**
089     * <pre>
090     * PollRepContent ::= SEQUENCE OF SEQUENCE {
091     *         certReqId              INTEGER,
092     *         checkAfter             INTEGER,  -- time in seconds
093     *         reason                 PKIFreeText OPTIONAL
094     *     }
095     * </pre>
096     * @return a basic ASN.1 object representation.
097     */
098    public ASN1Primitive toASN1Primitive()
099    {
100        ASN1EncodableVector outer = new ASN1EncodableVector();
101
102        for (int i = 0; i != certReqId.length; i++)
103        {
104            ASN1EncodableVector v = new ASN1EncodableVector();
105
106            v.add(certReqId[i]);
107            v.add(checkAfter[i]);
108
109            if (reason[i] != null)
110            {
111                v.add(reason[i]);
112            }
113
114            outer.add(new DERSequence(v));
115        }
116        
117        return new DERSequence(outer);
118    }
119}