Java 类org.bouncycastle.asn1.x509.SubjectDirectoryAttributes 实例源码

项目:keystore-explorer    文件:X509Ext.java   
private String getSubjectDirectoryAttributesStringValue(byte[] value) throws IOException {
    // @formatter:off

    /*
     * SubjectDirectoryAttributes ::= ASN1Sequence SIZE (1..MAX) OF Attribute
     *
     * Attribute ::= ASN1Sequence
     * {
     *      type AttributeType,
     *      values SET OF AttributeValue
     * }
     */

    // @formatter:on

    StringBuilder sb = new StringBuilder();

    SubjectDirectoryAttributes subjectDirectoryAttributes = SubjectDirectoryAttributes.getInstance(value);

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

        ASN1ObjectIdentifier attributeType = ((Attribute) attribute).getAttrType();
        String attributeTypeStr = attributeType.getId();

        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();
}