1 package com.lowagie.bc.asn1; 2 3 import java.io.IOException; 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 char[] cs = new char[string.length]; 63 64 for (int i = 0; i != cs.length; i++) 65 { 66 cs[i] = (char)(string[i] & 0xff); 67 } 68 69 this.string = new String(cs); 70 } 71 72 75 public DERT61String( 76 String string) 77 { 78 this.string = string; 79 } 80 81 public String getString() 82 { 83 return string; 84 } 85 86 void encode( 87 DEROutputStream out) 88 throws IOException 89 { 90 out.writeEncoded(T61_STRING, this.getOctets()); 91 } 92 93 public byte[] getOctets() 94 { 95 char[] cs = string.toCharArray(); 96 byte[] bs = new byte[cs.length]; 97 98 for (int i = 0; i != cs.length; i++) 99 { 100 bs[i] = (byte)cs[i]; 101 } 102 103 return bs; 104 } 105 106 public boolean equals( 107 Object o) 108 { 109 if ((o == null) || !(o instanceof DERT61String)) 110 { 111 return false; 112 } 113 114 return this.getString().equals(((DERT61String)o).getString()); 115 } 116 } 117 | Popular Tags |