Example usage for org.bouncycastle.asn1.x500 RDN getInstance

List of usage examples for org.bouncycastle.asn1.x500 RDN getInstance

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.x500 RDN getInstance.

Prototype

public static RDN getInstance(Object obj) 

Source Link

Usage

From source file:net.sf.keystore_explorer.crypto.x509.X509Ext.java

License:Open Source License

private String getDistributionPointNameString(DistributionPointName distributionPointName, String baseIndent)
        throws IOException {
    // @formatter:off

    /*//from  www  .j  a v  a2s .c  o m
     * DistributionPointName ::= CHOICE { fullname [0] GeneralNames,
     * nameRelativeToCRLIssuer [1] RelativeDistinguishedName }
     *
     * RelativeDistinguishedName ::= SET SIZE (1 .. MAX) OF
     * AttributeTypeAndValue
     *
     * AttributeTypeAndValue ::= ASN1Sequence { type AttributeType, value
     * AttributeValue }
     */

    // @formatter: on

    StringBuilder sb = new StringBuilder();

    sb.append(baseIndent);
    sb.append(res.getString("DistributionPointName"));
    sb.append(NEWLINE);

    if (distributionPointName.getType() == DistributionPointName.FULL_NAME) {
        sb.append(baseIndent);
        sb.append(INDENT);
        sb.append(res.getString("DistributionPointFullName"));
        sb.append(NEWLINE);

        GeneralNames generalNames = GeneralNames.getInstance(distributionPointName.getName());

        for (GeneralName generalName : generalNames.getNames()) {
            sb.append(baseIndent);
            sb.append(INDENT);
            sb.append(INDENT);
            sb.append(GeneralNameUtil.toString(generalName));
            sb.append(NEWLINE);
        }
    } else {
        // DistributionPointName.TAG_NAMERELATIVETOCRLISSUER
        sb.append(baseIndent);
        sb.append(INDENT);
        sb.append(res.getString("DistributionPointNameRelativeToCrlIssuer"));
        sb.append(NEWLINE);

        RDN rdn = RDN.getInstance(distributionPointName.getName());

        for (AttributeTypeAndValue attributeTypeAndValue : rdn.getTypesAndValues()) {
            ASN1ObjectIdentifier attributeType = attributeTypeAndValue.getType();
            ASN1Encodable attributeValue = attributeTypeAndValue.getValue();

            String attributeTypeStr = getAttributeTypeString(attributeType);
            String attributeValueStr = getAttributeValueString(attributeType, attributeValue);

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

    return sb.toString();
}

From source file:org.globus.gsi.bc.X500NameHelper.java

License:Apache License

/**
 * Converts to {@link X500Name X500Name} object.
 *
 * @return the <code>X500Name</code> object.
 *///from   www.  java  2 s  .c  o  m
public X500Name getAsName() {
    RDN[] rdns = new RDN[seq.size()];
    int index = 0;
    for (Enumeration<?> e = seq.getObjects(); e.hasMoreElements();) {
        rdns[index++] = RDN.getInstance(e.nextElement());
    }
    return new X500Name(BCStyle.INSTANCE, rdns);
}

From source file:org.globus.gsi.bc.X500NameHelper.java

License:Apache License

private static String toString(ASN1Sequence seq) {
    if (seq == null) {
        return null;
    }/*from  w w  w.ja v a2 s  .c  o  m*/
    RDN[] rdns = new RDN[seq.size()];
    int index = 0;
    for (Enumeration<?> e = seq.getObjects(); e.hasMoreElements();) {
        rdns[index++] = RDN.getInstance(e.nextElement());
    }
    return new X500Name(GlobusStyle.INSTANCE, rdns).toString();
}