Java源码示例:org.bouncycastle.asn1.x509.SubjectDirectoryAttributes

示例1
private String getSubjectDirectoryAttributesStringValue(byte[] value) throws IOException {
	// @formatter:off

	/*
	 * SubjectDirectoryAttributes ::= ASN1Sequence SIZE (1..MAX) OF Attribute
	 *
	 * Attribute ::= ASN1Sequence
	 * {
	 *      type AttributeType,
	 *      values SET OF AttributeValue
	 * }
	 *
	 * RFC 3739: "Compliant implementations SHALL be able to interpret the following attributes:"
	 *    DateOfBirth (1.3.6.1.5.5.7.9.1) ::= GeneralizedTime
	 *    PlaceOfBirth (1.3.6.1.5.5.7.9.2) ::= DirectoryString
	 *    Gender (1.3.6.1.5.5.7.9.3) ::= PrintableString (SIZE(1)) -- "M", "F", "m" or "f"
	 *    CountryOfCitizenship (1.3.6.1.5.5.7.9.4) ::= PrintableString (SIZE (2)) -- ISO 3166 Country Code
	 *    CountryOfResidence (1.3.6.1.5.5.7.9.5) ::= PrintableString (SIZE (2)) -- ISO 3166 Country Code
	 */

	// @formatter:on

	StringBuilder sb = new StringBuilder();

	SubjectDirectoryAttributes subjectDirectoryAttributes = SubjectDirectoryAttributes.getInstance(value);

	for (Object attribute : subjectDirectoryAttributes.getAttributes()) {

		ASN1ObjectIdentifier attributeType = ((Attribute) attribute).getAttrType();
		AttributeTypeType att = AttributeTypeType.resolveOid(attributeType.getId());
		String attributeTypeStr = (att == AttributeTypeType.UNKNOWN) ? attributeType.getId() : att.friendly();

		ASN1Encodable[] attributeValues = ((Attribute) attribute).getAttributeValues();

		for (ASN1Encodable attributeValue : attributeValues) {

			String attributeValueStr = getAttributeValueString(attributeType, attributeValue);

			sb.append(MessageFormat.format("{0}: {1}", attributeTypeStr, attributeValueStr));
			sb.append(NEWLINE);
		}
	}

	return sb.toString();
}
 
示例2
private String subjectDirectoryAttributesExtractor(ASN1Primitive primitive) {
	SubjectDirectoryAttributes sub = SubjectDirectoryAttributes.getInstance(primitive);
	return sub.toString();
}