001package org.apache.commons.ssl.org.bouncycastle.asn1.x509; 002 003import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Choice; 004import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Encodable; 005import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object; 006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive; 007import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Set; 008import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1TaggedObject; 009import org.apache.commons.ssl.org.bouncycastle.asn1.DERTaggedObject; 010 011/** 012 * The DistributionPointName object. 013 * <pre> 014 * DistributionPointName ::= CHOICE { 015 * fullName [0] GeneralNames, 016 * nameRelativeToCRLIssuer [1] RDN 017 * } 018 * </pre> 019 */ 020public class DistributionPointName 021 extends ASN1Object 022 implements ASN1Choice 023{ 024 ASN1Encodable name; 025 int type; 026 027 public static final int FULL_NAME = 0; 028 public static final int NAME_RELATIVE_TO_CRL_ISSUER = 1; 029 030 public static DistributionPointName getInstance( 031 ASN1TaggedObject obj, 032 boolean explicit) 033 { 034 return getInstance(ASN1TaggedObject.getInstance(obj, true)); 035 } 036 037 public static DistributionPointName getInstance( 038 Object obj) 039 { 040 if (obj == null || obj instanceof DistributionPointName) 041 { 042 return (DistributionPointName)obj; 043 } 044 else if (obj instanceof ASN1TaggedObject) 045 { 046 return new DistributionPointName((ASN1TaggedObject)obj); 047 } 048 049 throw new IllegalArgumentException("unknown object in factory: " + obj.getClass().getName()); 050 } 051 052 public DistributionPointName( 053 int type, 054 ASN1Encodable name) 055 { 056 this.type = type; 057 this.name = name; 058 } 059 060 public DistributionPointName( 061 GeneralNames name) 062 { 063 this(FULL_NAME, name); 064 } 065 066 /** 067 * Return the tag number applying to the underlying choice. 068 * 069 * @return the tag number for this point name. 070 */ 071 public int getType() 072 { 073 return this.type; 074 } 075 076 /** 077 * Return the tagged object inside the distribution point name. 078 * 079 * @return the underlying choice item. 080 */ 081 public ASN1Encodable getName() 082 { 083 return (ASN1Encodable)name; 084 } 085 086 public DistributionPointName( 087 ASN1TaggedObject obj) 088 { 089 this.type = obj.getTagNo(); 090 091 if (type == 0) 092 { 093 this.name = GeneralNames.getInstance(obj, false); 094 } 095 else 096 { 097 this.name = ASN1Set.getInstance(obj, false); 098 } 099 } 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}