/** * * Copyright 2003-2004 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.geronimo.util.asn1.x509; import java.io.IOException; import org.apache.geronimo.util.asn1.DERBMPString; import org.apache.geronimo.util.asn1.DERIA5String; import org.apache.geronimo.util.asn1.DERObject; import org.apache.geronimo.util.asn1.DERObjectIdentifier; import org.apache.geronimo.util.asn1.DERPrintableString; import org.apache.geronimo.util.asn1.DERUTF8String; /** * The default converter for X509 DN entries when going from their * string value to */ public class X509DefaultEntryConverter extends X509NameEntryConverter { /** * Apply default coversion for the given value depending on the oid * and the character range of the value. * * @param oid the object identifier for the DN entry * @param value the value associated with it * @return the ASN.1 equivalent for the string value. */ public DERObject getConvertedValue( DERObjectIdentifier oid, String value) { if (value.length() != 0 && value.charAt(0) == '#') { try { return convertHexEncoded(value, 1); } catch (IOException e) { throw new RuntimeException("can't recode value for oid " + oid.getId()); } } else if (oid.equals(X509Name.EmailAddress)) { return new DERIA5String(value); } else if (canBePrintable(value)) { return new DERPrintableString(value); } else if (canBeUTF8(value)) { return new DERUTF8String(value); } return new DERBMPString(value); } }