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