1 package com.lowagie.bc.asn1; 2 3 import java.io.IOException; 4 import java.util.Enumeration; 5 import java.util.Vector; 6 7 abstract public class ASN1Set 8 extends DERObject 9 { 10 protected Vector set = new Vector(); 11 12 18 public static ASN1Set getInstance( 19 Object obj) 20 { 21 if (obj == null || obj instanceof ASN1Set) 22 { 23 return (ASN1Set)obj; 24 } 25 26 throw new IllegalArgumentException("unknown object in getInstance"); 27 } 28 29 45 public static ASN1Set 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 (ASN1Set)obj.getObject(); 57 } 58 else 59 { 60 if (obj.isExplicit()) 66 { 67 ASN1Set set = new DERSet(obj.getObject()); 68 69 return set; 70 } 71 else 72 { 73 if (obj.getObject() instanceof ASN1Set) 74 { 75 return (ASN1Set)obj.getObject(); 76 } 77 78 ASN1EncodableVector v = new ASN1EncodableVector(); 83 84 if (obj.getObject() instanceof ASN1Sequence) 85 { 86 ASN1Sequence s = (ASN1Sequence)obj.getObject(); 87 Enumeration e = s.getObjects(); 88 89 while (e.hasMoreElements()) 90 { 91 v.add((DEREncodable)e.nextElement()); 92 } 93 94 return new DERSet(v); 95 } 96 } 97 } 98 99 throw new IllegalArgumentException( 100 "unknown object in getInstanceFromTagged"); 101 } 102 103 public ASN1Set() 104 { 105 } 106 107 public Enumeration getObjects() 108 { 109 return set.elements(); 110 } 111 112 118 public DEREncodable getObjectAt( 119 int index) 120 { 121 return (DEREncodable)set.elementAt(index); 122 } 123 124 129 public int size() 130 { 131 return set.size(); 132 } 133 134 public int hashCode() 135 { 136 Enumeration e = this.getObjects(); 137 int hashCode = 0; 138 139 while (e.hasMoreElements()) 140 { 141 hashCode ^= e.nextElement().hashCode(); 142 } 143 144 return hashCode; 145 } 146 147 public boolean equals( 148 Object o) 149 { 150 if (o == null || !(o instanceof ASN1Set)) 151 { 152 return false; 153 } 154 155 ASN1Set other = (ASN1Set)o; 156 157 if (this.size() != other.size()) 158 { 159 return false; 160 } 161 162 Enumeration s1 = this.getObjects(); 163 Enumeration s2 = other.getObjects(); 164 165 while (s1.hasMoreElements()) 166 { 167 if (!s1.nextElement().equals(s2.nextElement())) 168 { 169 return false; 170 } 171 } 172 173 return true; 174 } 175 176 protected void addObject( 177 DEREncodable obj) 178 { 179 set.addElement(obj); 180 } 181 182 abstract void encode(DEROutputStream out) 183 throws IOException; 184 } 185 | Popular Tags |