1 17 18 package org.apache.geronimo.util.asn1.x509; 19 20 import java.math.BigInteger ; 21 22 import org.apache.geronimo.util.asn1.ASN1EncodableVector; 23 import org.apache.geronimo.util.asn1.ASN1Sequence; 24 import org.apache.geronimo.util.asn1.ASN1TaggedObject; 25 import org.apache.geronimo.util.asn1.DERBoolean; 26 import org.apache.geronimo.util.asn1.ASN1Encodable; 27 import org.apache.geronimo.util.asn1.DERInteger; 28 import org.apache.geronimo.util.asn1.DERObject; 29 import org.apache.geronimo.util.asn1.DERSequence; 30 31 public class BasicConstraints 32 extends ASN1Encodable 33 { 34 DERBoolean cA = new DERBoolean(false); 35 DERInteger pathLenConstraint = null; 36 37 public static BasicConstraints getInstance( 38 ASN1TaggedObject obj, 39 boolean explicit) 40 { 41 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 42 } 43 44 public static BasicConstraints getInstance( 45 Object obj) 46 { 47 if (obj == null || obj instanceof BasicConstraints) 48 { 49 return (BasicConstraints)obj; 50 } 51 else if (obj instanceof ASN1Sequence) 52 { 53 return new BasicConstraints((ASN1Sequence)obj); 54 } 55 56 throw new IllegalArgumentException ("unknown object in factory"); 57 } 58 59 public BasicConstraints( 60 ASN1Sequence seq) 61 { 62 if (seq.size() == 0) 63 { 64 this.cA = null; 65 this.pathLenConstraint = null; 66 } 67 else 68 { 69 this.cA = (DERBoolean)seq.getObjectAt(0); 70 if (seq.size() > 1) 71 { 72 this.pathLenConstraint = (DERInteger)seq.getObjectAt(1); 73 } 74 } 75 } 76 77 82 public BasicConstraints( 83 boolean cA, 84 int pathLenConstraint) 85 { 86 if (cA ) 87 { 88 this.cA = new DERBoolean(cA); 89 this.pathLenConstraint = new DERInteger(pathLenConstraint); 90 } 91 else 92 { 93 this.cA = null; 94 this.pathLenConstraint = null; 95 } 96 } 97 98 public BasicConstraints( 99 boolean cA) 100 { 101 if (cA) 102 { 103 this.cA = new DERBoolean(true); 104 } 105 else 106 { 107 this.cA = null; 108 } 109 this.pathLenConstraint = null; 110 } 111 112 117 public BasicConstraints( 118 int pathLenConstraint) 119 { 120 this.cA = new DERBoolean(true); 121 this.pathLenConstraint = new DERInteger(pathLenConstraint); 122 } 123 124 public boolean isCA() 125 { 126 return (cA != null) && cA.isTrue(); 127 } 128 129 public BigInteger getPathLenConstraint() 130 { 131 if (pathLenConstraint != null) 132 { 133 return pathLenConstraint.getValue(); 134 } 135 136 return null; 137 } 138 139 148 public DERObject toASN1Object() 149 { 150 ASN1EncodableVector v = new ASN1EncodableVector(); 151 152 if (cA != null) 153 { 154 v.add(cA); 155 156 if (pathLenConstraint != null) 157 { 158 v.add(pathLenConstraint); 159 } 160 } 161 162 return new DERSequence(v); 163 } 164 165 public String toString() 166 { 167 if (pathLenConstraint == null) 168 { 169 if (cA == null) 170 { 171 return "BasicConstraints: isCa(false)"; 172 } 173 return "BasicConstraints: isCa(" + this.isCA() + ")"; 174 } 175 return "BasicConstraints: isCa(" + this.isCA() + "), pathLenConstraint = " + pathLenConstraint.getValue(); 176 } 177 } 178 | Popular Tags |