001: package org.bouncycastle.asn1.x509;
002:
003: import org.bouncycastle.asn1.ASN1Choice;
004: import org.bouncycastle.asn1.ASN1Encodable;
005: import org.bouncycastle.asn1.ASN1Set;
006: import org.bouncycastle.asn1.ASN1TaggedObject;
007: import org.bouncycastle.asn1.DEREncodable;
008: import org.bouncycastle.asn1.DERObject;
009: import org.bouncycastle.asn1.DERTaggedObject;
010:
011: /**
012: * The DistributionPointName object.
013: * <pre>
014: * DistributionPointName ::= CHOICE {
015: * fullName [0] GeneralNames,
016: * nameRelativeToCRLIssuer [1] RelativeDistinguishedName
017: * }
018: * </pre>
019: */
020: public class DistributionPointName extends ASN1Encodable implements
021: ASN1Choice {
022: DEREncodable name;
023: int type;
024:
025: public static final int FULL_NAME = 0;
026: public static final int NAME_RELATIVE_TO_CRL_ISSUER = 1;
027:
028: public static DistributionPointName getInstance(
029: ASN1TaggedObject obj, boolean explicit) {
030: return getInstance(ASN1TaggedObject.getInstance(obj, true));
031: }
032:
033: public static DistributionPointName getInstance(Object obj) {
034: if (obj == null || obj instanceof DistributionPointName) {
035: return (DistributionPointName) obj;
036: } else if (obj instanceof ASN1TaggedObject) {
037: return new DistributionPointName((ASN1TaggedObject) obj);
038: }
039:
040: throw new IllegalArgumentException("unknown object in factory");
041: }
042:
043: /*
044: * @deprecated use ASN1Encodable
045: */
046: public DistributionPointName(int type, DEREncodable name) {
047: this .type = type;
048: this .name = name;
049: }
050:
051: public DistributionPointName(int type, ASN1Encodable name) {
052: this .type = type;
053: this .name = name;
054: }
055:
056: /**
057: * Return the tag number applying to the underlying choice.
058: *
059: * @return the tag number for this point name.
060: */
061: public int getType() {
062: return this .type;
063: }
064:
065: /**
066: * Return the tagged object inside the distribution point name.
067: *
068: * @return the underlying choice item.
069: */
070: public ASN1Encodable getName() {
071: return (ASN1Encodable) name;
072: }
073:
074: public DistributionPointName(ASN1TaggedObject obj) {
075: this .type = obj.getTagNo();
076:
077: if (type == 0) {
078: this .name = GeneralNames.getInstance(obj, false);
079: } else {
080: this .name = ASN1Set.getInstance(obj, false);
081: }
082: }
083:
084: public DERObject toASN1Object() {
085: return new DERTaggedObject(false, type, name);
086: }
087:
088: public String toString() {
089: String sep = System.getProperty("line.separator");
090: StringBuffer buf = new StringBuffer();
091: buf.append("DistributionPointName: [");
092: buf.append(sep);
093: if (type == FULL_NAME) {
094: appendObject(buf, sep, "fullName", name.toString());
095: } else {
096: appendObject(buf, sep, "nameRelativeToCRLIssuer", name
097: .toString());
098: }
099: buf.append("]");
100: buf.append(sep);
101: return buf.toString();
102: }
103:
104: private void appendObject(StringBuffer buf, String sep,
105: String name, String value) {
106: String indent = " ";
107:
108: buf.append(indent);
109: buf.append(name);
110: buf.append(":");
111: buf.append(sep);
112: buf.append(indent);
113: buf.append(indent);
114: buf.append(value);
115: buf.append(sep);
116: }
117: }
|