1 17 18 package org.apache.geronimo.util.asn1; 19 20 import java.io.IOException ; 21 22 25 public class DERT61String 26 extends DERObject 27 implements DERString 28 { 29 String string; 30 31 36 public static DERT61String getInstance( 37 Object obj) 38 { 39 if (obj == null || obj instanceof DERT61String) 40 { 41 return (DERT61String)obj; 42 } 43 44 if (obj instanceof ASN1OctetString) 45 { 46 return new DERT61String(((ASN1OctetString)obj).getOctets()); 47 } 48 49 if (obj instanceof ASN1TaggedObject) 50 { 51 return getInstance(((ASN1TaggedObject)obj).getObject()); 52 } 53 54 throw new IllegalArgumentException ("illegal object in getInstance: " + obj.getClass().getName()); 55 } 56 57 66 public static DERT61String getInstance( 67 ASN1TaggedObject obj, 68 boolean explicit) 69 { 70 return getInstance(obj.getObject()); 71 } 72 73 76 public DERT61String( 77 byte[] string) 78 { 79 char[] cs = new char[string.length]; 80 81 for (int i = 0; i != cs.length; i++) 82 { 83 cs[i] = (char)(string[i] & 0xff); 84 } 85 86 this.string = new String (cs); 87 } 88 89 92 public DERT61String( 93 String string) 94 { 95 this.string = string; 96 } 97 98 public String getString() 99 { 100 return string; 101 } 102 103 void encode( 104 DEROutputStream out) 105 throws IOException 106 { 107 out.writeEncoded(T61_STRING, this.getOctets()); 108 } 109 110 public byte[] getOctets() 111 { 112 char[] cs = string.toCharArray(); 113 byte[] bs = new byte[cs.length]; 114 115 for (int i = 0; i != cs.length; i++) 116 { 117 bs[i] = (byte)cs[i]; 118 } 119 120 return bs; 121 } 122 123 public boolean equals( 124 Object o) 125 { 126 if ((o == null) || !(o instanceof DERT61String)) 127 { 128 return false; 129 } 130 131 return this.getString().equals(((DERT61String)o).getString()); 132 } 133 134 public int hashCode() 135 { 136 return this.getString().hashCode(); 137 } 138 } 139 | Popular Tags |