1 17 18 package org.apache.geronimo.util.asn1; 19 20 import java.io.IOException ; 21 22 25 public class DERIA5String 26 extends DERObject 27 implements DERString 28 { 29 String string; 30 31 36 public static DERIA5String getInstance( 37 Object obj) 38 { 39 if (obj == null || obj instanceof DERIA5String) 40 { 41 return (DERIA5String)obj; 42 } 43 44 if (obj instanceof ASN1OctetString) 45 { 46 return new DERIA5String(((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 DERIA5String getInstance( 67 ASN1TaggedObject obj, 68 boolean explicit) 69 { 70 return getInstance(obj.getObject()); 71 } 72 73 76 public DERIA5String( 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 DERIA5String( 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(IA5_STRING, this.getOctets()); 121 } 122 123 public int hashCode() 124 { 125 return this.getString().hashCode(); 126 } 127 128 public boolean equals( 129 Object o) 130 { 131 if (!(o instanceof DERIA5String)) 132 { 133 return false; 134 } 135 136 DERIA5String s = (DERIA5String)o; 137 138 return this.getString().equals(s.getString()); 139 } 140 } 141 | Popular Tags |