001package org.apache.commons.ssl.org.bouncycastle.asn1.esf;
002
003import java.util.Enumeration;
004
005import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1EncodableVector;
006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object;
007import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive;
008import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Sequence;
009import org.apache.commons.ssl.org.bouncycastle.asn1.DERSequence;
010import org.apache.commons.ssl.org.bouncycastle.asn1.DERTaggedObject;
011
012/**
013 * <pre>
014 * CrlOcspRef ::= SEQUENCE {
015 *     crlids [0] CRLListID OPTIONAL,
016 *     ocspids [1] OcspListID OPTIONAL,
017 *     otherRev [2] OtherRevRefs OPTIONAL
018 * }
019 * </pre>
020 */
021public class CrlOcspRef
022    extends ASN1Object
023{
024
025    private CrlListID crlids;
026    private OcspListID ocspids;
027    private OtherRevRefs otherRev;
028
029    public static CrlOcspRef getInstance(Object obj)
030    {
031        if (obj instanceof CrlOcspRef)
032        {
033            return (CrlOcspRef)obj;
034        }
035        else if (obj != null)
036        {
037            return new CrlOcspRef(ASN1Sequence.getInstance(obj));
038        }
039
040        return null;
041    }
042
043    private CrlOcspRef(ASN1Sequence seq)
044    {
045        Enumeration e = seq.getObjects();
046        while (e.hasMoreElements())
047        {
048            DERTaggedObject o = (DERTaggedObject)e.nextElement();
049            switch (o.getTagNo())
050            {
051                case 0:
052                    this.crlids = CrlListID.getInstance(o.getObject());
053                    break;
054                case 1:
055                    this.ocspids = OcspListID.getInstance(o.getObject());
056                    break;
057                case 2:
058                    this.otherRev = OtherRevRefs.getInstance(o.getObject());
059                    break;
060                default:
061                    throw new IllegalArgumentException("illegal tag");
062            }
063        }
064    }
065
066    public CrlOcspRef(CrlListID crlids, OcspListID ocspids,
067                      OtherRevRefs otherRev)
068    {
069        this.crlids = crlids;
070        this.ocspids = ocspids;
071        this.otherRev = otherRev;
072    }
073
074    public CrlListID getCrlids()
075    {
076        return this.crlids;
077    }
078
079    public OcspListID getOcspids()
080    {
081        return this.ocspids;
082    }
083
084    public OtherRevRefs getOtherRev()
085    {
086        return this.otherRev;
087    }
088
089    public ASN1Primitive toASN1Primitive()
090    {
091        ASN1EncodableVector v = new ASN1EncodableVector();
092        if (null != this.crlids)
093        {
094            v.add(new DERTaggedObject(true, 0, this.crlids.toASN1Primitive()));
095        }
096        if (null != this.ocspids)
097        {
098            v.add(new DERTaggedObject(true, 1, this.ocspids.toASN1Primitive()));
099        }
100        if (null != this.otherRev)
101        {
102            v.add(new DERTaggedObject(true, 2, this.otherRev.toASN1Primitive()));
103        }
104        return new DERSequence(v);
105    }
106}