1 package org.bouncycastle.asn1;
6 * DER PrintableString object.
8 public class DERPrintableString
15 * return a printable string from the passed in object.
17 * @exception IllegalArgumentException if the object cannot be converted.
19 public static DERPrintableString getInstance(
22 if (obj == null || obj instanceof DERPrintableString)
24 return (DERPrintableString)obj;
27 if (obj instanceof ASN1OctetString)
29 return new DERPrintableString(((ASN1OctetString)obj).getOctets());
32 if (obj instanceof ASN1TaggedObject)
34 return getInstance(((ASN1TaggedObject)obj).getObject());
37 throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
41 * return a Printable String from a tagged object.
43 * @param obj the tagged object holding the object we want
44 * @param explicit true if the object is meant to be explicitly
45 * tagged false otherwise.
46 * @exception IllegalArgumentException if the tagged object cannot
49 public static DERPrintableString getInstance(
53 return getInstance(obj.getObject());
57 * basic constructor - byte encoded string.
59 public DERPrintableString(
62 char[] cs = new char[string.length];
64 for (int i = 0; i != cs.length; i++)
66 cs[i] = (char)(string[i] & 0xff);
69 this.string = new String(cs);
75 public DERPrintableString(
81 public String getString()
86 public byte[] getOctets()
88 char[] cs = string.toCharArray();
89 byte[] bs = new byte[cs.length];
91 for (int i = 0; i != cs.length; i++)
103 out.writeEncoded(PRINTABLE_STRING, this.getOctets());
106 public int hashCode()
108 return this.getString().hashCode();
111 public boolean equals(
114 if (!(o instanceof DERPrintableString))
119 DERPrintableString s = (DERPrintableString)o;
121 return this.getString().equals(s.getString());