KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
29  * The Holder object.
30  * <pre>
31  * Holder ::= SEQUENCE {
32  * baseCertificateID [0] IssuerSerial OPTIONAL,
33  * -- the issuer and serial number of
34  * -- the holder's Public Key Certificate
35  * entityName [1] GeneralNames OPTIONAL,
36  * -- the name of the claimant or role
37  * objectDigestInfo [2] ObjectDigestInfo OPTIONAL
38  * -- used to directly authenticate the holder,
39  * -- for example, an executable
40  * }
41  * </pre>
42  */

43 public class Holder
44     extends ASN1Encodable
45 {
46     IssuerSerial baseCertificateID;
47     GeneralNames entityName;
48     ObjectDigestInfo objectDigestInfo;
49
50     public static Holder getInstance(
51             Object JavaDoc obj)
52     {
53         if (obj instanceof Holder)
54         {
55             return (Holder)obj;
56         }
57         else if (obj instanceof ASN1Sequence)
58         {
59             return new Holder((ASN1Sequence)obj);
60         }
61
62         throw new IllegalArgumentException JavaDoc("unknown object in factory");
63     }
64
65     public Holder(
66         ASN1Sequence seq)
67     {
68         for (int i = 0; i != seq.size(); i++)
69         {
70             ASN1TaggedObject tObj = (ASN1TaggedObject)seq.getObjectAt(i);
71
72             switch (tObj.getTagNo())
73             {
74             case 0:
75                 baseCertificateID = IssuerSerial.getInstance(tObj, false);
76                 break;
77             case 1:
78                 entityName = GeneralNames.getInstance(tObj, false);
79                 break;
80             case 2:
81                 objectDigestInfo = ObjectDigestInfo.getInstance(tObj, false);
82                 break;
83             default:
84                 throw new IllegalArgumentException JavaDoc("unknown tag in Holder");
85             }
86         }
87     }
88
89     public Holder(
90         IssuerSerial baseCertificateID)
91     {
92         this.baseCertificateID = baseCertificateID;
93     }
94
95     public Holder(
96         GeneralNames entityName)
97     {
98         this.entityName = entityName;
99     }
100
101     public IssuerSerial getBaseCertificateID()
102     {
103         return baseCertificateID;
104     }
105
106     public GeneralNames getEntityName()
107     {
108         return entityName;
109     }
110
111     public ObjectDigestInfo getObjectDigestInfo()
112     {
113         return objectDigestInfo;
114     }
115
116     public DERObject toASN1Object()
117     {
118         ASN1EncodableVector v = new ASN1EncodableVector();
119
120         if (baseCertificateID != null)
121         {
122             v.add(new DERTaggedObject(false, 0, baseCertificateID));
123         }
124
125         if (entityName != null)
126         {
127             v.add(new DERTaggedObject(false, 1, entityName));
128         }
129
130         if (objectDigestInfo != null)
131         {
132             v.add(new DERTaggedObject(false, 2, objectDigestInfo));
133         }
134
135         return new DERSequence(v);
136     }
137 }
138
Popular Tags