FileDocCategorySizeDatePackage
ASN1Set.javaAPI DocAndroid 1.5 API8284Wed May 06 22:41:06 BST 2009org.bouncycastle.asn1

ASN1Set

public abstract class ASN1Set extends ASN1Collection

Fields Summary
Constructors Summary
public ASN1Set()

    
Methods Summary
public booleanequals(java.lang.Object o)

        if (o == this)
        {
            return true;
        }
        
        if (!(o instanceof DEREncodable))
        {
            return false;
        }

        DERObject      dObj = ((DEREncodable)o).getDERObject();
        
        if (!(dObj instanceof ASN1Set))
        {
            return false;
        }

        ASN1Set   other = (ASN1Set)dObj;

        if (this.size() != other.size())
        {
            return false;
        }

        Enumeration s1 = this.getObjects();
        Enumeration s2 = other.getObjects();

        while (s1.hasMoreElements())
        {
            if (!s1.nextElement().equals(s2.nextElement()))
            {
                return false;
            }
        }

        return true;
    
public static org.bouncycastle.asn1.ASN1SetgetInstance(java.lang.Object obj)
return an ASN1Set from the given object.

param
obj the object we want converted.
exception
IllegalArgumentException if the object cannot be converted.

        if (obj == null || obj instanceof ASN1Set)
        {
            return (ASN1Set)obj;
        }

        throw new IllegalArgumentException("unknown object in getInstance");
    
public static org.bouncycastle.asn1.ASN1SetgetInstance(ASN1TaggedObject obj, boolean explicit)
Return an ASN1 set from a tagged object. There is a special case here, if an object appears to have been explicitly tagged on reading but we were expecting it to be implictly tagged in the normal course of events it indicates that we lost the surrounding set - so we need to add it back (this will happen if the tagged object is a sequence that contains other sequences). If you are dealing with implicitly tagged sets you really should be using this method.

param
obj the tagged object.
param
explicit true if the object is meant to be explicitly tagged false otherwise.
exception
IllegalArgumentException if the tagged object cannot be converted.

        if (explicit)
        {
            if (!obj.isExplicit())
            {
                throw new IllegalArgumentException("object implicit - explicit expected.");
            }

            return (ASN1Set)obj.getObject();
        }
        else
        {
            //
            // constructed object which appears to be explicitly tagged
            // and it's really implicit means we have to add the
            // surrounding sequence.
            //
            if (obj.isExplicit())
            {
                ASN1Set    set = new DERSet(obj.getObject());

                return set;
            }
            else
            {
                if (obj.getObject() instanceof ASN1Set)
                {
                    return (ASN1Set)obj.getObject();
                }

                //
                // in this case the parser returns a sequence, convert it
                // into a set.
                //
                ASN1EncodableVector  v = new ASN1EncodableVector();

                if (obj.getObject() instanceof ASN1Sequence)
                {
                    ASN1Sequence s = (ASN1Sequence)obj.getObject();
                    Enumeration e = s.getObjects();

                    while (e.hasMoreElements())
                    {
                        v.add((DEREncodable)e.nextElement());
                    }

                    return new DERSet(v, false);
                }
            }
        }

        throw new IllegalArgumentException(
                    "unknown object in getInstanceFromTagged");