~brian-thomason/+junk/bouncycastle

« back to all changes in this revision

Viewing changes to jdk1.0/org/bouncycastle/asn1/DERPrintableString.java

  • Committer: Brian Thomason
  • Date: 2011-12-20 17:20:32 UTC
  • Revision ID: brian.thomason@canonical.com-20111220172032-rdtm13jgdxtksacr
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.bouncycastle.asn1;
 
2
 
 
3
import java.io.IOException;
 
4
 
 
5
/**
 
6
 * DER PrintableString object.
 
7
 */
 
8
public class DERPrintableString
 
9
    extends DERObject
 
10
{
 
11
    String  string;
 
12
 
 
13
    public DERPrintableString(
 
14
        String   string)
 
15
    {
 
16
        this.string = string;
 
17
    }
 
18
 
 
19
    /**
 
20
     * @param string - bytes representing the string
 
21
     */
 
22
    public DERPrintableString(
 
23
        byte[]   string)
 
24
    {
 
25
        this.string = new String(string, 0);
 
26
    }
 
27
 
 
28
    public String getString()
 
29
    {
 
30
        return string;
 
31
    }
 
32
 
 
33
    public int hashCode()
 
34
    {
 
35
        return this.getString().hashCode();
 
36
    }
 
37
 
 
38
    public boolean equals(
 
39
        Object  o)
 
40
    {
 
41
        if (!(o instanceof DERPrintableString))
 
42
        {
 
43
            return false;
 
44
        }
 
45
 
 
46
        DERPrintableString  s = (DERPrintableString)o;
 
47
 
 
48
        return this.getString().equals(s.getString());
 
49
    }
 
50
    
 
51
    void encode(
 
52
        DEROutputStream  out)
 
53
        throws IOException
 
54
    {
 
55
        byte[]  bytes = new byte[string.length()];
 
56
 
 
57
        string.getBytes(0, string.length(), bytes, 0);
 
58
 
 
59
        out.writeEncoded(PRINTABLE_STRING, bytes);
 
60
    }
 
61
}