1 package org.bouncycastle.asn1;
6 * DER UniversalString object.
8 public class DERUniversalString
13 char[] table = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
16 * return a Universal String from the passed in object.
18 * @exception IllegalArgumentException if the object cannot be converted.
20 public static DERUniversalString getInstance(
23 if (obj == null || obj instanceof DERUniversalString)
25 return (DERUniversalString)obj;
28 if (obj instanceof ASN1OctetString)
30 return new DERUniversalString(((ASN1OctetString)obj).getOctets());
33 throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
37 * return a Universal String from a tagged object.
39 * @param obj the tagged object holding the object we want
40 * @param explicit true if the object is meant to be explicitly
41 * tagged false otherwise.
42 * @exception IllegalArgumentException if the tagged object cannot
45 public static DERUniversalString getInstance(
49 return getInstance(obj.getObject());
53 * basic constructor - byte encoded string.
55 public DERUniversalString(
62 * UniversalStrings have characters which are 4 bytes long - for the
63 * moment we just return them in Hex...
65 public String getString()
67 StringBuffer buf = new StringBuffer();
69 for (int i = 0; i != string.length; i++)
71 buf.append(table[(string[i] >>> 4) % 0xf]);
72 buf.append(table[string[i] & 0xf]);
75 return buf.toString();
78 public byte[] getOctets()
87 out.writeEncoded(UNIVERSAL_STRING, this.getOctets());
90 public boolean equals(
93 if ((o == null) || !(o instanceof DERUniversalString))
98 return this.getString().equals(((DERUniversalString)o).getString());