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.ASN1Choice;
22  import org.apache.geronimo.util.asn1.ASN1Encodable;
23  import org.apache.geronimo.util.asn1.ASN1Set;
24  import org.apache.geronimo.util.asn1.ASN1TaggedObject;
25  import org.apache.geronimo.util.asn1.DEREncodable;
26  import org.apache.geronimo.util.asn1.DERObject;
27  import org.apache.geronimo.util.asn1.DERTaggedObject;
28  
29  /**
30   * The DistributionPointName object.
31   * <pre>
32   * DistributionPointName ::= CHOICE {
33   *     fullName                 [0] GeneralNames,
34   *     nameRelativeToCRLIssuer  [1] RelativeDistinguishedName
35   * }
36   * </pre>
37   */
38  public class DistributionPointName
39      extends ASN1Encodable
40      implements ASN1Choice
41  {
42      DEREncodable        name;
43      int                 type;
44  
45      public static final int FULL_NAME = 0;
46      public static final int NAME_RELATIVE_TO_CRL_ISSUER = 1;
47  
48      public static DistributionPointName getInstance(
49          ASN1TaggedObject obj,
50          boolean          explicit)
51      {
52          return getInstance(ASN1TaggedObject.getInstance(obj, true));
53      }
54  
55      public static DistributionPointName getInstance(
56          Object  obj)
57      {
58          if (obj == null || obj instanceof DistributionPointName)
59          {
60              return (DistributionPointName)obj;
61          }
62          else if (obj instanceof ASN1TaggedObject)
63          {
64              return new DistributionPointName((ASN1TaggedObject)obj);
65          }
66  
67          throw new IllegalArgumentException("unknown object in factory");
68      }
69  
70      /*
71       * @deprecated use ASN1Encodable
72       */
73      public DistributionPointName(
74          int             type,
75          DEREncodable    name)
76      {
77          this.type = type;
78          this.name = name;
79      }
80  
81      public DistributionPointName(
82          int             type,
83          ASN1Encodable   name)
84      {
85          this.type = type;
86          this.name = name;
87      }
88  
89      /**
90       * Return the tag number applying to the underlying choice.
91       *
92       * @return the tag number for this point name.
93       */
94      public int getType()
95      {
96          return this.type;
97      }
98  
99      /**
100      * Return the tagged object inside the distribution point name.
101      *
102      * @return the underlying choice item.
103      */
104     public ASN1Encodable getName()
105     {
106         return (ASN1Encodable)name;
107     }
108 
109     public DistributionPointName(
110         ASN1TaggedObject    obj)
111     {
112         this.type = obj.getTagNo();
113 
114         if (type == 0)
115         {
116             this.name = GeneralNames.getInstance(obj, false);
117         }
118         else
119         {
120             this.name = ASN1Set.getInstance(obj, false);
121         }
122     }
123 
124     public DERObject toASN1Object()
125     {
126         return new DERTaggedObject(false, type, name);
127     }
128 }