1 package org.bouncycastle.asn1;
2
3 import java.io.*;
4
5
8 public class DERT61String
9 extends DERObject
10 implements DERString
11 {
12 String string;
13
14
19 public static DERT61String getInstance(
20 Object obj)
21 {
22 if (obj == null || obj instanceof DERT61String)
23 {
24 return (DERT61String)obj;
25 }
26
27 if (obj instanceof ASN1OctetString)
28 {
29 return new DERT61String(((ASN1OctetString)obj).getOctets());
30 }
31
32 if (obj instanceof ASN1TaggedObject)
33 {
34 return getInstance(((ASN1TaggedObject)obj).getObject());
35 }
36
37 throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
38 }
39
40
49 public static DERT61String getInstance(
50 ASN1TaggedObject obj,
51 boolean explicit)
52 {
53 return getInstance(obj.getObject());
54 }
55
56
59 public DERT61String(
60 byte[] string)
61 {
62 this.string = new String(string);
63 }
64
65
68 public DERT61String(
69 String string)
70 {
71 this.string = string;
72 }
73
74 public String getString()
75 {
76 return string;
77 }
78
79 void encode(
80 DEROutputStream out)
81 throws IOException
82 {
83 out.writeEncoded(T61_STRING, string.getBytes());
84 }
85
86 public boolean equals(
87 Object o)
88 {
89 if ((o == null) || !(o instanceof DERT61String))
90 {
91 return false;
92 }
93
94 return this.getString().equals(((DERT61String)o).getString());
95 }
96 }
97