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.ASN1Choice;
021 import org.apache.geronimo.crypto.asn1.ASN1Encodable;
022 import org.apache.geronimo.crypto.asn1.ASN1Set;
023 import org.apache.geronimo.crypto.asn1.ASN1TaggedObject;
024 import org.apache.geronimo.crypto.asn1.DEREncodable;
025 import org.apache.geronimo.crypto.asn1.DERObject;
026 import org.apache.geronimo.crypto.asn1.DERTaggedObject;
027
028 /**
029 * The DistributionPointName object.
030 * <pre>
031 * DistributionPointName ::= CHOICE {
032 * fullName [0] GeneralNames,
033 * nameRelativeToCRLIssuer [1] RelativeDistinguishedName
034 * }
035 * </pre>
036 */
037 public class DistributionPointName
038 extends ASN1Encodable
039 implements ASN1Choice
040 {
041 DEREncodable name;
042 int type;
043
044 public static final int FULL_NAME = 0;
045 public static final int NAME_RELATIVE_TO_CRL_ISSUER = 1;
046
047 public static DistributionPointName getInstance(
048 ASN1TaggedObject obj,
049 boolean explicit)
050 {
051 return getInstance(ASN1TaggedObject.getInstance(obj, true));
052 }
053
054 public static DistributionPointName getInstance(
055 Object obj)
056 {
057 if (obj == null || obj instanceof DistributionPointName)
058 {
059 return (DistributionPointName)obj;
060 }
061 else if (obj instanceof ASN1TaggedObject)
062 {
063 return new DistributionPointName((ASN1TaggedObject)obj);
064 }
065
066 throw new IllegalArgumentException("unknown object in factory");
067 }
068
069 /*
070 * @deprecated use ASN1Encodable
071 */
072 public DistributionPointName(
073 int type,
074 DEREncodable name)
075 {
076 this.type = type;
077 this.name = name;
078 }
079
080 public DistributionPointName(
081 int type,
082 ASN1Encodable name)
083 {
084 this.type = type;
085 this.name = name;
086 }
087
088 /**
089 * Return the tag number applying to the underlying choice.
090 *
091 * @return the tag number for this point name.
092 */
093 public int getType()
094 {
095 return this.type;
096 }
097
098 /**
099 * Return the tagged object inside the distribution point name.
100 *
101 * @return the underlying choice item.
102 */
103 public ASN1Encodable getName()
104 {
105 return (ASN1Encodable)name;
106 }
107
108 public DistributionPointName(
109 ASN1TaggedObject obj)
110 {
111 this.type = obj.getTagNo();
112
113 if (type == 0)
114 {
115 this.name = GeneralNames.getInstance(obj, false);
116 }
117 else
118 {
119 this.name = ASN1Set.getInstance(obj, false);
120 }
121 }
122
123 public DERObject toASN1Object()
124 {
125 return new DERTaggedObject(false, type, name);
126 }
127 }