// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.asn1;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.bouncycastle.util.Encodable;

public abstract class ASN1Object implements ASN1Encodable, Encodable
{
    public void encodeTo(final OutputStream outputStream) throws IOException {
        this.toASN1Primitive().encodeTo(outputStream);
    }
    
    public void encodeTo(final OutputStream outputStream, final String s) throws IOException {
        this.toASN1Primitive().encodeTo(outputStream, s);
    }
    
    @Override
    public byte[] getEncoded() throws IOException {
        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        this.toASN1Primitive().encodeTo(byteArrayOutputStream);
        return byteArrayOutputStream.toByteArray();
    }
    
    public byte[] getEncoded(final String s) throws IOException {
        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        this.toASN1Primitive().encodeTo(byteArrayOutputStream, s);
        return byteArrayOutputStream.toByteArray();
    }
    
    @Override
    public int hashCode() {
        return this.toASN1Primitive().hashCode();
    }
    
    @Override
    public boolean equals(final Object o) {
        return this == o || (o instanceof ASN1Encodable && this.toASN1Primitive().equals(((ASN1Encodable)o).toASN1Primitive()));
    }
    
    protected static boolean hasEncodedTagValue(final Object o, final int n) {
        return o instanceof byte[] && ((byte[])o)[0] == n;
    }
    
    @Override
    public abstract ASN1Primitive toASN1Primitive();
}
