1 package org.bouncycastle.asn1.x509; 2 3 import org.bouncycastle.asn1.ASN1Choice; 4 import org.bouncycastle.asn1.ASN1Encodable; 5 import org.bouncycastle.asn1.ASN1Set; 6 import org.bouncycastle.asn1.ASN1TaggedObject; 7 import org.bouncycastle.asn1.DEREncodable; 8 import org.bouncycastle.asn1.DERObject; 9 import org.bouncycastle.asn1.DERTaggedObject; 10 11 /** 12 * The DistributionPointName object. 13 * <pre> 14 * DistributionPointName ::= CHOICE { 15 * fullName [0] GeneralNames, 16 * nameRelativeToCRLIssuer [1] RDN 17 * } 18 * </pre> 19 */ 20 public class DistributionPointName 21 extends ASN1Encodable 22 implements ASN1Choice 23 { 24 DEREncodable name; 25 int type; 26 27 public static final int FULL_NAME = 0; 28 public static final int NAME_RELATIVE_TO_CRL_ISSUER = 1; 29 30 public static DistributionPointName getInstance( 31 ASN1TaggedObject obj, 32 boolean explicit) 33 { 34 return getInstance(ASN1TaggedObject.getInstance(obj, true)); 35 } 36 37 public static DistributionPointName getInstance( 38 Object obj) 39 { 40 if (obj == null || obj instanceof DistributionPointName) 41 { 42 return (DistributionPointName)obj; 43 } 44 else if (obj instanceof ASN1TaggedObject) 45 { 46 return new DistributionPointName((ASN1TaggedObject)obj); 47 } 48 49 throw new IllegalArgumentException("unknown object in factory: " + obj.getClass().getName()); 50 } 51 52 /* 53 * @deprecated use ASN1Encodable 54 */ 55 public DistributionPointName( 56 int type, 57 DEREncodable name) 58 { 59 this.type = type; 60 this.name = name; 61 } 62 63 public DistributionPointName( 64 int type, 65 ASN1Encodable name) 66 { 67 this.type = type; 68 this.name = name; 69 } 70 71 public DistributionPointName( 72 GeneralNames name) 73 { 74 this(FULL_NAME, name); 75 } 76 77 /** 78 * Return the tag number applying to the underlying choice. 79 * 80 * @return the tag number for this point name. 81 */ 82 public int getType() 83 { 84 return this.type; 85 } 86 87 /** 88 * Return the tagged object inside the distribution point name. 89 * 90 * @return the underlying choice item. 91 */ 92 public ASN1Encodable getName() 93 { 94 return (ASN1Encodable)name; 95 } 96 97 public DistributionPointName( 98 ASN1TaggedObject obj) 99 { 100 this.type = obj.getTagNo(); 101 102 if (type == 0) 103 { 104 this.name = GeneralNames.getInstance(obj, false); 105 } 106 else 107 { 108 this.name = ASN1Set.getInstance(obj, false); 109 } 110 } 111 112 public DERObject toASN1Object() 113 { 114 return new DERTaggedObject(false, type, name); 115 } 116 117 public String toString() 118 { 119 String sep = System.getProperty("line.separator"); 120 StringBuffer buf = new StringBuffer(); 121 buf.append("DistributionPointName: ["); 122 buf.append(sep); 123 if (type == FULL_NAME) 124 { 125 appendObject(buf, sep, "fullName", name.toString()); 126 } 127 else 128 { 129 appendObject(buf, sep, "nameRelativeToCRLIssuer", name.toString()); 130 } 131 buf.append("]"); 132 buf.append(sep); 133 return buf.toString(); 134 } 135 136 private void appendObject(StringBuffer buf, String sep, String name, String value) 137 { 138 String indent = " "; 139 140 buf.append(indent); 141 buf.append(name); 142 buf.append(":"); 143 buf.append(sep); 144 buf.append(indent); 145 buf.append(indent); 146 buf.append(value); 147 buf.append(sep); 148 } 149 } 150