src/java.base/share/classes/sun/security/x509/RDN.java
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 53018 8bf9268df0e2
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
31426
9cd672654f97 8022444: Remove sun.security.util.ObjectIdentifier.equals(ObjectIdentifier other) method
juh
parents: 30649
diff changeset
     2
 * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.security.x509;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.StringReader;
35283
c5082624b79f 8074068: Cleanup in java.base/share/classes/sun/security/x509/
igerasim
parents: 31426
diff changeset
    30
import java.util.Arrays;
c5082624b79f 8074068: Cleanup in java.base/share/classes/sun/security/x509/
igerasim
parents: 31426
diff changeset
    31
import java.util.StringJoiner;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * RDNs are a set of {attribute = value} assertions.  Some of those
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * attributes are "distinguished" (unique w/in context).  Order is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * never relevant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Some X.500 names include only a single distinguished attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * per RDN.  This style is currently common.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Note that DER-encoded RDNs sort AVAs by assertion OID ... so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * when we parse this data we don't have to worry about canonicalizing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * it, but we'll need to sort them when we expose the RDN class more.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * The ASN.1 for RDNs is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * RelativeDistinguishedName ::=
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *   SET OF AttributeTypeAndValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * AttributeTypeAndValue ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *   type     AttributeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *   value    AttributeValue }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * AttributeType ::= OBJECT IDENTIFIER
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * AttributeValue ::= ANY DEFINED BY AttributeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * Note that instances of this class are immutable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
public class RDN {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // currently not private, accessed directly from X500Name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    final AVA[] assertion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    // cached immutable List of the AVAs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private volatile List<AVA> avaList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    // cache canonical String form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private volatile String canonicalString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Constructs an RDN from its printable representation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * An RDN may consist of one or multiple Attribute Value Assertions (AVAs),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * using '+' as a separator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * If the '+' should be considered part of an AVA value, it must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * preceded by '\'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param name String form of RDN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @throws IOException on parsing error
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public RDN(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        this(name, Collections.<String, String>emptyMap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Constructs an RDN from its printable representation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * An RDN may consist of one or multiple Attribute Value Assertions (AVAs),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * using '+' as a separator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * If the '+' should be considered part of an AVA value, it must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * preceded by '\'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param name String form of RDN
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 30033
diff changeset
   100
     * @param keywordMap an additional mapping of keywords to OIDs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @throws IOException on parsing error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public RDN(String name, Map<String, String> keywordMap) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        int quoteCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        int searchOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        int avaOffset = 0;
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 26967
diff changeset
   107
        List<AVA> avaVec = new ArrayList<>(3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        int nextPlus = name.indexOf('+');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        while (nextPlus >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            quoteCount += X500Name.countQuotes(name, searchOffset, nextPlus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
             * We have encountered an AVA delimiter (plus sign).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
             * If the plus sign in the RDN under consideration is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
             * preceded by a backslash (escape), or by a double quote, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
             * is part of the AVA. Otherwise, it is used as a separator, to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
             * delimit the AVA under consideration from any subsequent AVAs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            if (nextPlus > 0 && name.charAt(nextPlus - 1) != '\\'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                && quoteCount != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                 * Plus sign is a separator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                String avaString = name.substring(avaOffset, nextPlus);
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 47216
diff changeset
   124
                if (avaString.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    throw new IOException("empty AVA in RDN \"" + name + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                // Parse AVA, and store it in vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                AVA ava = new AVA(new StringReader(avaString), keywordMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                avaVec.add(ava);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                // Increase the offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                avaOffset = nextPlus + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                // Set quote counter back to zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                quoteCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            searchOffset = nextPlus + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            nextPlus = name.indexOf('+', searchOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        // parse last or only AVA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        String avaString = name.substring(avaOffset);
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 47216
diff changeset
   144
        if (avaString.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            throw new IOException("empty AVA in RDN \"" + name + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        AVA ava = new AVA(new StringReader(avaString), keywordMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        avaVec.add(ava);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        assertion = avaVec.toArray(new AVA[avaVec.size()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Constructs an RDN from its printable representation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * An RDN may consist of one or multiple Attribute Value Assertions (AVAs),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * using '+' as a separator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * If the '+' should be considered part of an AVA value, it must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * preceded by '\'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param name String form of RDN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @throws IOException on parsing error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    RDN(String name, String format) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        this(name, format, Collections.<String, String>emptyMap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Constructs an RDN from its printable representation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * An RDN may consist of one or multiple Attribute Value Assertions (AVAs),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * using '+' as a separator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * If the '+' should be considered part of an AVA value, it must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * preceded by '\'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @param name String form of RDN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @param keyword an additional mapping of keywords to OIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @throws IOException on parsing error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    RDN(String name, String format, Map<String, String> keywordMap)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (format.equalsIgnoreCase("RFC2253") == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            throw new IOException("Unsupported format " + format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        int searchOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        int avaOffset = 0;
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 26967
diff changeset
   187
        List<AVA> avaVec = new ArrayList<>(3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        int nextPlus = name.indexOf('+');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        while (nextPlus >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
             * We have encountered an AVA delimiter (plus sign).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
             * If the plus sign in the RDN under consideration is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
             * preceded by a backslash (escape), or by a double quote, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
             * is part of the AVA. Otherwise, it is used as a separator, to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
             * delimit the AVA under consideration from any subsequent AVAs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            if (nextPlus > 0 && name.charAt(nextPlus - 1) != '\\' ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                 * Plus sign is a separator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                String avaString = name.substring(avaOffset, nextPlus);
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 47216
diff changeset
   202
                if (avaString.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    throw new IOException("empty AVA in RDN \"" + name + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                // Parse AVA, and store it in vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                AVA ava = new AVA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    (new StringReader(avaString), AVA.RFC2253, keywordMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                avaVec.add(ava);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                // Increase the offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                avaOffset = nextPlus + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            searchOffset = nextPlus + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            nextPlus = name.indexOf('+', searchOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        // parse last or only AVA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        String avaString = name.substring(avaOffset);
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 47216
diff changeset
   220
        if (avaString.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            throw new IOException("empty AVA in RDN \"" + name + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        AVA ava = new AVA(new StringReader(avaString), AVA.RFC2253, keywordMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        avaVec.add(ava);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        assertion = avaVec.toArray(new AVA[avaVec.size()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Constructs an RDN from an ASN.1 encoded value.  The encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * of the name in the stream uses DER (a BER/1 subset).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @param value a DER-encoded value holding an RDN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @throws IOException on parsing error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    RDN(DerValue rdn) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (rdn.tag != DerValue.tag_Set) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            throw new IOException("X500 RDN");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        DerInputStream dis = new DerInputStream(rdn.toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        DerValue[] avaset = dis.getSet(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        assertion = new AVA[avaset.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        for (int i = 0; i < avaset.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            assertion[i] = new AVA(avaset[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Creates an empty RDN with slots for specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * number of AVAs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @param i number of AVAs to be in RDN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    RDN(int i) { assertion = new AVA[i]; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public RDN(AVA ava) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if (ava == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        assertion = new AVA[] { ava };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public RDN(AVA[] avas) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        assertion = avas.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        for (int i = 0; i < assertion.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            if (assertion[i] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * Return an immutable List of the AVAs in this RDN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public List<AVA> avas() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        List<AVA> list = avaList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if (list == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            list = Collections.unmodifiableList(Arrays.asList(assertion));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            avaList = list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        return list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Return the number of AVAs in this RDN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return assertion.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        if (obj instanceof RDN == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        RDN other = (RDN)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if (this.assertion.length != other.assertion.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        String thisCanon = this.toRFC2253String(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        String otherCanon = other.toRFC2253String(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        return thisCanon.equals(otherCanon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * Calculates a hash code value for the object.  Objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * which are equal will also have the same hashcode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 30033
diff changeset
   312
     * @return int hashCode value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return toRFC2253String(true).hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * return specified attribute value from RDN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 30033
diff changeset
   321
     * @param oid ObjectIdentifier of attribute to be found
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 30033
diff changeset
   322
     * @return DerValue of attribute value; null if attribute does not exist
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    DerValue findAttribute(ObjectIdentifier oid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        for (int i = 0; i < assertion.length; i++) {
31426
9cd672654f97 8022444: Remove sun.security.util.ObjectIdentifier.equals(ObjectIdentifier other) method
juh
parents: 30649
diff changeset
   326
            if (assertion[i].oid.equals(oid)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                return assertion[i].value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * Encode the RDN in DER-encoded form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @param out DerOutputStream to which RDN is to be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    void encode(DerOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        out.putOrderedSetOf(DerValue.tag_Set, assertion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * Returns a printable form of this RDN, using RFC 1779 style catenation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * of attribute/value assertions, and emitting attribute type keywords
26967
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
   346
     * from RFCs 1779, 2253, and 5280.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        if (assertion.length == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            return assertion[0].toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   353
        StringJoiner sj = new StringJoiner(" + ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        for (int i = 0; i < assertion.length; i++) {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   355
            sj.add(assertion[i].toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   357
        return sj.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * Returns a printable form of this RDN using the algorithm defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * RFC 1779. Only RFC 1779 attribute type keywords are emitted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public String toRFC1779String() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        return toRFC1779String(Collections.<String, String>emptyMap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Returns a printable form of this RDN using the algorithm defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * RFC 1779. RFC 1779 attribute type keywords are emitted, as well
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * as keywords contained in the OID/keyword map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public String toRFC1779String(Map<String, String> oidMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        if (assertion.length == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            return assertion[0].toRFC1779String(oidMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   378
        StringJoiner sj = new StringJoiner(" + ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        for (int i = 0; i < assertion.length; i++) {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   380
            sj.add(assertion[i].toRFC1779String(oidMap));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   382
        return sj.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * Returns a printable form of this RDN using the algorithm defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * RFC 2253. Only RFC 2253 attribute type keywords are emitted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    public String toRFC2253String() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        return toRFC2253StringInternal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            (false, Collections.<String, String>emptyMap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * Returns a printable form of this RDN using the algorithm defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * RFC 2253. RFC 2253 attribute type keywords are emitted, as well as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * keywords contained in the OID/keyword map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    public String toRFC2253String(Map<String, String> oidMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        return toRFC2253StringInternal(false, oidMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * Returns a printable form of this RDN using the algorithm defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * RFC 2253. Only RFC 2253 attribute type keywords are emitted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * If canonical is true, then additional canonicalizations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * documented in X500Principal.getName are performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    public String toRFC2253String(boolean canonical) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        if (canonical == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            return toRFC2253StringInternal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                (false, Collections.<String, String>emptyMap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        String c = canonicalString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            c = toRFC2253StringInternal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                (true, Collections.<String, String>emptyMap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            canonicalString = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    private String toRFC2253StringInternal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        (boolean canonical, Map<String, String> oidMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
         * Section 2.2: When converting from an ASN.1 RelativeDistinguishedName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
         * to a string, the output consists of the string encodings of each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
         * AttributeTypeAndValue (according to 2.3), in any order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
         * Where there is a multi-valued RDN, the outputs from adjoining
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
         * AttributeTypeAndValues are separated by a plus ('+' ASCII 43)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
         * character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        // normally, an RDN only contains one AVA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if (assertion.length == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            return canonical ? assertion[0].toRFC2253CanonicalString() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                               assertion[0].toRFC2253String(oidMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
35283
c5082624b79f 8074068: Cleanup in java.base/share/classes/sun/security/x509/
igerasim
parents: 31426
diff changeset
   441
        AVA[] toOutput = assertion;
c5082624b79f 8074068: Cleanup in java.base/share/classes/sun/security/x509/
igerasim
parents: 31426
diff changeset
   442
        if (canonical) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            // order the string type AVA's alphabetically,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            // followed by the oid type AVA's numerically
35283
c5082624b79f 8074068: Cleanup in java.base/share/classes/sun/security/x509/
igerasim
parents: 31426
diff changeset
   445
            toOutput = assertion.clone();
c5082624b79f 8074068: Cleanup in java.base/share/classes/sun/security/x509/
igerasim
parents: 31426
diff changeset
   446
            Arrays.sort(toOutput, AVAComparator.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
35283
c5082624b79f 8074068: Cleanup in java.base/share/classes/sun/security/x509/
igerasim
parents: 31426
diff changeset
   448
        StringJoiner sj = new StringJoiner("+");
c5082624b79f 8074068: Cleanup in java.base/share/classes/sun/security/x509/
igerasim
parents: 31426
diff changeset
   449
        for (AVA ava : toOutput) {
c5082624b79f 8074068: Cleanup in java.base/share/classes/sun/security/x509/
igerasim
parents: 31426
diff changeset
   450
            sj.add(canonical ? ava.toRFC2253CanonicalString()
c5082624b79f 8074068: Cleanup in java.base/share/classes/sun/security/x509/
igerasim
parents: 31426
diff changeset
   451
                             : ava.toRFC2253String(oidMap));
c5082624b79f 8074068: Cleanup in java.base/share/classes/sun/security/x509/
igerasim
parents: 31426
diff changeset
   452
        }
c5082624b79f 8074068: Cleanup in java.base/share/classes/sun/security/x509/
igerasim
parents: 31426
diff changeset
   453
        return sj.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
class AVAComparator implements Comparator<AVA> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    private static final Comparator<AVA> INSTANCE = new AVAComparator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    private AVAComparator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    static Comparator<AVA> getInstance() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        return INSTANCE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * AVA's containing a standard keyword are ordered alphabetically,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * followed by AVA's containing an OID keyword, ordered numerically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    public int compare(AVA a1, AVA a2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        boolean a1Has2253 = a1.hasRFC2253Keyword();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        boolean a2Has2253 = a2.hasRFC2253Keyword();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        if (a1Has2253 == a2Has2253) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            return a1.toRFC2253CanonicalString().compareTo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                        (a2.toRFC2253CanonicalString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            if (a1Has2253) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
}