1package org.bouncycastle.asn1.x509; 2 3import java.io.IOException; 4 5import org.bouncycastle.asn1.DERGeneralizedTime; 6import org.bouncycastle.asn1.DERIA5String; 7import org.bouncycastle.asn1.DERObject; 8import org.bouncycastle.asn1.DERObjectIdentifier; 9import org.bouncycastle.asn1.DERUTF8String; 10 11/** 12 * The default converter for X509 DN entries when going from their 13 * string value to ASN.1 strings. 14 */ 15public class X509DefaultEntryConverter 16 extends X509NameEntryConverter 17{ 18 /** 19 * Apply default coversion for the given value depending on the oid 20 * and the character range of the value. 21 * 22 * @param oid the object identifier for the DN entry 23 * @param value the value associated with it 24 * @return the ASN.1 equivalent for the string value. 25 */ 26 public DERObject getConvertedValue( 27 DERObjectIdentifier oid, 28 String value) 29 { 30 if (value.length() != 0 && value.charAt(0) == '#') 31 { 32 try 33 { 34 return convertHexEncoded(value, 1); 35 } 36 catch (IOException e) 37 { 38 throw new RuntimeException("can't recode value for oid " + oid.getId()); 39 } 40 } 41 else if (oid.equals(X509Name.EmailAddress) || oid.equals(X509Name.DC)) 42 { 43 return new DERIA5String(value); 44 } 45 else if (oid.equals(X509Name.DATE_OF_BIRTH)) 46 { 47 return new DERGeneralizedTime(value); 48 } 49 50 return new DERUTF8String(value); 51 } 52} 53