1package org.bouncycastle.asn1;
2
3import java.io.IOException;
4
5public abstract  class ASN1Object
6    extends DERObject
7{
8    /**
9     * Create a base ASN.1 object from a byte stream.
10     *
11     * @param data the byte stream to parse.
12     * @return the base ASN.1 object represented by the byte stream.
13     * @exception IOException if there is a problem parsing the data.
14     */
15    public static ASN1Object fromByteArray(byte[] data)
16        throws IOException
17    {
18        ASN1InputStream aIn = new ASN1InputStream(data);
19
20        try
21        {
22            return (ASN1Object)aIn.readObject();
23        }
24        catch (ClassCastException e)
25        {
26            throw new IOException("cannot recognise object in stream");
27        }
28    }
29
30    public final boolean equals(Object o)
31    {
32        if (this == o)
33        {
34            return true;
35        }
36
37        return (o instanceof DEREncodable) && asn1Equals(((DEREncodable)o).getDERObject());
38    }
39
40    public abstract int hashCode();
41
42    abstract void encode(DEROutputStream out) throws IOException;
43
44    abstract boolean asn1Equals(DERObject o);
45}
46