001: package org.bouncycastle.asn1.x509;
002:
003: import org.bouncycastle.asn1.ASN1Encodable;
004: import org.bouncycastle.asn1.ASN1EncodableVector;
005: import org.bouncycastle.asn1.ASN1Sequence;
006: import org.bouncycastle.asn1.ASN1TaggedObject;
007: import org.bouncycastle.asn1.DERBitString;
008: import org.bouncycastle.asn1.DERObject;
009: import org.bouncycastle.asn1.DERSequence;
010: import org.bouncycastle.asn1.DERTaggedObject;
011:
012: /**
013: * The DistributionPoint object.
014: * <pre>
015: * DistributionPoint ::= SEQUENCE {
016: * distributionPoint [0] DistributionPointName OPTIONAL,
017: * reasons [1] ReasonFlags OPTIONAL,
018: * cRLIssuer [2] GeneralNames OPTIONAL
019: * }
020: * </pre>
021: */
022: public class DistributionPoint extends ASN1Encodable {
023: DistributionPointName distributionPoint;
024: ReasonFlags reasons;
025: GeneralNames cRLIssuer;
026:
027: public static DistributionPoint getInstance(ASN1TaggedObject obj,
028: boolean explicit) {
029: return getInstance(ASN1Sequence.getInstance(obj, explicit));
030: }
031:
032: public static DistributionPoint getInstance(Object obj) {
033: if (obj == null || obj instanceof DistributionPoint) {
034: return (DistributionPoint) obj;
035: }
036:
037: if (obj instanceof ASN1Sequence) {
038: return new DistributionPoint((ASN1Sequence) obj);
039: }
040:
041: throw new IllegalArgumentException(
042: "Invalid DistributionPoint: "
043: + obj.getClass().getName());
044: }
045:
046: public DistributionPoint(ASN1Sequence seq) {
047: for (int i = 0; i != seq.size(); i++) {
048: ASN1TaggedObject t = ASN1TaggedObject.getInstance(seq
049: .getObjectAt(i));
050: switch (t.getTagNo()) {
051: case 0:
052: distributionPoint = DistributionPointName.getInstance(
053: t, true);
054: break;
055: case 1:
056: reasons = new ReasonFlags(DERBitString.getInstance(t,
057: false));
058: break;
059: case 2:
060: cRLIssuer = GeneralNames.getInstance(t, false);
061: }
062: }
063: }
064:
065: public DistributionPoint(DistributionPointName distributionPoint,
066: ReasonFlags reasons, GeneralNames cRLIssuer) {
067: this .distributionPoint = distributionPoint;
068: this .reasons = reasons;
069: this .cRLIssuer = cRLIssuer;
070: }
071:
072: public DistributionPointName getDistributionPoint() {
073: return distributionPoint;
074: }
075:
076: public ReasonFlags getReasons() {
077: return reasons;
078: }
079:
080: public GeneralNames getCRLIssuer() {
081: return cRLIssuer;
082: }
083:
084: public DERObject toASN1Object() {
085: ASN1EncodableVector v = new ASN1EncodableVector();
086:
087: if (distributionPoint != null) {
088: //
089: // as this is a CHOICE it must be explicitly tagged
090: //
091: v.add(new DERTaggedObject(0, distributionPoint));
092: }
093:
094: if (reasons != null) {
095: v.add(new DERTaggedObject(false, 1, reasons));
096: }
097:
098: if (cRLIssuer != null) {
099: v.add(new DERTaggedObject(false, 2, cRLIssuer));
100: }
101:
102: return new DERSequence(v);
103: }
104:
105: public String toString() {
106: String sep = System.getProperty("line.separator");
107: StringBuffer buf = new StringBuffer();
108: buf.append("DistributionPoint: [");
109: buf.append(sep);
110: if (distributionPoint != null) {
111: appendObject(buf, sep, "distributionPoint",
112: distributionPoint.toString());
113: }
114: if (reasons != null) {
115: appendObject(buf, sep, "reasons", reasons.toString());
116: }
117: if (cRLIssuer != null) {
118: appendObject(buf, sep, "cRLIssuer", cRLIssuer.toString());
119: }
120: buf.append("]");
121: buf.append(sep);
122: return buf.toString();
123: }
124:
125: private void appendObject(StringBuffer buf, String sep,
126: String name, String value) {
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: }
|