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