X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fbouncycastle%2Fasn1%2FDEROctetString.java;fp=src%2Forg%2Fbouncycastle%2Fasn1%2FDEROctetString.java;h=fd9f516c7384f61e49d4ab2ba79d271c4b3e7663;hb=e5e9355b4f4e0e2c8de9068a71c1e3cc26fa9905;hp=0000000000000000000000000000000000000000;hpb=f35445729371789b3d496f426d7f87542f8e1a45;p=org.ibex.core.git diff --git a/src/org/bouncycastle/asn1/DEROctetString.java b/src/org/bouncycastle/asn1/DEROctetString.java new file mode 100644 index 0000000..fd9f516 --- /dev/null +++ b/src/org/bouncycastle/asn1/DEROctetString.java @@ -0,0 +1,97 @@ +package org.bouncycastle.asn1; + +import java.io.*; + +public class DEROctetString + extends DERObject +{ + byte[] string; + + /** + * @param string the octets making up the octet string. + */ + public DEROctetString( + byte[] string) + { + this.string = string; + } + + public DEROctetString( + DERObject 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()); + } + } + + public DEROctetString( + DEREncodable obj) + { + this(obj.getDERObject()); + } + + public byte[] getOctets() + { + return string; + } + + void encode( + DEROutputStream out) + throws IOException + { + out.writeEncoded(OCTET_STRING, string); + } + + public int hashCode() + { + byte[] b = this.getOctets(); + int value = 0; + + for (int i = 0; i != b.length; i++) + { + value ^= (b[i] & 0xff) << (i % 4); + } + + return value; + } + + public boolean equals( + Object o) + { + if (o == null || !(o instanceof DEROctetString)) + { + return false; + } + + DEROctetString other = (DEROctetString)o; + + if (other.getOctets().length != this.getOctets().length) + { + return false; + } + + byte[] b1 = other.getOctets(); + byte[] b2 = this.getOctets(); + + for (int i = 0; i != b1.length; i++) + { + if (b1[i] != b2[i]) + { + return false; + } + } + + return true; + } +}