1 17 18 package org.apache.geronimo.util.asn1.x509; 19 20 import java.math.BigInteger ; 21 22 import org.apache.geronimo.util.asn1.ASN1Encodable; 23 import org.apache.geronimo.util.asn1.ASN1EncodableVector; 24 import org.apache.geronimo.util.asn1.ASN1Sequence; 25 import org.apache.geronimo.util.asn1.ASN1TaggedObject; 26 import org.apache.geronimo.util.asn1.DERInteger; 27 import org.apache.geronimo.util.asn1.DERObject; 28 import org.apache.geronimo.util.asn1.DERSequence; 29 import org.apache.geronimo.util.asn1.DERTaggedObject; 30 31 public class GeneralSubtree 32 extends ASN1Encodable 33 { 34 private GeneralName base; 35 private DERInteger minimum; 36 private DERInteger maximum; 37 38 public GeneralSubtree( 39 ASN1Sequence seq) 40 { 41 base = GeneralName.getInstance(seq.getObjectAt(0)); 42 43 switch (seq.size()) 44 { 45 case 1: 46 break; 47 case 2: 48 ASN1TaggedObject o = (ASN1TaggedObject)seq.getObjectAt(1); 49 switch (o.getTagNo()) 50 { 51 case 0 : 52 minimum = DERInteger.getInstance(o, false); 53 break; 54 case 1 : 55 maximum = DERInteger.getInstance(o, false); 56 break; 57 default: 58 throw new IllegalArgumentException ("Bad tag number: " + o.getTagNo()); 59 } 60 break; 61 case 3 : 62 minimum = DERInteger.getInstance((ASN1TaggedObject)seq.getObjectAt(1), false); 63 maximum = DERInteger.getInstance((ASN1TaggedObject)seq.getObjectAt(2), false); 64 break; 65 default: 66 throw new IllegalArgumentException ("Bad sequence size: " + seq.size()); 67 } 68 } 69 70 public static GeneralSubtree getInstance( 71 ASN1TaggedObject o, 72 boolean explicit) 73 { 74 return new GeneralSubtree(ASN1Sequence.getInstance(o, explicit)); 75 } 76 77 public static GeneralSubtree getInstance( 78 Object obj) 79 { 80 if (obj == null) 81 { 82 return null; 83 } 84 85 if (obj instanceof GeneralSubtree) 86 { 87 return (GeneralSubtree)obj; 88 } 89 90 return new GeneralSubtree(ASN1Sequence.getInstance(obj)); 91 } 92 93 public GeneralName getBase() 94 { 95 return base; 96 } 97 98 public BigInteger getMinimum() 99 { 100 if (minimum == null) 101 { 102 return BigInteger.valueOf(0); 103 } 104 105 return minimum.getValue(); 106 } 107 108 public BigInteger getMaximum() 109 { 110 if (maximum == null) 111 { 112 return null; 113 } 114 115 return maximum.getValue(); 116 } 117 118 124 public DERObject toASN1Object() 125 { 126 ASN1EncodableVector v = new ASN1EncodableVector(); 127 128 v.add(base); 129 130 if (minimum != null) 131 { 132 v.add(new DERTaggedObject(false, 0, minimum)); 133 } 134 135 if (maximum != null) 136 { 137 v.add(new DERTaggedObject(false, 1, maximum)); 138 } 139 140 return new DERSequence(v); 141 } 142 } 143 | Popular Tags |