001 /**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements. See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package org.apache.geronimo.util.asn1.x509;
020
021 import org.apache.geronimo.util.asn1.ASN1Encodable;
022 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
023 import org.apache.geronimo.util.asn1.ASN1Sequence;
024 import org.apache.geronimo.util.asn1.ASN1TaggedObject;
025 import org.apache.geronimo.util.asn1.DERObject;
026 import org.apache.geronimo.util.asn1.DERSequence;
027 import org.apache.geronimo.util.asn1.DERTaggedObject;
028
029 /**
030 * The Holder object.
031 * <pre>
032 * Holder ::= SEQUENCE {
033 * baseCertificateID [0] IssuerSerial OPTIONAL,
034 * -- the issuer and serial number of
035 * -- the holder's Public Key Certificate
036 * entityName [1] GeneralNames OPTIONAL,
037 * -- the name of the claimant or role
038 * objectDigestInfo [2] ObjectDigestInfo OPTIONAL
039 * -- used to directly authenticate the holder,
040 * -- for example, an executable
041 * }
042 * </pre>
043 */
044 public class Holder
045 extends ASN1Encodable
046 {
047 IssuerSerial baseCertificateID;
048 GeneralNames entityName;
049 ObjectDigestInfo objectDigestInfo;
050
051 public static Holder getInstance(
052 Object obj)
053 {
054 if (obj instanceof Holder)
055 {
056 return (Holder)obj;
057 }
058 else if (obj instanceof ASN1Sequence)
059 {
060 return new Holder((ASN1Sequence)obj);
061 }
062
063 throw new IllegalArgumentException("unknown object in factory");
064 }
065
066 public Holder(
067 ASN1Sequence seq)
068 {
069 for (int i = 0; i != seq.size(); i++)
070 {
071 ASN1TaggedObject tObj = (ASN1TaggedObject)seq.getObjectAt(i);
072
073 switch (tObj.getTagNo())
074 {
075 case 0:
076 baseCertificateID = IssuerSerial.getInstance(tObj, false);
077 break;
078 case 1:
079 entityName = GeneralNames.getInstance(tObj, false);
080 break;
081 case 2:
082 objectDigestInfo = ObjectDigestInfo.getInstance(tObj, false);
083 break;
084 default:
085 throw new IllegalArgumentException("unknown tag in Holder");
086 }
087 }
088 }
089
090 public Holder(
091 IssuerSerial baseCertificateID)
092 {
093 this.baseCertificateID = baseCertificateID;
094 }
095
096 public Holder(
097 GeneralNames entityName)
098 {
099 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 }