View Javadoc

1   /**
2    *
3    *  Licensed to the Apache Software Foundation (ASF) under one or more
4    *  contributor license agreements.  See the NOTICE file distributed with
5    *  this work for additional information regarding copyright ownership.
6    *  The ASF licenses this file to You under the Apache License, Version 2.0
7    *  (the "License"); you may not use this file except in compliance with
8    *  the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing, software
13   *  distributed under the License is distributed on an "AS IS" BASIS,
14   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *  See the License for the specific language governing permissions and
16   *  limitations under the License.
17   */
18  
19  package org.apache.geronimo.util.asn1.x509;
20  
21  import org.apache.geronimo.util.asn1.ASN1Encodable;
22  import org.apache.geronimo.util.asn1.ASN1EncodableVector;
23  import org.apache.geronimo.util.asn1.ASN1Sequence;
24  import org.apache.geronimo.util.asn1.ASN1TaggedObject;
25  import org.apache.geronimo.util.asn1.DERBitString;
26  import org.apache.geronimo.util.asn1.DERObject;
27  import org.apache.geronimo.util.asn1.DERSequence;
28  import org.apache.geronimo.util.asn1.DERTaggedObject;
29  
30  /**
31   * The DistributionPoint object.
32   * <pre>
33   * DistributionPoint ::= SEQUENCE {
34   *      distributionPoint [0] DistributionPointName OPTIONAL,
35   *      reasons           [1] ReasonFlags OPTIONAL,
36   *      cRLIssuer         [2] GeneralNames OPTIONAL
37   * }
38   * </pre>
39   */
40  public class DistributionPoint
41      extends ASN1Encodable
42  {
43      DistributionPointName       distributionPoint;
44      ReasonFlags                 reasons;
45      GeneralNames                cRLIssuer;
46  
47      public static DistributionPoint getInstance(
48          ASN1TaggedObject obj,
49          boolean          explicit)
50      {
51          return getInstance(ASN1Sequence.getInstance(obj, explicit));
52      }
53  
54      public static DistributionPoint getInstance(
55          Object obj)
56      {
57          if(obj == null || obj instanceof DistributionPoint)
58          {
59              return (DistributionPoint)obj;
60          }
61  
62          if(obj instanceof ASN1Sequence)
63          {
64              return new DistributionPoint((ASN1Sequence)obj);
65          }
66  
67          throw new IllegalArgumentException("Invalid DistributionPoint: " + obj.getClass().getName());
68      }
69  
70      public DistributionPoint(
71          ASN1Sequence seq)
72      {
73          for (int i = 0; i != seq.size(); i++)
74          {
75              ASN1TaggedObject    t = (ASN1TaggedObject)seq.getObjectAt(i);
76              switch (t.getTagNo())
77              {
78              case 0:
79                  distributionPoint = DistributionPointName.getInstance(t, true);
80                  break;
81              case 1:
82                  reasons = new ReasonFlags(DERBitString.getInstance(t, false));
83                  break;
84              case 2:
85                  cRLIssuer = GeneralNames.getInstance(t, false);
86              }
87          }
88      }
89  
90      public DistributionPoint(
91          DistributionPointName distributionPoint,
92          ReasonFlags                 reasons,
93          GeneralNames            cRLIssuer)
94      {
95          this.distributionPoint = distributionPoint;
96          this.reasons = reasons;
97          this.cRLIssuer = cRLIssuer;
98      }
99  
100     public DistributionPointName getDistributionPoint()
101     {
102         return distributionPoint;
103     }
104 
105     public ReasonFlags getReasons()
106     {
107         return reasons;
108     }
109 
110     public GeneralNames getCRLIssuer()
111     {
112         return cRLIssuer;
113     }
114 
115     public DERObject toASN1Object()
116     {
117         ASN1EncodableVector  v = new ASN1EncodableVector();
118 
119         if (distributionPoint != null)
120         {
121             //
122             // as this is a CHOICE it must be explicitly tagged
123             //
124             v.add(new DERTaggedObject(0, distributionPoint));
125         }
126 
127         if (reasons != null)
128         {
129             v.add(new DERTaggedObject(false, 1, reasons));
130         }
131 
132         if (cRLIssuer != null)
133         {
134             v.add(new DERTaggedObject(false, 2, cRLIssuer));
135         }
136 
137         return new DERSequence(v);
138     }
139 }