Home | History | Annotate | Download | only in ocsp
      1 package org.bouncycastle.asn1.ocsp;
      2 
      3 import java.util.Enumeration;
      4 
      5 import org.bouncycastle.asn1.ASN1EncodableVector;
      6 import org.bouncycastle.asn1.ASN1GeneralizedTime;
      7 import org.bouncycastle.asn1.ASN1Integer;
      8 import org.bouncycastle.asn1.ASN1Object;
      9 import org.bouncycastle.asn1.ASN1Primitive;
     10 import org.bouncycastle.asn1.ASN1Sequence;
     11 import org.bouncycastle.asn1.ASN1TaggedObject;
     12 import org.bouncycastle.asn1.DERIA5String;
     13 import org.bouncycastle.asn1.DERSequence;
     14 import org.bouncycastle.asn1.DERTaggedObject;
     15 
     16 public class CrlID
     17     extends ASN1Object
     18 {
     19     private DERIA5String         crlUrl;
     20     private ASN1Integer          crlNum;
     21     private ASN1GeneralizedTime  crlTime;
     22 
     23     private CrlID(
     24         ASN1Sequence    seq)
     25     {
     26         Enumeration    e = seq.getObjects();
     27 
     28         while (e.hasMoreElements())
     29         {
     30             ASN1TaggedObject    o = (ASN1TaggedObject)e.nextElement();
     31 
     32             switch (o.getTagNo())
     33             {
     34             case 0:
     35                 crlUrl = DERIA5String.getInstance(o, true);
     36                 break;
     37             case 1:
     38                 crlNum = ASN1Integer.getInstance(o, true);
     39                 break;
     40             case 2:
     41                 crlTime = ASN1GeneralizedTime.getInstance(o, true);
     42                 break;
     43             default:
     44                 throw new IllegalArgumentException(
     45                         "unknown tag number: " + o.getTagNo());
     46             }
     47         }
     48     }
     49 
     50     public static CrlID getInstance(
     51         Object  obj)
     52     {
     53         if (obj instanceof CrlID)
     54         {
     55             return (CrlID)obj;
     56         }
     57         else if (obj != null)
     58         {
     59             return new CrlID(ASN1Sequence.getInstance(obj));
     60         }
     61 
     62         return null;
     63     }
     64 
     65     public DERIA5String getCrlUrl()
     66     {
     67         return crlUrl;
     68     }
     69 
     70     public ASN1Integer getCrlNum()
     71     {
     72         return crlNum;
     73     }
     74 
     75     public ASN1GeneralizedTime getCrlTime()
     76     {
     77         return crlTime;
     78     }
     79 
     80     /**
     81      * Produce an object suitable for an ASN1OutputStream.
     82      * <pre>
     83      * CrlID ::= SEQUENCE {
     84      *     crlUrl               [0]     EXPLICIT IA5String OPTIONAL,
     85      *     crlNum               [1]     EXPLICIT INTEGER OPTIONAL,
     86      *     crlTime              [2]     EXPLICIT GeneralizedTime OPTIONAL }
     87      * </pre>
     88      */
     89     public ASN1Primitive toASN1Primitive()
     90     {
     91         ASN1EncodableVector    v = new ASN1EncodableVector();
     92 
     93         if (crlUrl != null)
     94         {
     95             v.add(new DERTaggedObject(true, 0, crlUrl));
     96         }
     97 
     98         if (crlNum != null)
     99         {
    100             v.add(new DERTaggedObject(true, 1, crlNum));
    101         }
    102 
    103         if (crlTime != null)
    104         {
    105             v.add(new DERTaggedObject(true, 2, crlTime));
    106         }
    107 
    108         return new DERSequence(v);
    109     }
    110 }
    111