1 17 18 package org.apache.geronimo.util.asn1; 19 20 import java.io.IOException ; 21 22 25 public class DERVisibleString 26 extends DERObject 27 implements DERString 28 { 29 String string; 30 31 36 public static DERVisibleString getInstance( 37 Object obj) 38 { 39 if (obj == null || obj instanceof DERVisibleString) 40 { 41 return (DERVisibleString)obj; 42 } 43 44 if (obj instanceof ASN1OctetString) 45 { 46 return new DERVisibleString(((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 DERVisibleString getInstance( 67 ASN1TaggedObject obj, 68 boolean explicit) 69 { 70 return getInstance(obj.getObject()); 71 } 72 73 76 public DERVisibleString( 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 DERVisibleString( 93 String string) 94 { 95 this.string = string; 96 } 97 98 public String getString() 99 { 100 return string; 101 } 102 103 public byte[] getOctets() 104 { 105 char[] cs = string.toCharArray(); 106 byte[] bs = new byte[cs.length]; 107 108 for (int i = 0; i != cs.length; i++) 109 { 110 bs[i] = (byte)cs[i]; 111 } 112 113 return bs; 114 } 115 116 void encode( 117 DEROutputStream out) 118 throws IOException 119 { 120 out.writeEncoded(VISIBLE_STRING, this.getOctets()); 121 } 122 123 public boolean equals( 124 Object o) 125 { 126 if ((o == null) || !(o instanceof DERVisibleString)) 127 { 128 return false; 129 } 130 131 return this.getString().equals(((DERVisibleString)o).getString()); 132 } 133 134 public int hashCode() 135 { 136 return this.getString().hashCode(); 137 } 138 } 139 | Popular Tags |