ASN1ObjectIdentifier oid;
RFC2253Parser p;
ASN1Sequence seq;
Iterator i;
ASN1Set set;
String key;
String val;
AVA entry;
initMaps();
if (encType == -1) {
if (!allowDefaultEncoding_) {
throw new BadNameException(
"Use the other constructor with the explicit "
+ "encoding parameter!");
}
currentEncoding_ = defaultEncoding_;
} else {
if (encType != UTF8_ENCODING && encType != T61_ENCODING
&& encType != PRINTABLE_ENCODING && encType != IA5_ENCODING) {
throw new BadNameException("Unknown EncodingType: " + encType);
}
currentEncoding_ = encType;
}
p = new RFC2253Parser();
set = new ASN1Set(1);
for (i = p.parse(rfc2253String).iterator(); i.hasNext();) {
entry = (AVA) i.next();
key = entry.getKey();
key = key.toUpperCase();
oid = (ASN1ObjectIdentifier) a2oid_.get(key);
seq = new ASN1Sequence(2);
if (oid == null) {
try {
oid = new ASN1ObjectIdentifier(key);
} catch (Exception e) {
throw new BadNameException("Unsupported attribute key: \""
+ key + "\"");
}
}
seq.add(oid.clone());
if (entry.isEncodedValue()) {
ByteArrayInputStream in;
BERDecoder dec;
ASN1Type obj;
byte[] buf;
try {
buf = entry.getEncodedValue();
in = new ByteArrayInputStream(buf);
dec = new BERDecoder(in);
obj = dec.readType();
dec.close();
} catch (Exception e) {
throw new BadNameException(
"Binary data is not a valid BER encoding!");
}
seq.add(obj);
} else {
val = entry.getValue();
/*
* This is a workaround for email addresses which contain the
* '@' symbol. This symbol is not in the character set of the
* ASN.1 PrintableString. Hence, we have to take a IA5String
* instead.
*/
if (entry.getKey().equalsIgnoreCase("EMAILADDRESS")
|| entry.getKey().equalsIgnoreCase("UID")) {
seq.add(new ASN1IA5String(val));
} else if (entry.getKey().equalsIgnoreCase("C")
|| entry.getKey().equalsIgnoreCase("SERIALNUMBER")) {
seq.add(new ASN1PrintableString(val));
} else {
switch (currentEncoding_) {
case (ASN1.TAG_UTF8STRING):
seq.add(new ASN1UTF8String(val));
break;
case (ASN1.TAG_IA5STRING):
seq.add(new ASN1IA5String(val));
break;
case (ASN1.TAG_PRINTABLESTRING):
if (checkPrintableSpelling(val)) {
seq.add(new ASN1PrintableString(val));
} else {
throw new BadNameException(
"Illegal characters for PrintableString "
+ "in characters");
}
break;
case (ASN1.TAG_T61STRING):
seq.add(new ASN1T61String(val));
break;
}
}
}
set.add(seq);
if (entry.hasSibling()) {
continue;
}
set.trimToSize();
super.add(0, set);
set = new ASN1Set(1);
}
trimToSize();
}