Home | History | Annotate | Download | only in x509
      1 package org.bouncycastle.asn1.x509;
      2 
      3 import java.math.BigInteger;
      4 import java.util.Hashtable;
      5 
      6 import org.bouncycastle.asn1.ASN1Enumerated;
      7 import org.bouncycastle.asn1.ASN1Object;
      8 import org.bouncycastle.asn1.ASN1Primitive;
      9 import org.bouncycastle.util.Integers;
     10 
     11 /**
     12  * The CRLReason enumeration.
     13  * <pre>
     14  * CRLReason ::= ENUMERATED {
     15  *  unspecified             (0),
     16  *  keyCompromise           (1),
     17  *  cACompromise            (2),
     18  *  affiliationChanged      (3),
     19  *  superseded              (4),
     20  *  cessationOfOperation    (5),
     21  *  certificateHold         (6),
     22  *  removeFromCRL           (8),
     23  *  privilegeWithdrawn      (9),
     24  *  aACompromise           (10)
     25  * }
     26  * </pre>
     27  */
     28 public class CRLReason
     29     extends ASN1Object
     30 {
     31     /**
     32      * @deprecated use lower case version
     33      */
     34     public static final int UNSPECIFIED = 0;
     35     /**
     36      * @deprecated use lower case version
     37      */
     38     public static final int KEY_COMPROMISE = 1;
     39     /**
     40      * @deprecated use lower case version
     41      */
     42     public static final int CA_COMPROMISE = 2;
     43     /**
     44      * @deprecated use lower case version
     45      */
     46     public static final int AFFILIATION_CHANGED = 3;
     47     /**
     48      * @deprecated use lower case version
     49      */
     50     public static final int SUPERSEDED = 4;
     51     /**
     52      * @deprecated use lower case version
     53      */
     54     public static final int CESSATION_OF_OPERATION  = 5;
     55     /**
     56      * @deprecated use lower case version
     57      */
     58     public static final int CERTIFICATE_HOLD = 6;
     59     /**
     60      * @deprecated use lower case version
     61      */
     62     public static final int REMOVE_FROM_CRL = 8;
     63     /**
     64      * @deprecated use lower case version
     65      */
     66     public static final int PRIVILEGE_WITHDRAWN = 9;
     67     /**
     68      * @deprecated use lower case version
     69      */
     70     public static final int AA_COMPROMISE = 10;
     71 
     72     public static final int unspecified = 0;
     73     public static final int keyCompromise = 1;
     74     public static final int cACompromise = 2;
     75     public static final int affiliationChanged = 3;
     76     public static final int superseded = 4;
     77     public static final int cessationOfOperation  = 5;
     78     public static final int certificateHold = 6;
     79     // 7 -> unknown
     80     public static final int removeFromCRL = 8;
     81     public static final int privilegeWithdrawn = 9;
     82     public static final int aACompromise = 10;
     83 
     84     private static final String[] reasonString =
     85     {
     86         "unspecified", "keyCompromise", "cACompromise", "affiliationChanged",
     87         "superseded", "cessationOfOperation", "certificateHold", "unknown",
     88         "removeFromCRL", "privilegeWithdrawn", "aACompromise"
     89     };
     90 
     91     private static final Hashtable table = new Hashtable();
     92 
     93     private ASN1Enumerated value;
     94 
     95     public static CRLReason getInstance(Object o)
     96     {
     97         if (o instanceof CRLReason)
     98         {
     99             return (CRLReason)o;
    100         }
    101         else if (o != null)
    102         {
    103             return lookup(ASN1Enumerated.getInstance(o).getValue().intValue());
    104         }
    105 
    106         return null;
    107     }
    108 
    109     private CRLReason(
    110         int reason)
    111     {
    112         value = new ASN1Enumerated(reason);
    113     }
    114 
    115     public String toString()
    116     {
    117         String str;
    118         int reason = getValue().intValue();
    119         if (reason < 0 || reason > 10)
    120         {
    121             str = "invalid";
    122         }
    123         else
    124         {
    125             str = reasonString[reason];
    126         }
    127         return "CRLReason: " + str;
    128     }
    129 
    130     public BigInteger getValue()
    131     {
    132         return value.getValue();
    133     }
    134 
    135     public ASN1Primitive toASN1Primitive()
    136     {
    137         return value;
    138     }
    139 
    140     public static CRLReason lookup(int value)
    141     {
    142         Integer idx = Integers.valueOf(value);
    143 
    144         if (!table.containsKey(idx))
    145         {
    146             table.put(idx, new CRLReason(value));
    147         }
    148 
    149         return (CRLReason)table.get(idx);
    150     }
    151 }
    152