KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.geronimo.util.asn1.ASN1Encodable;
21 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
22 import org.apache.geronimo.util.asn1.ASN1Sequence;
23 import org.apache.geronimo.util.asn1.ASN1TaggedObject;
24 import org.apache.geronimo.util.asn1.DERObject;
25 import org.apache.geronimo.util.asn1.DERSequence;
26 import org.apache.geronimo.util.asn1.DERTaggedObject;
27
28 public class V2Form
29     extends ASN1Encodable
30 {
31     GeneralNames issuerName;
32     IssuerSerial baseCertificateID;
33     ObjectDigestInfo objectDigestInfo;
34
35     public static V2Form getInstance(
36         ASN1TaggedObject obj,
37         boolean explicit)
38     {
39         return getInstance(ASN1Sequence.getInstance(obj, explicit));
40     }
41
42     public static V2Form getInstance(
43         Object JavaDoc obj)
44     {
45         if (obj == null || obj instanceof V2Form)
46         {
47             return (V2Form)obj;
48         }
49         else if (obj instanceof ASN1Sequence)
50         {
51             return new V2Form((ASN1Sequence)obj);
52         }
53
54         throw new IllegalArgumentException JavaDoc("unknown object in factory");
55     }
56
57     public V2Form(
58         GeneralNames issuerName)
59     {
60         this.issuerName = issuerName;
61     }
62
63     public V2Form(
64         ASN1Sequence seq)
65     {
66         int index = 0;
67
68         if (!(seq.getObjectAt(0) instanceof ASN1TaggedObject))
69         {
70             index++;
71             this.issuerName = GeneralNames.getInstance(seq.getObjectAt(0));
72         }
73
74         for (int i = index; i != seq.size(); i++)
75         {
76             ASN1TaggedObject o = (ASN1TaggedObject)seq.getObjectAt(i);
77             if (o.getTagNo() == 0)
78             {
79                 baseCertificateID = IssuerSerial.getInstance(o, false);
80             }
81             else if (o.getTagNo() == 1)
82             {
83                 objectDigestInfo = ObjectDigestInfo.getInstance(o, false);
84             }
85         }
86     }
87
88     public GeneralNames getIssuerName()
89     {
90         return issuerName;
91     }
92
93     public IssuerSerial getBaseCertificateID()
94     {
95         return baseCertificateID;
96     }
97
98     public ObjectDigestInfo getObjectDigestInfo()
99     {
100         return objectDigestInfo;
101     }
102
103     /**
104      * Produce an object suitable for an ASN1OutputStream.
105      * <pre>
106      * V2Form ::= SEQUENCE {
107      * issuerName GeneralNames OPTIONAL,
108      * baseCertificateID [0] IssuerSerial OPTIONAL,
109      * objectDigestInfo [1] ObjectDigestInfo OPTIONAL
110      * -- issuerName MUST be present in this profile
111      * -- baseCertificateID and objectDigestInfo MUST NOT
112      * -- be present in this profile
113      * }
114      * </pre>
115      */

116     public DERObject toASN1Object()
117     {
118         ASN1EncodableVector v = new ASN1EncodableVector();
119
120         if (issuerName != null)
121         {
122             v.add(issuerName);
123         }
124
125         if (baseCertificateID != null)
126         {
127             v.add(new DERTaggedObject(false, 0, baseCertificateID));
128         }
129
130         if (objectDigestInfo != null)
131         {
132             v.add(new DERTaggedObject(false, 1, objectDigestInfo));
133         }
134
135         return new DERSequence(v);
136     }
137 }
138
Popular Tags