1 17 18 package org.apache.geronimo.util.asn1.x509; 19 20 import java.io.ByteArrayInputStream ; 21 import java.io.IOException ; 22 23 import org.apache.geronimo.util.asn1.ASN1InputStream; 24 import org.apache.geronimo.util.asn1.DERObject; 25 import org.apache.geronimo.util.asn1.DERObjectIdentifier; 26 27 68 public abstract class X509NameEntryConverter 69 { 70 78 protected DERObject convertHexEncoded( 79 String str, 80 int off) 81 throws IOException 82 { 83 str = str.toLowerCase(); 84 byte[] data = new byte[str.length() / 2]; 85 for (int index = 0; index != data.length; index++) 86 { 87 char left = str.charAt((index * 2) + off); 88 char right = str.charAt((index * 2) + off + 1); 89 90 if (left < 'a') 91 { 92 data[index] = (byte)((left - '0') << 4); 93 } 94 else 95 { 96 data[index] = (byte)((left - 'a' + 10) << 4); 97 } 98 if (right < 'a') 99 { 100 data[index] |= (byte)(right - '0'); 101 } 102 else 103 { 104 data[index] |= (byte)(right - 'a' + 10); 105 } 106 } 107 108 ASN1InputStream aIn = new ASN1InputStream( 109 new ByteArrayInputStream (data)); 110 111 return aIn.readObject(); 112 } 113 114 118 protected boolean canBePrintable( 119 String str) 120 { 121 for (int i = str.length() - 1; i >= 0; i--) 122 { 123 char ch = str.charAt(i); 124 125 if (str.charAt(i) > 0x007f) 126 { 127 return false; 128 } 129 130 if ('a' <= ch && ch <= 'z') 131 { 132 continue; 133 } 134 135 if ('A' <= ch && ch <= 'Z') 136 { 137 continue; 138 } 139 140 if ('0' <= ch && ch <= '9') 141 { 142 continue; 143 } 144 145 switch (ch) 146 { 147 case ' ': 148 case '\'': 149 case '(': 150 case ')': 151 case '+': 152 case '-': 153 case '.': 154 case ':': 155 case '=': 156 case '?': 157 continue; 158 } 159 160 return false; 161 } 162 163 return true; 164 } 165 166 170 protected boolean canBeUTF8( 171 String str) 172 { 173 for (int i = str.length() - 1; i >= 0; i--) 174 { 175 if (str.charAt(i) > 0x00ff) 176 { 177 return false; 178 } 179 } 180 181 return true; 182 } 183 184 192 public abstract DERObject getConvertedValue(DERObjectIdentifier oid, String value); 193 } 194 | Popular Tags |