1 package org.bouncycastle.asn1;
6 abstract public class ASN1Set
9 protected Vector set = new Vector();
12 * return an ASN1Set from the given object.
14 * @param obj the object we want converted.
15 * @exception IllegalArgumentException if the object cannot be converted.
17 public static ASN1Set getInstance(
20 if (obj == null || obj instanceof ASN1Set)
25 throw new IllegalArgumentException("unknown object in getInstance");
29 * Return an ASN1 set from a tagged object. There is a special
30 * case here, if an object appears to have been explicitly tagged on
31 * reading but we were expecting it to be implictly tagged in the
32 * normal course of events it indicates that we lost the surrounding
33 * set - so we need to add it back (this will happen if the tagged
34 * object is a sequence that contains other sequences). If you are
35 * dealing with implicitly tagged sets you really <b>should</b>
36 * be using this method.
38 * @param obj the tagged object.
39 * @param explicit true if the object is meant to be explicitly tagged
41 * @exception IllegalArgumentException if the tagged object cannot
44 public static ASN1Set getInstance(
50 if (!obj.isExplicit())
52 throw new IllegalArgumentException("object implicit - explicit expected.");
55 return (ASN1Set)obj.getObject();
60 // constructed object which appears to be explicitly tagged
61 // and it's really implicit means we have to add the
62 // surrounding sequence.
66 ASN1Set set = new DERSet(obj.getObject());
73 // in this case the parser returns a sequence, convert it
76 DEREncodableVector v = new DEREncodableVector();
78 if (obj.getObject() instanceof ASN1Sequence)
80 ASN1Sequence s = (ASN1Sequence)obj.getObject();
81 Enumeration e = s.getObjects();
83 while (e.hasMoreElements())
85 v.add((DEREncodable)e.nextElement());
93 throw new IllegalArgumentException(
94 "unknown object in getInstanceFromTagged");
101 public Enumeration getObjects()
103 return set.elements();
107 * return the object at the set postion indicated by index.
109 * @param the set number (starting at zero) of the object
110 * @return the object at the set postion indicated by index.
112 public DEREncodable getObjectAt(
115 return (DEREncodable)set.elementAt(index);
119 * return the number of objects in this set.
121 * @return the number of objects in this set.
128 public int hashCode()
130 Enumeration e = this.getObjects();
133 while (e.hasMoreElements())
135 hashCode ^= e.nextElement().hashCode();
141 public boolean equals(
144 if (o == null || !(o instanceof ASN1Set))
149 ASN1Set other = (ASN1Set)o;
151 if (this.size() != other.size())
156 Enumeration s1 = this.getObjects();
157 Enumeration s2 = other.getObjects();
159 while (s1.hasMoreElements())
161 if (!s1.nextElement().equals(s2.nextElement()))
170 protected void addObject(
176 abstract void encode(DEROutputStream out)