2002/03/21 01:19:32
[org.ibex.core.git] / src / org / bouncycastle / asn1 / DERPrintableString.java
1 package org.bouncycastle.asn1;
2
3 import java.io.*;
4
5 /**
6  * DER PrintableString object.
7  */
8 public class DERPrintableString
9     extends DERObject
10     implements DERString
11 {
12     String  string;
13
14     /**
15      * basic constructor - byte encoded string.
16      */
17     public DERPrintableString(
18         byte[]   string)
19     {
20         try
21         {
22             this.string = new String(string, "US-ASCII");
23         }
24         catch(UnsupportedEncodingException e)
25         {
26             throw new RuntimeException("PANIC: " + e);
27         }
28     }
29
30     /**
31      * basic constructor
32      */
33     public DERPrintableString(
34         String   string)
35     {
36         this.string = string;
37     }
38
39     public String getString()
40     {
41         return string;
42     }
43
44     public byte[] getOctets()
45     {
46         try
47         {
48             return string.getBytes("US-ASCII");
49         }
50         catch(UnsupportedEncodingException e)
51         {
52             throw new RuntimeException("PANIC: " + e);
53         }
54     }
55
56     void encode(
57         DEROutputStream  out)
58         throws IOException
59     {
60         out.writeEncoded(PRINTABLE_STRING, this.getOctets());
61     }
62 }