* @return A Collection of ASN.1 Attribute (org.bouncycastle.asn1.x509), or an empty Collection, never null
* @see #getSubjectDirectoryAttributes(Certificate)
*/
public static Collection<Attribute> getSubjectDirectoryAttributes(String dirAttr) {
ArrayList<Attribute> ret = new ArrayList<Attribute>();
Attribute attr = null;
String value = CertTools.getPartFromDN(dirAttr, "countryOfResidence");
if (!StringUtils.isEmpty(value)) {
ASN1EncodableVector vec = new ASN1EncodableVector();
vec.add(new DERPrintableString(value));
attr = new Attribute(new DERObjectIdentifier(id_pda_countryOfResidence),new DERSet(vec));
ret.add(attr);
}
value = CertTools.getPartFromDN(dirAttr, "countryOfCitizenship");
if (!StringUtils.isEmpty(value)) {
ASN1EncodableVector vec = new ASN1EncodableVector();
vec.add(new DERPrintableString(value));
attr = new Attribute(new DERObjectIdentifier(id_pda_countryOfCitizenship),new DERSet(vec));
ret.add(attr);
}
value = CertTools.getPartFromDN(dirAttr, "gender");
if (!StringUtils.isEmpty(value)) {
ASN1EncodableVector vec = new ASN1EncodableVector();
vec.add(new DERPrintableString(value));
attr = new Attribute(new DERObjectIdentifier(id_pda_gender),new DERSet(vec));
ret.add(attr);
}
value = CertTools.getPartFromDN(dirAttr, "placeOfBirth");
if (!StringUtils.isEmpty(value)) {
ASN1EncodableVector vec = new ASN1EncodableVector();
X509DefaultEntryConverter conv = new X509DefaultEntryConverter();
DERObject obj = conv.getConvertedValue(new DERObjectIdentifier(id_pda_placeOfBirth), value);
vec.add(obj);
attr = new Attribute(new DERObjectIdentifier(id_pda_placeOfBirth),new DERSet(vec));
ret.add(attr);
}
// dateOfBirth that is a GeneralizedTime
// The correct format for this is YYYYMMDD, it will be padded to YYYYMMDD120000Z
value = CertTools.getPartFromDN(dirAttr, "dateOfBirth");
if (!StringUtils.isEmpty(value)) {
if (value.length() == 8) {
value += "120000Z"; // standard format according to rfc3739
ASN1EncodableVector vec = new ASN1EncodableVector();
vec.add(new DERGeneralizedTime(value));
attr = new Attribute(new DERObjectIdentifier(id_pda_dateOfBirth),new DERSet(vec));
ret.add(attr);
} else {
log.error("Wrong length of data for 'dateOfBirth', should be of format YYYYMMDD, skipping...");
}
}