KeyPurposeId.java revision e1142c149e244797ce73b0e7fad40816e447a817
1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpackage org.bouncycastle.asn1.x509;
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport org.bouncycastle.asn1.ASN1Object;
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport org.bouncycastle.asn1.ASN1ObjectIdentifier;
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport org.bouncycastle.asn1.ASN1Primitive;
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The KeyPurposeId object.
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * <pre>
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *     KeyPurposeId ::= OBJECT IDENTIFIER
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *     id-kp ::= OBJECT IDENTIFIER { iso(1) identified-organization(3)
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *          dod(6) internet(1) security(5) mechanisms(5) pkix(7) 3}
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * </pre>
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic class KeyPurposeId
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    extends ASN1Object
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    private static final ASN1ObjectIdentifier id_kp = new ASN1ObjectIdentifier("1.3.6.1.5.5.7.3");
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * { 2 5 29 37 0 }
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    public static final KeyPurposeId anyExtendedKeyUsage = new KeyPurposeId(Extension.extendedKeyUsage.branch("0"));
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /**
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * { id-kp 1 }
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
30    public static final KeyPurposeId id_kp_serverAuth = new KeyPurposeId(id_kp.branch("1"));
31    /**
32     * { id-kp 2 }
33     */
34    public static final KeyPurposeId id_kp_clientAuth = new KeyPurposeId(id_kp.branch("2"));
35    /**
36     * { id-kp 3 }
37     */
38    public static final KeyPurposeId id_kp_codeSigning = new KeyPurposeId(id_kp.branch("3"));
39    /**
40     * { id-kp 4 }
41     */
42    public static final KeyPurposeId id_kp_emailProtection = new KeyPurposeId(id_kp.branch("4"));
43    /**
44     * Usage deprecated by RFC4945 - was { id-kp 5 }
45     */
46    public static final KeyPurposeId id_kp_ipsecEndSystem = new KeyPurposeId(id_kp.branch("5"));
47    /**
48     * Usage deprecated by RFC4945 - was { id-kp 6 }
49     */
50    public static final KeyPurposeId id_kp_ipsecTunnel = new KeyPurposeId(id_kp.branch("6"));
51    /**
52     * Usage deprecated by RFC4945 - was { idkp 7 }
53     */
54    public static final KeyPurposeId id_kp_ipsecUser = new KeyPurposeId(id_kp.branch("7"));
55    /**
56     * { id-kp 8 }
57     */
58    public static final KeyPurposeId id_kp_timeStamping = new KeyPurposeId(id_kp.branch("8"));
59    /**
60     * { id-kp 9 }
61     */
62    public static final KeyPurposeId id_kp_OCSPSigning = new KeyPurposeId(id_kp.branch("9"));
63    /**
64     * { id-kp 10 }
65     */
66    public static final KeyPurposeId id_kp_dvcs = new KeyPurposeId(id_kp.branch("10"));
67    /**
68     * { id-kp 11 }
69     */
70    public static final KeyPurposeId id_kp_sbgpCertAAServerAuth = new KeyPurposeId(id_kp.branch("11"));
71    /**
72     * { id-kp 12 }
73     */
74    public static final KeyPurposeId id_kp_scvp_responder = new KeyPurposeId(id_kp.branch("12"));
75    /**
76     * { id-kp 13 }
77     */
78    public static final KeyPurposeId id_kp_eapOverPPP = new KeyPurposeId(id_kp.branch("13"));
79    /**
80     * { id-kp 14 }
81     */
82    public static final KeyPurposeId id_kp_eapOverLAN = new KeyPurposeId(id_kp.branch("14"));
83    /**
84     * { id-kp 15 }
85     */
86    public static final KeyPurposeId id_kp_scvpServer = new KeyPurposeId(id_kp.branch("15"));
87    /**
88     * { id-kp 16 }
89     */
90    public static final KeyPurposeId id_kp_scvpClient = new KeyPurposeId(id_kp.branch("16"));
91    /**
92     * { id-kp 17 }
93     */
94    public static final KeyPurposeId id_kp_ipsecIKE = new KeyPurposeId(id_kp.branch("17"));
95    /**
96     * { id-kp 18 }
97     */
98    public static final KeyPurposeId id_kp_capwapAC = new KeyPurposeId(id_kp.branch("18"));
99    /**
100     * { id-kp 19 }
101     */
102    public static final KeyPurposeId id_kp_capwapWTP = new KeyPurposeId(id_kp.branch("19"));
103
104    //
105    // microsoft key purpose ids
106    //
107    /**
108     * { 1 3 6 1 4 1 311 20 2 2 }
109     */
110    public static final KeyPurposeId id_kp_smartcardlogon = new KeyPurposeId(new ASN1ObjectIdentifier("1.3.6.1.4.1.311.20.2.2"));
111
112    private ASN1ObjectIdentifier id;
113
114    private KeyPurposeId(ASN1ObjectIdentifier id)
115    {
116        this.id = id;
117    }
118
119    /**
120     * @deprecated use getInstance and an OID or one of the constants above.
121     * @param id string representation of an OID.
122     */
123    public KeyPurposeId(String id)
124    {
125        this(new ASN1ObjectIdentifier(id));
126    }
127
128    public static KeyPurposeId getInstance(Object o)
129    {
130        if (o instanceof KeyPurposeId)
131        {
132            return (KeyPurposeId)o;
133        }
134        else if (o != null)
135        {
136            return new KeyPurposeId(ASN1ObjectIdentifier.getInstance(o));
137        }
138
139        return null;
140    }
141
142    public ASN1Primitive toASN1Primitive()
143    {
144        return id;
145    }
146
147    public String getId()
148    {
149        return id.getId();
150    }
151}
152