1 package org.bouncycastle.asn1;
6 * DER BMPString object.
8 public class DERBMPString
15 * return a BMP String from the given object.
17 * @param obj the object we want converted.
18 * @exception IllegalArgumentException if the object cannot be converted.
20 public static DERBMPString getInstance(
23 if (obj == null || obj instanceof DERBMPString)
25 return (DERBMPString)obj;
28 if (obj instanceof ASN1OctetString)
30 return new DERBMPString(((ASN1OctetString)obj).getOctets());
33 if (obj instanceof ASN1TaggedObject)
35 return getInstance(((ASN1TaggedObject)obj).getObject());
38 throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
42 * return a BMP String from a tagged object.
44 * @param obj the tagged object holding the object we want
45 * @param explicit true if the object is meant to be explicitly
46 * tagged false otherwise.
47 * @exception IllegalArgumentException if the tagged object cannot
50 public static DERBMPString getInstance(
54 return getInstance(obj.getObject());
59 * basic constructor - byte encoded string.
64 char[] cs = new char[string.length / 2];
66 for (int i = 0; i != cs.length; i++)
68 cs[i] = (char)((string[2 * i] << 8) | (string[2 * i + 1] & 0xff));
71 this.string = new String(cs);
83 public String getString()
90 return this.getString().hashCode();
93 public boolean equals(
96 if (!(o instanceof DERBMPString))
101 DERPrintableString s = (DERPrintableString)o;
103 return this.getString().equals(s.getString());
110 char[] c = string.toCharArray();
111 byte[] b = new byte[c.length * 2];
113 for (int i = 0; i != c.length; i++)
115 b[2 * i] = (byte)(c[i] >> 8);
116 b[2 * i + 1] = (byte)c[i];
119 out.writeEncoded(BMP_STRING, b);