1 package org.bouncycastle.asn1;
6 * DER IA5String object - this is an ascii string.
8 public class DERIA5String
15 * return a IA5 string from the passed in object
17 * @exception IllegalArgumentException if the object cannot be converted.
19 public static DERIA5String getInstance(
22 if (obj == null || obj instanceof DERIA5String)
24 return (DERIA5String)obj;
27 if (obj instanceof ASN1OctetString)
29 return new DERIA5String(((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 an IA5 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 DERIA5String getInstance(
53 return getInstance(obj.getObject());
57 * basic constructor - with bytes.
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);
73 * basic constructor - with string.
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(IA5_STRING, this.getOctets());
106 public int hashCode()
108 return this.getString().hashCode();
111 public boolean equals(
114 if (!(o instanceof DERIA5String))
119 DERIA5String s = (DERIA5String)o;
121 return this.getString().equals(s.getString());