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