001package org.apache.commons.ssl.org.bouncycastle.asn1.cms;
002
003import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1EncodableVector;
004import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object;
005import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive;
006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Sequence;
007import org.apache.commons.ssl.org.bouncycastle.asn1.DERSequence;
008import org.apache.commons.ssl.org.bouncycastle.asn1.x509.CertificateList;
009
010/**
011 * <a href="http://tools.ietf.org/html/rfc5544">RFC 5544</a>
012 * Binding Documents with Time-Stamps; TimeStampAndCRL object.
013 * <pre>
014 * TimeStampAndCRL ::= SEQUENCE {
015 *     timeStamp   TimeStampToken,          -- according to RFC 3161
016 *     crl         CertificateList OPTIONAL -- according to RFC 5280
017 *  }
018 * </pre>
019 */
020public class TimeStampAndCRL
021    extends ASN1Object
022{
023    private ContentInfo timeStamp;
024    private CertificateList crl;
025
026    public TimeStampAndCRL(ContentInfo timeStamp)
027    {
028        this.timeStamp = timeStamp;
029    }
030
031    private TimeStampAndCRL(ASN1Sequence seq)
032    {
033        this.timeStamp = ContentInfo.getInstance(seq.getObjectAt(0));
034        if (seq.size() == 2)
035        {
036            this.crl = CertificateList.getInstance(seq.getObjectAt(1));
037        }
038    }
039
040    /**
041     * Return a TimeStampAndCRL object from the given object.
042     * <p>
043     * Accepted inputs:
044     * <ul>
045     * <li> null &rarr; null
046     * <li> {@link TimeStampAndCRL} object
047     * <li> {@link org.bouncycastle.asn1.ASN1Sequence#getInstance(java.lang.Object) ASN1Sequence} input formats with TimeStampAndCRL structure inside
048     * </ul>
049     *
050     * @param obj the object we want converted.
051     * @exception IllegalArgumentException if the object cannot be converted.
052     */
053    public static TimeStampAndCRL getInstance(Object obj)
054    {
055        if (obj instanceof TimeStampAndCRL)
056        {
057            return (TimeStampAndCRL)obj;
058        }
059        else if (obj != null)
060        {
061            return new TimeStampAndCRL(ASN1Sequence.getInstance(obj));
062        }
063
064        return null;
065    }
066
067    public ContentInfo getTimeStampToken()
068    {
069        return this.timeStamp;
070    }
071
072    /** @deprecated use getCRL() */
073    public CertificateList getCertificateList()
074    {
075        return this.crl;
076    }
077
078    public CertificateList getCRL()
079    {
080        return this.crl;
081    }
082
083    public ASN1Primitive toASN1Primitive()
084    {
085        ASN1EncodableVector v = new ASN1EncodableVector();
086
087        v.add(timeStamp);
088
089        if (crl != null)
090        {
091            v.add(crl);
092        }
093
094        return new DERSequence(v);
095    }
096}