Example usage for org.bouncycastle.asn1 DLSet getObjectAt

List of usage examples for org.bouncycastle.asn1 DLSet getObjectAt

Introduction

In this page you can find the example usage for org.bouncycastle.asn1 DLSet getObjectAt.

Prototype

public ASN1Encodable getObjectAt(int index) 

Source Link

Document

return the object at the set position indicated by index.

Usage

From source file:eu.europa.ec.markt.dss.DSSUtils.java

License:Open Source License

private static HashMap<String, String> get(final X500Principal x500Principal) {

    HashMap<String, String> treeMap = new HashMap<String, String>();
    final byte[] encoded = x500Principal.getEncoded();
    final ASN1Sequence asn1Sequence = ASN1Sequence.getInstance(encoded);
    final ASN1Encodable[] asn1Encodables = asn1Sequence.toArray();
    for (final ASN1Encodable asn1Encodable : asn1Encodables) {

        final DLSet dlSet = (DLSet) asn1Encodable;
        for (int ii = 0; ii < dlSet.size(); ii++) {

            final DLSequence dlSequence = (DLSequence) dlSet.getObjectAt(ii);
            if (dlSequence.size() != 2) {

                throw new DSSException("The DLSequence must contains exactly 2 elements.");
            }/*from   w  ww.java 2  s . c o  m*/
            final ASN1Encodable asn1EncodableAttributeType = dlSequence.getObjectAt(0);
            final String stringAttributeType = getString(asn1EncodableAttributeType);
            final ASN1Encodable asn1EncodableAttributeValue = dlSequence.getObjectAt(1);
            final String stringAttributeValue = getString(asn1EncodableAttributeValue);
            treeMap.put(stringAttributeType, stringAttributeValue);
        }
    }
    return treeMap;
}

From source file:eu.europa.ec.markt.dss.DSSUtils.java

License:Open Source License

private static String getUtf8String(final X500Principal x500Principal) {

    final byte[] encoded = x500Principal.getEncoded();
    final ASN1Sequence asn1Sequence = ASN1Sequence.getInstance(encoded);
    final ASN1Encodable[] asn1Encodables = asn1Sequence.toArray();
    final StringBuilder stringBuilder = new StringBuilder();
    /**//from w  w w .  java  2  s.c o m
     * RFC 4514 LDAP: Distinguished Names
     * 2.1.  Converting the RDNSequence
     *
     * If the RDNSequence is an empty sequence, the result is the empty or
     * zero-length string.
     *
     * Otherwise, the output consists of the string encodings of each
     * RelativeDistinguishedName in the RDNSequence (according to Section
     * 2.2), starting with the last element of the sequence and moving
     * backwards toward the first.
     * ...
     */
    for (int ii = asn1Encodables.length - 1; ii >= 0; ii--) {

        final ASN1Encodable asn1Encodable = asn1Encodables[ii];

        final DLSet dlSet = (DLSet) asn1Encodable;
        for (int jj = 0; jj < dlSet.size(); jj++) {

            final DLSequence dlSequence = (DLSequence) dlSet.getObjectAt(jj);
            if (dlSequence.size() != 2) {

                throw new DSSException("The DLSequence must contains exactly 2 elements.");
            }
            final ASN1Encodable attributeType = dlSequence.getObjectAt(0);
            final ASN1Encodable attributeValue = dlSequence.getObjectAt(1);
            String string = getString(attributeValue);

            /**
             * RFC 4514               LDAP: Distinguished Names
             * ...
             * Other characters may be escaped.
             *
             * Each octet of the character to be escaped is replaced by a backslash
             * and two hex digits, which form a single octet in the code of the
             * character.  Alternatively, if and only if the character to be escaped
             * is one of
             *
             * ' ', '"', '#', '+', ',', ';', '<', '=', '>', or '\'
             * (U+0020, U+0022, U+0023, U+002B, U+002C, U+003B,
             * U+003C, U+003D, U+003E, U+005C, respectively)
             *
             * it can be prefixed by a backslash ('\' U+005C).
             * ...
             */
            string = string.replace("\"", "\\\"");
            string = string.replace("#", "\\#");
            string = string.replace("+", "\\+");
            string = string.replace(",", "\\,");
            string = string.replace(";", "\\;");
            string = string.replace("<", "\\<");
            string = string.replace("=", "\\=");
            string = string.replace(">", "\\>");
            // System.out.println(">>> " + attributeType.toString() + "=" + attributeValue.getClass().getSimpleName() + "[" + string + "]");
            if (stringBuilder.length() != 0) {
                stringBuilder.append(',');
            }
            stringBuilder.append(attributeType).append('=').append(string);
        }
    }
    //final X500Name x500Name = X500Name.getInstance(encoded);
    return stringBuilder.toString();
}

