1 package org.bouncycastle.asn1;
6 * DER VisibleString object.
8 public class DERVisibleString
15 * return a Visible String from the passed in object.
17 * @exception IllegalArgumentException if the object cannot be converted.
19 public static DERVisibleString getInstance(
22 if (obj == null || obj instanceof DERVisibleString)
24 return (DERVisibleString)obj;
27 if (obj instanceof ASN1OctetString)
29 return new DERVisibleString(((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 Visible 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 DERVisibleString getInstance(
53 return getInstance(obj.getObject());
57 * basic constructor - byte encoded string.
59 public DERVisibleString(
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 DERVisibleString(
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(VISIBLE_STRING, this.getOctets());
106 public boolean equals(
109 if ((o == null) || !(o instanceof DERVisibleString))
114 return this.getString().equals(((DERVisibleString)o).getString());