1 /**
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one or more
4 * contributor license agreements. See the NOTICE file distributed with
5 * this work for additional information regarding copyright ownership.
6 * The ASF licenses this file to You under the Apache License, Version 2.0
7 * (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package org.apache.geronimo.util.asn1.x509;
20
21 import org.apache.geronimo.util.asn1.ASN1Encodable;
22 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
23 import org.apache.geronimo.util.asn1.ASN1Sequence;
24 import org.apache.geronimo.util.asn1.ASN1TaggedObject;
25 import org.apache.geronimo.util.asn1.DERObject;
26 import org.apache.geronimo.util.asn1.DERSequence;
27 import org.apache.geronimo.util.asn1.DERTaggedObject;
28
29 /**
30 * The Holder object.
31 * <pre>
32 * Holder ::= SEQUENCE {
33 * baseCertificateID [0] IssuerSerial OPTIONAL,
34 * -- the issuer and serial number of
35 * -- the holder's Public Key Certificate
36 * entityName [1] GeneralNames OPTIONAL,
37 * -- the name of the claimant or role
38 * objectDigestInfo [2] ObjectDigestInfo OPTIONAL
39 * -- used to directly authenticate the holder,
40 * -- for example, an executable
41 * }
42 * </pre>
43 */
44 public class Holder
45 extends ASN1Encodable
46 {
47 IssuerSerial baseCertificateID;
48 GeneralNames entityName;
49 ObjectDigestInfo objectDigestInfo;
50
51 public static Holder getInstance(
52 Object obj)
53 {
54 if (obj instanceof Holder)
55 {
56 return (Holder)obj;
57 }
58 else if (obj instanceof ASN1Sequence)
59 {
60 return new Holder((ASN1Sequence)obj);
61 }
62
63 throw new IllegalArgumentException("unknown object in factory");
64 }
65
66 public Holder(
67 ASN1Sequence seq)
68 {
69 for (int i = 0; i != seq.size(); i++)
70 {
71 ASN1TaggedObject tObj = (ASN1TaggedObject)seq.getObjectAt(i);
72
73 switch (tObj.getTagNo())
74 {
75 case 0:
76 baseCertificateID = IssuerSerial.getInstance(tObj, false);
77 break;
78 case 1:
79 entityName = GeneralNames.getInstance(tObj, false);
80 break;
81 case 2:
82 objectDigestInfo = ObjectDigestInfo.getInstance(tObj, false);
83 break;
84 default:
85 throw new IllegalArgumentException("unknown tag in Holder");
86 }
87 }
88 }
89
90 public Holder(
91 IssuerSerial baseCertificateID)
92 {
93 this.baseCertificateID = baseCertificateID;
94 }
95
96 public Holder(
97 GeneralNames entityName)
98 {
99 this.entityName = entityName;
100 }
101
102 public IssuerSerial getBaseCertificateID()
103 {
104 return baseCertificateID;
105 }
106
107 public GeneralNames getEntityName()
108 {
109 return entityName;
110 }
111
112 public ObjectDigestInfo getObjectDigestInfo()
113 {
114 return objectDigestInfo;
115 }
116
117 public DERObject toASN1Object()
118 {
119 ASN1EncodableVector v = new ASN1EncodableVector();
120
121 if (baseCertificateID != null)
122 {
123 v.add(new DERTaggedObject(false, 0, baseCertificateID));
124 }
125
126 if (entityName != null)
127 {
128 v.add(new DERTaggedObject(false, 1, entityName));
129 }
130
131 if (objectDigestInfo != null)
132 {
133 v.add(new DERTaggedObject(false, 2, objectDigestInfo));
134 }
135
136 return new DERSequence(v);
137 }
138 }