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