KickJava   Java API By Example, From Geeks To Geeks.

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


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.Vector JavaDoc;
22
23 import org.apache.geronimo.util.asn1.ASN1Encodable;
24 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
25 import org.apache.geronimo.util.asn1.ASN1Sequence;
26 import org.apache.geronimo.util.asn1.ASN1TaggedObject;
27 import org.apache.geronimo.util.asn1.DERObject;
28 import org.apache.geronimo.util.asn1.DERObjectIdentifier;
29 import org.apache.geronimo.util.asn1.DERSequence;
30
31 public class CertificatePolicies
32     extends ASN1Encodable
33 {
34     static final DERObjectIdentifier anyPolicy = new DERObjectIdentifier("2.5.29.32.0");
35
36     Vector JavaDoc policies = new Vector JavaDoc();
37
38 /**
39  * @deprecated use an ASN1Sequence of PolicyInformation
40  */

41     public static CertificatePolicies getInstance(
42         ASN1TaggedObject obj,
43         boolean explicit)
44     {
45         return getInstance(ASN1Sequence.getInstance(obj, explicit));
46     }
47
48 /**
49  * @deprecated use an ASN1Sequence of PolicyInformation
50  */

51     public static CertificatePolicies getInstance(
52         Object JavaDoc obj)
53     {
54         if (obj instanceof CertificatePolicies)
55         {
56             return (CertificatePolicies)obj;
57         }
58         else if (obj instanceof ASN1Sequence)
59         {
60             return new CertificatePolicies((ASN1Sequence)obj);
61         }
62
63         throw new IllegalArgumentException JavaDoc("unknown object in factory");
64     }
65
66 /**
67  * @deprecated use an ASN1Sequence of PolicyInformation
68  */

69     public CertificatePolicies(
70         ASN1Sequence seq)
71     {
72         Enumeration JavaDoc e = seq.getObjects();
73         while (e.hasMoreElements())
74         {
75             ASN1Sequence s = (ASN1Sequence)e.nextElement();
76             policies.addElement(s.getObjectAt(0));
77         }
78         // For now we just don't handle PolicyQualifiers
79
}
80
81     /**
82      * create a certificate policy with the given OID.
83      * @deprecated use an ASN1Sequence of PolicyInformation
84      */

85     public CertificatePolicies(
86         DERObjectIdentifier p)
87     {
88         policies.addElement(p);
89     }
90
91     /**
92      * create a certificate policy with the policy given by the OID represented
93      * by the string p.
94      * @deprecated use an ASN1Sequence of PolicyInformation
95      */

96     public CertificatePolicies(
97         String JavaDoc p)
98     {
99         this(new DERObjectIdentifier(p));
100     }
101
102     public void addPolicy(
103         String JavaDoc p)
104     {
105         policies.addElement(new DERObjectIdentifier(p));
106     }
107
108     public String JavaDoc getPolicy(int nr)
109     {
110         if (policies.size() > nr)
111             return ((DERObjectIdentifier)policies.elementAt(nr)).getId();
112
113         return null;
114     }
115
116     /**
117      * <pre>
118      * certificatePolicies ::= SEQUENCE SIZE (1..MAX) OF PolicyInformation
119      *
120      * PolicyInformation ::= SEQUENCE {
121      * policyIdentifier CertPolicyId,
122      * policyQualifiers SEQUENCE SIZE (1..MAX) OF
123      * PolicyQualifierInfo OPTIONAL }
124      *
125      * CertPolicyId ::= OBJECT IDENTIFIER
126      *
127      * PolicyQualifierInfo ::= SEQUENCE {
128      * policyQualifierId PolicyQualifierId,
129      * qualifier ANY DEFINED BY policyQualifierId }
130      *
131      * PolicyQualifierId ::=
132      * OBJECT IDENTIFIER ( id-qt-cps | id-qt-unotice )
133      * </pre>
134      * @deprecated use an ASN1Sequence of PolicyInformation
135      */

136     public DERObject toASN1Object()
137     {
138         ASN1EncodableVector v = new ASN1EncodableVector();
139
140         // We only do policyIdentifier yet...
141
for (int i=0;i<policies.size();i++)
142         {
143             v.add(new DERSequence((DERObjectIdentifier)policies.elementAt(i)));
144         }
145
146         return new DERSequence(v);
147     }
148
149     public String JavaDoc toString()
150     {
151         String JavaDoc p = null;
152         for (int i=0;i<policies.size();i++)
153         {
154             if (p != null)
155                 p += ", ";
156             p += ((DERObjectIdentifier)policies.elementAt(i)).getId();
157         }
158         return "CertificatePolicies: "+p;
159     }
160 }
161
Popular Tags