KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > util > asn1 > x509 > ExtendedKeyUsage


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.util.asn1.x509;
19
20 import java.util.Enumeration JavaDoc;
21 import java.util.Hashtable JavaDoc;
22 import java.util.Vector JavaDoc;
23
24 import org.apache.geronimo.util.asn1.ASN1Encodable;
25 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
26 import org.apache.geronimo.util.asn1.ASN1Sequence;
27 import org.apache.geronimo.util.asn1.ASN1TaggedObject;
28 import org.apache.geronimo.util.asn1.DERObject;
29 import org.apache.geronimo.util.asn1.DERSequence;
30
31 /**
32  * The extendedKeyUsage object.
33  * <pre>
34  * extendedKeyUsage ::= SEQUENCE SIZE (1..MAX) OF KeyPurposeId
35  * </pre>
36  */

37 public class ExtendedKeyUsage
38     extends ASN1Encodable
39 {
40     Hashtable JavaDoc usageTable = new Hashtable JavaDoc();
41     ASN1Sequence seq;
42
43     public static ExtendedKeyUsage getInstance(
44         ASN1TaggedObject obj,
45         boolean explicit)
46     {
47         return getInstance(ASN1Sequence.getInstance(obj, explicit));
48     }
49
50     public static ExtendedKeyUsage getInstance(
51         Object JavaDoc obj)
52     {
53         if(obj == null || obj instanceof ExtendedKeyUsage)
54         {
55             return (ExtendedKeyUsage)obj;
56         }
57
58         if(obj instanceof ASN1Sequence)
59         {
60             return new ExtendedKeyUsage((ASN1Sequence)obj);
61         }
62
63         throw new IllegalArgumentException JavaDoc("Invalid ExtendedKeyUsage: " + obj.getClass().getName());
64     }
65
66     public ExtendedKeyUsage(
67         KeyPurposeId usage)
68     {
69         this.seq = new DERSequence(usage);
70
71         this.usageTable.put(usage, usage);
72     }
73
74     public ExtendedKeyUsage(
75         ASN1Sequence seq)
76     {
77         this.seq = seq;
78
79         Enumeration JavaDoc e = seq.getObjects();
80
81         while (e.hasMoreElements())
82         {
83             Object JavaDoc o = e.nextElement();
84
85             this.usageTable.put(o, o);
86         }
87     }
88
89     public ExtendedKeyUsage(
90         Vector JavaDoc usages)
91     {
92         ASN1EncodableVector v = new ASN1EncodableVector();
93         Enumeration JavaDoc e = usages.elements();
94
95         while (e.hasMoreElements())
96         {
97             DERObject o = (DERObject)e.nextElement();
98
99             v.add(o);
100             this.usageTable.put(o, o);
101         }
102
103         this.seq = new DERSequence(v);
104     }
105
106     public boolean hasKeyPurposeId(
107         KeyPurposeId keyPurposeId)
108     {
109         return (usageTable.get(keyPurposeId) != null);
110     }
111
112     public int size()
113     {
114         return usageTable.size();
115     }
116
117     public DERObject toASN1Object()
118     {
119         return seq;
120     }
121 }
122
Popular Tags