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