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: public class V2Form extends ASN1Encodable {
027: GeneralNames issuerName;
028: IssuerSerial baseCertificateID;
029: ObjectDigestInfo objectDigestInfo;
030:
031: public static V2Form getInstance(ASN1TaggedObject obj,
032: boolean explicit) {
033: return getInstance(ASN1Sequence.getInstance(obj, explicit));
034: }
035:
036: public static V2Form getInstance(Object obj) {
037: if (obj == null || obj instanceof V2Form) {
038: return (V2Form) obj;
039: } else if (obj instanceof ASN1Sequence) {
040: return new V2Form((ASN1Sequence) obj);
041: }
042:
043: throw new IllegalArgumentException("unknown object in factory");
044: }
045:
046: public V2Form(GeneralNames issuerName) {
047: this .issuerName = issuerName;
048: }
049:
050: public V2Form(ASN1Sequence seq) {
051: int index = 0;
052:
053: if (!(seq.getObjectAt(0) instanceof ASN1TaggedObject)) {
054: index++;
055: this .issuerName = GeneralNames.getInstance(seq
056: .getObjectAt(0));
057: }
058:
059: for (int i = index; i != seq.size(); i++) {
060: ASN1TaggedObject o = (ASN1TaggedObject) seq.getObjectAt(i);
061: if (o.getTagNo() == 0) {
062: baseCertificateID = IssuerSerial.getInstance(o, false);
063: } else if (o.getTagNo() == 1) {
064: objectDigestInfo = ObjectDigestInfo.getInstance(o,
065: false);
066: }
067: }
068: }
069:
070: public GeneralNames getIssuerName() {
071: return issuerName;
072: }
073:
074: public IssuerSerial getBaseCertificateID() {
075: return baseCertificateID;
076: }
077:
078: public ObjectDigestInfo getObjectDigestInfo() {
079: return objectDigestInfo;
080: }
081:
082: /**
083: * Produce an object suitable for an ASN1OutputStream.
084: * <pre>
085: * V2Form ::= SEQUENCE {
086: * issuerName GeneralNames OPTIONAL,
087: * baseCertificateID [0] IssuerSerial OPTIONAL,
088: * objectDigestInfo [1] ObjectDigestInfo OPTIONAL
089: * -- issuerName MUST be present in this profile
090: * -- baseCertificateID and objectDigestInfo MUST NOT
091: * -- be present in this profile
092: * }
093: * </pre>
094: */
095: public DERObject toASN1Object() {
096: ASN1EncodableVector v = new ASN1EncodableVector();
097:
098: if (issuerName != null) {
099: v.add(issuerName);
100: }
101:
102: if (baseCertificateID != null) {
103: v.add(new DERTaggedObject(false, 0, baseCertificateID));
104: }
105:
106: if (objectDigestInfo != null) {
107: v.add(new DERTaggedObject(false, 1, objectDigestInfo));
108: }
109:
110: return new DERSequence(v);
111: }
112: }
|