1 package org.bouncycastle.asn1;
6 public abstract class ASN1OctetString
12 * return an Octet String from a tagged object.
14 * @param obj the tagged object holding the object we want.
15 * @param explicit true if the object is meant to be explicitly
16 * tagged false otherwise.
17 * @exception IllegalArgumentException if the tagged object cannot
20 public static ASN1OctetString getInstance(
24 return getInstance(obj.getObject());
28 * return an Octet String from the given object.
30 * @param obj the object we want converted.
31 * @exception IllegalArgumentException if the object cannot be converted.
33 public static ASN1OctetString getInstance(
36 if (obj == null || obj instanceof ASN1OctetString)
38 return (ASN1OctetString)obj;
41 if (obj instanceof ASN1TaggedObject)
43 return getInstance(((ASN1TaggedObject)obj).getObject());
46 if (obj instanceof ASN1Sequence)
48 Vector v = new Vector();
49 Enumeration e = ((ASN1Sequence)obj).getObjects();
51 while (e.hasMoreElements())
53 v.addElement(e.nextElement());
56 return new BERConstructedOctetString(v);
59 throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
63 * @param string the octets making up the octet string.
65 public ASN1OctetString(
71 public ASN1OctetString(
76 ByteArrayOutputStream bOut = new ByteArrayOutputStream();
77 DEROutputStream dOut = new DEROutputStream(bOut);
79 dOut.writeObject(obj);
82 this.string = bOut.toByteArray();
86 throw new IllegalArgumentException("Error processing object : " + e.toString());
90 public byte[] getOctets()
97 byte[] b = this.getOctets();
100 for (int i = 0; i != b.length; i++)
102 value ^= (b[i] & 0xff) << (i % 4);
108 public boolean equals(
111 if (o == null || !(o instanceof DEROctetString))
116 DEROctetString other = (DEROctetString)o;
118 byte[] b1 = other.getOctets();
119 byte[] b2 = this.getOctets();
121 if (b1.length != b2.length)
126 for (int i = 0; i != b1.length; i++)
137 abstract void encode(DEROutputStream out)