FileDocCategorySizeDatePackage
ASN1OctetString.javaAPI DocAzureus 3.0.3.43349Tue Jun 08 05:12:56 BST 2004org.bouncycastle.asn1

ASN1OctetString

public abstract class ASN1OctetString extends DERObject

Fields Summary
byte[]
string
Constructors Summary
public ASN1OctetString(byte[] string)

param
string the octets making up the octet string.

        this.string = string;
    
public ASN1OctetString(DEREncodable obj)

        try
        {
            ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
            DEROutputStream         dOut = new DEROutputStream(bOut);

            dOut.writeObject(obj);
            dOut.close();

            this.string = bOut.toByteArray();
        }
        catch (IOException e)
        {
            throw new IllegalArgumentException("Error processing object : " + e.toString());
        }
    
Methods Summary
abstract voidencode(DEROutputStream out)

public booleanequals(java.lang.Object o)

        if (o == null || !(o instanceof DEROctetString))
        {
            return false;
        }

        DEROctetString  other = (DEROctetString)o;

        byte[] b1 = other.getOctets();
        byte[] b2 = this.getOctets();

        if (b1.length != b2.length)
        {
            return false;
        }

        for (int i = 0; i != b1.length; i++)
        {
            if (b1[i] != b2[i])
            {
                return false;
            }
        }

        return true;
    
public static org.bouncycastle.asn1.ASN1OctetStringgetInstance(ASN1TaggedObject obj, boolean explicit)
return an Octet String from a tagged object.

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

        return getInstance(obj.getObject());
    
public static org.bouncycastle.asn1.ASN1OctetStringgetInstance(java.lang.Object obj)
return an Octet String from the given object.

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

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

        if (obj instanceof ASN1TaggedObject)
        {
            return getInstance(((ASN1TaggedObject)obj).getObject());
        }

        if (obj instanceof ASN1Sequence)
        {
            Vector      v = new Vector();
            Enumeration e = ((ASN1Sequence)obj).getObjects();

            while (e.hasMoreElements())
            {
                v.addElement(e.nextElement());
            }

            return new BERConstructedOctetString(v);
        }

        throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
    
public byte[]getOctets()

        return string;
    
public inthashCode()

        byte[]  b = this.getOctets();
        int     value = 0;

        for (int i = 0; i != b.length; i++)
        {
            value ^= (b[i] & 0xff) << (i % 4);
        }

        return value;