1 17 18 package org.apache.geronimo.util.asn1; 19 20 import java.io.IOException ; 21 22 public class DERGeneralString 23 extends DERObject implements DERString 24 { 25 private String string; 26 27 public static DERGeneralString getInstance( 28 Object obj) 29 { 30 if (obj == null || obj instanceof DERGeneralString) 31 { 32 return (DERGeneralString) obj; 33 } 34 if (obj instanceof ASN1OctetString) 35 { 36 return new DERGeneralString(((ASN1OctetString) obj).getOctets()); 37 } 38 if (obj instanceof ASN1TaggedObject) 39 { 40 return getInstance(((ASN1TaggedObject) obj).getObject()); 41 } 42 throw new IllegalArgumentException ("illegal object in getInstance: " 43 + obj.getClass().getName()); 44 } 45 46 public static DERGeneralString getInstance( 47 ASN1TaggedObject obj, 48 boolean explicit) 49 { 50 return getInstance(obj.getObject()); 51 } 52 53 public DERGeneralString(byte[] string) 54 { 55 char[] cs = new char[string.length]; 56 for (int i = 0; i != cs.length; i++) 57 { 58 cs[i] = (char)(string[i] & 0xff); 59 } 60 this.string = new String (cs); 61 } 62 63 public DERGeneralString(String string) 64 { 65 this.string = string; 66 } 67 68 public String getString() 69 { 70 return string; 71 } 72 73 public byte[] getOctets() 74 { 75 char[] cs = string.toCharArray(); 76 byte[] bs = new byte[cs.length]; 77 for (int i = 0; i != cs.length; i++) 78 { 79 bs[i] = (byte) cs[i]; 80 } 81 return bs; 82 } 83 84 void encode(DEROutputStream out) 85 throws IOException 86 { 87 out.writeEncoded(GENERAL_STRING, this.getOctets()); 88 } 89 90 public int hashCode() 91 { 92 return this.getString().hashCode(); 93 } 94 95 public boolean equals(Object o) 96 { 97 if (!(o instanceof DERGeneralString)) 98 { 99 return false; 100 } 101 DERGeneralString s = (DERGeneralString) o; 102 return this.getString().equals(s.getString()); 103 } 104 } 105 | Popular Tags |