001package org.apache.commons.ssl.org.bouncycastle.asn1.x509;
002
003import java.math.BigInteger;
004import java.util.Hashtable;
005
006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Enumerated;
007import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object;
008import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive;
009import org.bouncycastle.util.Integers;
010
011/**
012 * The CRLReason enumeration.
013 * <pre>
014 * CRLReason ::= ENUMERATED {
015 *  unspecified             (0),
016 *  keyCompromise           (1),
017 *  cACompromise            (2),
018 *  affiliationChanged      (3),
019 *  superseded              (4),
020 *  cessationOfOperation    (5),
021 *  certificateHold         (6),
022 *  removeFromCRL           (8),
023 *  privilegeWithdrawn      (9),
024 *  aACompromise           (10)
025 * }
026 * </pre>
027 */
028public class CRLReason
029    extends ASN1Object
030{
031    /**
032     * @deprecated use lower case version
033     */
034    public static final int UNSPECIFIED = 0;
035    /**
036     * @deprecated use lower case version
037     */
038    public static final int KEY_COMPROMISE = 1;
039    /**
040     * @deprecated use lower case version
041     */
042    public static final int CA_COMPROMISE = 2;
043    /**
044     * @deprecated use lower case version
045     */
046    public static final int AFFILIATION_CHANGED = 3;
047    /**
048     * @deprecated use lower case version
049     */
050    public static final int SUPERSEDED = 4;
051    /**
052     * @deprecated use lower case version
053     */
054    public static final int CESSATION_OF_OPERATION  = 5;
055    /**
056     * @deprecated use lower case version
057     */
058    public static final int CERTIFICATE_HOLD = 6;
059    /**
060     * @deprecated use lower case version
061     */
062    public static final int REMOVE_FROM_CRL = 8;
063    /**
064     * @deprecated use lower case version
065     */
066    public static final int PRIVILEGE_WITHDRAWN = 9;
067    /**
068     * @deprecated use lower case version
069     */
070    public static final int AA_COMPROMISE = 10;
071
072    public static final int unspecified = 0;
073    public static final int keyCompromise = 1;
074    public static final int cACompromise = 2;
075    public static final int affiliationChanged = 3;
076    public static final int superseded = 4;
077    public static final int cessationOfOperation  = 5;
078    public static final int certificateHold = 6;
079    // 7 -> unknown
080    public static final int removeFromCRL = 8;
081    public static final int privilegeWithdrawn = 9;
082    public static final int aACompromise = 10;
083
084    private static final String[] reasonString =
085    {
086        "unspecified", "keyCompromise", "cACompromise", "affiliationChanged",
087        "superseded", "cessationOfOperation", "certificateHold", "unknown",
088        "removeFromCRL", "privilegeWithdrawn", "aACompromise"
089    };
090
091    private static final Hashtable table = new Hashtable();
092
093    private ASN1Enumerated value;
094
095    public static CRLReason getInstance(Object o)
096    {
097        if (o instanceof CRLReason)
098        {
099            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}