1 19 20 package com.maverick.crypto.asn1; 21 22 import java.io.IOException ; 23 import java.util.Enumeration ; 24 import java.util.Vector ; 25 26 abstract public class ASN1Set 27 extends DERObject 28 { 29 protected Vector set = new Vector (); 30 31 37 public static ASN1Set getInstance( 38 Object obj) 39 { 40 if (obj == null || obj instanceof ASN1Set) 41 { 42 return (ASN1Set)obj; 43 } 44 45 throw new IllegalArgumentException ("unknown object in getInstance"); 46 } 47 48 64 public static ASN1Set getInstance( 65 ASN1TaggedObject obj, 66 boolean explicit) 67 { 68 if (explicit) 69 { 70 if (!obj.isExplicit()) 71 { 72 throw new IllegalArgumentException ("object implicit - explicit expected."); 73 } 74 75 return (ASN1Set)obj.getObject(); 76 } 77 else 78 { 79 if (obj.isExplicit()) 85 { 86 ASN1Set set = new DERSet(obj.getObject()); 87 88 return set; 89 } 90 else 91 { 92 if (obj.getObject() instanceof ASN1Set) 93 { 94 return (ASN1Set)obj.getObject(); 95 } 96 97 ASN1EncodableVector v = new ASN1EncodableVector(); 102 103 if (obj.getObject() instanceof ASN1Sequence) 104 { 105 ASN1Sequence s = (ASN1Sequence)obj.getObject(); 106 Enumeration e = s.getObjects(); 107 108 while (e.hasMoreElements()) 109 { 110 v.add((DEREncodable)e.nextElement()); 111 } 112 113 return new DERSet(v); 114 } 115 } 116 } 117 118 throw new IllegalArgumentException ( 119 "unknown object in getInstanceFromTagged"); 120 } 121 122 public ASN1Set() 123 { 124 } 125 126 public Enumeration getObjects() 127 { 128 return set.elements(); 129 } 130 131 137 public DEREncodable getObjectAt( 138 int index) 139 { 140 return (DEREncodable)set.elementAt(index); 141 } 142 143 148 public int size() 149 { 150 return set.size(); 151 } 152 153 public int hashCode() 154 { 155 Enumeration e = this.getObjects(); 156 int hashCode = 0; 157 158 while (e.hasMoreElements()) 159 { 160 hashCode ^= e.nextElement().hashCode(); 161 } 162 163 return hashCode; 164 } 165 166 public boolean equals( 167 Object o) 168 { 169 if (o == null || !(o instanceof ASN1Set)) 170 { 171 return false; 172 } 173 174 ASN1Set other = (ASN1Set)o; 175 176 if (this.size() != other.size()) 177 { 178 return false; 179 } 180 181 Enumeration s1 = this.getObjects(); 182 Enumeration s2 = other.getObjects(); 183 184 while (s1.hasMoreElements()) 185 { 186 if (!s1.nextElement().equals(s2.nextElement())) 187 { 188 return false; 189 } 190 } 191 192 return true; 193 } 194 195 protected void addObject( 196 DEREncodable obj) 197 { 198 set.addElement(obj); 199 } 200 201 abstract void encode(DEROutputStream out) 202 throws IOException ; 203 } 204 | Popular Tags |