1 17 18 package org.apache.geronimo.util.asn1.x509; 19 20 import org.apache.geronimo.util.asn1.ASN1Choice; 21 import org.apache.geronimo.util.asn1.ASN1Encodable; 22 import org.apache.geronimo.util.asn1.ASN1OctetString; 23 import org.apache.geronimo.util.asn1.ASN1Sequence; 24 import org.apache.geronimo.util.asn1.ASN1TaggedObject; 25 import org.apache.geronimo.util.asn1.DEREncodable; 26 import org.apache.geronimo.util.asn1.DERIA5String; 27 import org.apache.geronimo.util.asn1.DERObject; 28 import org.apache.geronimo.util.asn1.DERObjectIdentifier; 29 import org.apache.geronimo.util.asn1.DERTaggedObject; 30 31 56 public class GeneralName 57 extends ASN1Encodable 58 implements ASN1Choice 59 { 60 public static final int otherName = 0; 61 public static final int rfc822Name = 1; 62 public static final int dNSName = 2; 63 public static final int x400Address = 3; 64 public static final int directoryName = 4; 65 public static final int ediPartyName = 5; 66 public static final int uniformResourceIdentifier = 6; 67 public static final int iPAddress = 7; 68 public static final int registeredID = 8; 69 70 DEREncodable obj; 71 int tag; 72 73 public GeneralName( 74 X509Name dirName) 75 { 76 this.obj = dirName; 77 this.tag = 4; 78 } 79 80 83 public GeneralName( 84 DERObject name, int tag) 85 { 86 this.obj = name; 87 this.tag = tag; 88 } 89 90 117 public GeneralName( 118 int tag, 119 ASN1Encodable name) 120 { 121 this.obj = name; 122 this.tag = tag; 123 } 124 125 131 public GeneralName( 132 int tag, 133 String name) 134 { 135 if (tag == rfc822Name || tag == dNSName || tag == uniformResourceIdentifier) 136 { 137 this.tag = tag; 138 this.obj = new DERIA5String(name); 139 } 140 else if (tag == registeredID) 141 { 142 this.tag = tag; 143 this.obj = new DERObjectIdentifier(name); 144 } 145 else 146 { 147 throw new IllegalArgumentException ("can't process String for tag: " + tag); 148 } 149 } 150 151 public static GeneralName getInstance( 152 Object obj) 153 { 154 if (obj == null || obj instanceof GeneralName) 155 { 156 return (GeneralName)obj; 157 } 158 159 if (obj instanceof ASN1TaggedObject) 160 { 161 ASN1TaggedObject tagObj = (ASN1TaggedObject)obj; 162 int tag = tagObj.getTagNo(); 163 164 switch (tag) 165 { 166 case otherName: 167 return new GeneralName(ASN1Sequence.getInstance(tagObj, false), tag); 168 case rfc822Name: 169 return new GeneralName(DERIA5String.getInstance(tagObj, false), tag); 170 case dNSName: 171 return new GeneralName(DERIA5String.getInstance(tagObj, false), tag); 172 case x400Address: 173 throw new IllegalArgumentException ("unknown tag: " + tag); 174 case directoryName: 175 return new GeneralName(ASN1Sequence.getInstance(tagObj, true), tag); 176 case ediPartyName: 177 return new GeneralName(ASN1Sequence.getInstance(tagObj, false), tag); 178 case uniformResourceIdentifier: 179 return new GeneralName(DERIA5String.getInstance(tagObj, false), tag); 180 case iPAddress: 181 return new GeneralName(ASN1OctetString.getInstance(tagObj, false), tag); 182 case registeredID: 183 return new GeneralName(DERObjectIdentifier.getInstance(tagObj, false), tag); 184 } 185 } 186 187 throw new IllegalArgumentException ("unknown object in getInstance"); 188 } 189 190 public static GeneralName getInstance( 191 ASN1TaggedObject tagObj, 192 boolean explicit) 193 { 194 return GeneralName.getInstance(ASN1TaggedObject.getInstance(tagObj, true)); 195 } 196 197 public int getTagNo() 198 { 199 return tag; 200 } 201 202 public DEREncodable getName() 203 { 204 return obj; 205 } 206 207 public DERObject toASN1Object() 208 { 209 if (tag == directoryName) { 211 return new DERTaggedObject(true, tag, obj); 212 } 213 else 214 { 215 return new DERTaggedObject(false, tag, obj); 216 } 217 } 218 } 219 | Popular Tags |