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