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.DERBitString;
023: import org.apache.geronimo.crypto.asn1.DERObject;
024: import org.apache.geronimo.crypto.asn1.DERSequence;
025: import org.apache.geronimo.crypto.asn1.DERTaggedObject;
026:
027: /**
028: * The DistributionPoint object.
029: * <pre>
030: * DistributionPoint ::= SEQUENCE {
031: * distributionPoint [0] DistributionPointName OPTIONAL,
032: * reasons [1] ReasonFlags OPTIONAL,
033: * cRLIssuer [2] GeneralNames OPTIONAL
034: * }
035: * </pre>
036: */
037: public class DistributionPoint extends ASN1Encodable {
038: DistributionPointName distributionPoint;
039: ReasonFlags reasons;
040: GeneralNames cRLIssuer;
041:
042: public static DistributionPoint getInstance(ASN1TaggedObject obj,
043: boolean explicit) {
044: return getInstance(ASN1Sequence.getInstance(obj, explicit));
045: }
046:
047: public static DistributionPoint getInstance(Object obj) {
048: if (obj == null || obj instanceof DistributionPoint) {
049: return (DistributionPoint) obj;
050: }
051:
052: if (obj instanceof ASN1Sequence) {
053: return new DistributionPoint((ASN1Sequence) obj);
054: }
055:
056: throw new IllegalArgumentException(
057: "Invalid DistributionPoint: "
058: + obj.getClass().getName());
059: }
060:
061: public DistributionPoint(ASN1Sequence seq) {
062: for (int i = 0; i != seq.size(); i++) {
063: ASN1TaggedObject t = (ASN1TaggedObject) seq.getObjectAt(i);
064: switch (t.getTagNo()) {
065: case 0:
066: distributionPoint = DistributionPointName.getInstance(
067: t, true);
068: break;
069: case 1:
070: reasons = new ReasonFlags(DERBitString.getInstance(t,
071: false));
072: break;
073: case 2:
074: cRLIssuer = GeneralNames.getInstance(t, false);
075: }
076: }
077: }
078:
079: public DistributionPoint(DistributionPointName distributionPoint,
080: ReasonFlags reasons, GeneralNames cRLIssuer) {
081: this .distributionPoint = distributionPoint;
082: this .reasons = reasons;
083: this .cRLIssuer = cRLIssuer;
084: }
085:
086: public DistributionPointName getDistributionPoint() {
087: return distributionPoint;
088: }
089:
090: public ReasonFlags getReasons() {
091: return reasons;
092: }
093:
094: public GeneralNames getCRLIssuer() {
095: return cRLIssuer;
096: }
097:
098: public DERObject toASN1Object() {
099: ASN1EncodableVector v = new ASN1EncodableVector();
100:
101: if (distributionPoint != null) {
102: //
103: // as this is a CHOICE it must be explicitly tagged
104: //
105: v.add(new DERTaggedObject(0, distributionPoint));
106: }
107:
108: if (reasons != null) {
109: v.add(new DERTaggedObject(false, 1, reasons));
110: }
111:
112: if (cRLIssuer != null) {
113: v.add(new DERTaggedObject(false, 2, cRLIssuer));
114: }
115:
116: return new DERSequence(v);
117: }
118: }
|