From source file:eu.europa.esig.dss.DSSASN1Utils.java

License:Open Source License

public static Map<String, String> get(final X500Principal x500Principal) {
    Map<String, String> treeMap = new HashMap<String, String>();
    final byte[] encoded = x500Principal.getEncoded();
    final ASN1Sequence asn1Sequence = ASN1Sequence.getInstance(encoded);
    final ASN1Encodable[] asn1Encodables = asn1Sequence.toArray();
    for (final ASN1Encodable asn1Encodable : asn1Encodables) {

        final DLSet dlSet = (DLSet) asn1Encodable;
        for (int ii = 0; ii < dlSet.size(); ii++) {

            final DLSequence dlSequence = (DLSequence) dlSet.getObjectAt(ii);
            if (dlSequence.size() != 2) {

                throw new DSSException("The DLSequence must contains exactly 2 elements.");
            }/*from   w  w w. ja  v a  2s . c o m*/
            final ASN1Encodable asn1EncodableAttributeType = dlSequence.getObjectAt(0);
            final String stringAttributeType = getString(asn1EncodableAttributeType);
            final ASN1Encodable asn1EncodableAttributeValue = dlSequence.getObjectAt(1);
            final String stringAttributeValue = getString(asn1EncodableAttributeValue);
            treeMap.put(stringAttributeType, stringAttributeValue);
        }
    }
    return treeMap;
}

From source file:eu.europa.esig.dss.DSSASN1Utils.java

License:Open Source License

public static String getUtf8String(final X500Principal x500Principal) {

    final byte[] encoded = x500Principal.getEncoded();
    final ASN1Sequence asn1Sequence = ASN1Sequence.getInstance(encoded);
    final ASN1Encodable[] asn1Encodables = asn1Sequence.toArray();
    final StringBuilder stringBuilder = new StringBuilder();
    /**//from w  w  w. j  a  v  a2  s  .  c o m
     * RFC 4514 LDAP: Distinguished Names
     * 2.1. Converting the RDNSequence
     *
     * If the RDNSequence is an empty sequence, the result is the empty or
     * zero-length string.
     *
     * Otherwise, the output consists of the string encodings of each
     * RelativeDistinguishedName in the RDNSequence (according to Section
     * 2.2), starting with the last element of the sequence and moving
     * backwards toward the first.
     * ...
     */
    for (int ii = asn1Encodables.length - 1; ii >= 0; ii--) {

        final ASN1Encodable asn1Encodable = asn1Encodables[ii];

        final DLSet dlSet = (DLSet) asn1Encodable;
        for (int jj = 0; jj < dlSet.size(); jj++) {

            final DLSequence dlSequence = (DLSequence) dlSet.getObjectAt(jj);
            if (dlSequence.size() != 2) {

                throw new DSSException("The DLSequence must contains exactly 2 elements.");
            }
            final ASN1Encodable attributeType = dlSequence.getObjectAt(0);
            final ASN1Encodable attributeValue = dlSequence.getObjectAt(1);
            String string = getString(attributeValue);

            /**
             * RFC 4514 LDAP: Distinguished Names
             * ...
             * Other characters may be escaped.
             *
             * Each octet of the character to be escaped is replaced by a backslash
             * and two hex digits, which form a single octet in the code of the
             * character. Alternatively, if and only if the character to be escaped
             * is one of
             *
             * ' ', '"', '#', '+', ',', ';', '<', '=', '>', or '\'
             * (U+0020, U+0022, U+0023, U+002B, U+002C, U+003B,
             * U+003C, U+003D, U+003E, U+005C, respectively)
             *
             * it can be prefixed by a backslash ('\' U+005C).
             * ...
             */
            string = string.replace("\"", "\\\"");
            string = string.replace("#", "\\#");
            string = string.replace("+", "\\+");
            string = string.replace(",", "\\,");
            string = string.replace(";", "\\;");
            string = string.replace("<", "\\<");
            string = string.replace("=", "\\=");
            string = string.replace(">", "\\>");
            // System.out.println(">>> " + attributeType.toString() + "=" +
            // attributeValue.getClass().getSimpleName() + "[" + string + "]");
            if (stringBuilder.length() != 0) {
                stringBuilder.append(',');
            }
            stringBuilder.append(attributeType).append('=').append(string);
        }
    }
    // final X500Name x500Name = X500Name.getInstance(encoded);
    return stringBuilder.toString();
}