1 package com.lowagie.bc.asn1; 2 3 import java.io.IOException; 4 import java.util.Enumeration; 5 import java.util.Vector; 6 7 public abstract class ASN1Sequence 8 extends DERObject 9 { 10 private Vector seq = new Vector(); 11 12 18 public static ASN1Sequence getInstance( 19 Object obj) 20 { 21 if (obj == null || obj instanceof ASN1Sequence) 22 { 23 return (ASN1Sequence)obj; 24 } 25 26 throw new IllegalArgumentException("unknown object in getInstance"); 27 } 28 29 45 public static ASN1Sequence getInstance( 46 ASN1TaggedObject obj, 47 boolean explicit) 48 { 49 if (explicit) 50 { 51 if (!obj.isExplicit()) 52 { 53 throw new IllegalArgumentException("object implicit - explicit expected."); 54 } 55 56 return (ASN1Sequence)obj.getObject(); 57 } 58 else 59 { 60 if (obj.isExplicit()) 66 { 67 if (obj instanceof BERTaggedObject) 68 { 69 return new BERSequence(obj.getObject()); 70 } 71 else 72 { 73 return new DERSequence(obj.getObject()); 74 } 75 } 76 else 77 { 78 if (obj.getObject() instanceof ASN1Sequence) 79 { 80 return (ASN1Sequence)obj.getObject(); 81 } 82 } 83 } 84 85 throw new IllegalArgumentException( 86 "unknown object in getInstanceFromTagged"); 87 } 88 89 public Enumeration getObjects() 90 { 91 return seq.elements(); 92 } 93 94 100 public DEREncodable getObjectAt( 101 int index) 102 { 103 return (DEREncodable)seq.elementAt(index); 104 } 105 106 111 public int size() 112 { 113 return seq.size(); 114 } 115 116 public int hashCode() 117 { 118 Enumeration e = this.getObjects(); 119 int hashCode = 0; 120 121 while (e.hasMoreElements()) 122 { 123 Object o = e.nextElement(); 124 125 if (o != null) 126 { 127 hashCode ^= o.hashCode(); 128 } 129 } 130 131 return hashCode; 132 } 133 134 public boolean equals( 135 Object o) 136 { 137 if (o == null || !(o instanceof ASN1Sequence)) 138 { 139 return false; 140 } 141 142 ASN1Sequence other = (ASN1Sequence)o; 143 144 if (this.size() != other.size()) 145 { 146 return false; 147 } 148 149 Enumeration s1 = this.getObjects(); 150 Enumeration s2 = other.getObjects(); 151 152 while (s1.hasMoreElements()) 153 { 154 Object o1 = s1.nextElement(); 155 Object o2 = s2.nextElement(); 156 157 if (o1 != null && o2 != null) 158 { 159 if (!o1.equals(o2)) 160 { 161 return false; 162 } 163 } 164 else if (o1 == null && o2 == null) 165 { 166 continue; 167 } 168 else 169 { 170 return false; 171 } 172 } 173 174 return true; 175 } 176 177 protected void addObject( 178 DEREncodable obj) 179 { 180 seq.addElement(obj); 181 } 182 183 abstract void encode(DEROutputStream out) 184 throws IOException; 185 } 186 | Popular Tags |