DistributionPointName.java revision e6bf3e8dfa2804891a82075cb469b736321b4827
1package org.bouncycastle.asn1.x509; 2 3import org.bouncycastle.asn1.ASN1Choice; 4import org.bouncycastle.asn1.ASN1Encodable; 5import org.bouncycastle.asn1.ASN1Object; 6import org.bouncycastle.asn1.ASN1Primitive; 7import org.bouncycastle.asn1.ASN1Set; 8import org.bouncycastle.asn1.ASN1TaggedObject; 9import 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 */ 20public class DistributionPointName 21 extends ASN1Object 22 implements ASN1Choice 23{ 24 ASN1Encodable 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 public DistributionPointName( 53 int type, 54 ASN1Encodable name) 55 { 56 this.type = type; 57 this.name = name; 58 } 59 60 public DistributionPointName( 61 GeneralNames name) 62 { 63 this(FULL_NAME, name); 64 } 65 66 /** 67 * Return the tag number applying to the underlying choice. 68 * 69 * @return the tag number for this point name. 70 */ 71 public int getType() 72 { 73 return this.type; 74 } 75 76 /** 77 * Return the tagged object inside the distribution point name. 78 * 79 * @return the underlying choice item. 80 */ 81 public ASN1Encodable getName() 82 { 83 return (ASN1Encodable)name; 84 } 85 86 public DistributionPointName( 87 ASN1TaggedObject obj) 88 { 89 this.type = obj.getTagNo(); 90 91 if (type == 0) 92 { 93 this.name = GeneralNames.getInstance(obj, false); 94 } 95 else 96 { 97 this.name = ASN1Set.getInstance(obj, false); 98 } 99 } 100 101 public ASN1Primitive toASN1Primitive() 102 { 103 return new DERTaggedObject(false, type, name); 104 } 105 106 public String toString() 107 { 108 String sep = System.getProperty("line.separator"); 109 StringBuffer buf = new StringBuffer(); 110 buf.append("DistributionPointName: ["); 111 buf.append(sep); 112 if (type == FULL_NAME) 113 { 114 appendObject(buf, sep, "fullName", name.toString()); 115 } 116 else 117 { 118 appendObject(buf, sep, "nameRelativeToCRLIssuer", name.toString()); 119 } 120 buf.append("]"); 121 buf.append(sep); 122 return buf.toString(); 123 } 124 125 private void appendObject(StringBuffer buf, String sep, String name, String value) 126 { 127 String indent = " "; 128 129 buf.append(indent); 130 buf.append(name); 131 buf.append(":"); 132 buf.append(sep); 133 buf.append(indent); 134 buf.append(indent); 135 buf.append(value); 136 buf.append(sep); 137 } 138} 139