src/java.base/share/classes/sun/security/x509/RFC822Name.java
author redestad
Thu, 13 Dec 2018 15:31:05 +0100
changeset 53018 8bf9268df0e2
parent 52856 5f3b9b633731
child 53082 4c539cb11633
permissions -rw-r--r--
8215281: Use String.isEmpty() when applicable in java.base Reviewed-by: dfuchs, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 10369
diff changeset
     2
 * Copyright (c) 1997, 2011, 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;
6122
16fa7ed7ff1b 6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents: 5506
diff changeset
    29
import java.util.Locale;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * This class implements the RFC822Name as required by the GeneralNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * ASN.1 object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @author Amit Kapoor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @see GeneralName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @see GeneralNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @see GeneralNameInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class RFC822Name implements GeneralNameInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * Create the RFC822Name object from the passed encoded Der value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * @param derValue the encoded DER RFC822Name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * @exception IOException on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public RFC822Name(DerValue derValue) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        name = derValue.getIA5String();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        parseName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * Create the RFC822Name object with the specified name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @param name the RFC822Name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @throws IOException on invalid input name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public RFC822Name(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        parseName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Parse an RFC822Name string to see if it is a valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * addr-spec according to IETF RFC822 and RFC2459:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * [local-part@]domain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * local-part@ could be empty for an RFC822Name NameConstraint,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * but the domain at least must be non-empty.  Case is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * significant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param name the RFC822Name string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @throws IOException if name is not valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public void parseName(String name) throws IOException {
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 52856
diff changeset
    82
        if (name == null || name.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            throw new IOException("RFC822Name may not be null or empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        // See if domain is a valid domain name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        String domain = name.substring(name.indexOf('@')+1);
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 52856
diff changeset
    87
        if (domain.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            throw new IOException("RFC822Name may not end with @");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            //An RFC822 NameConstraint could start with a ., although
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            //a DNSName may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            if (domain.startsWith(".")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                if (domain.length() == 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                    throw new IOException("RFC822Name domain may not be just .");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Return the type of the GeneralName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public int getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return (GeneralNameInterface.NAME_RFC822);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Return the actual name value of the GeneralName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Encode the RFC822 name into the DerOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @param out the DER stream to encode the RFC822Name to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @exception IOException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public void encode(DerOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        out.putIA5String(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Convert the name into user readable string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        return ("RFC822Name: " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Compares this name with another, for equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @return true iff the names are equivalent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * according to RFC2459.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (this == obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if (!(obj instanceof RFC822Name))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        RFC822Name other = (RFC822Name)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        // RFC2459 mandates that these names are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        // not case-sensitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return name.equalsIgnoreCase(other.name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Returns the hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @return a hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public int hashCode() {
10369
e9d2e59e53f0 7059542: JNDI name operations should be locale independent
xuelei
parents: 6122
diff changeset
   156
        return name.toUpperCase(Locale.ENGLISH).hashCode();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Return constraint type:<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *   <li>NAME_DIFF_TYPE = -1: input name is different type from name (i.e. does not constrain)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *   <li>NAME_MATCH = 0: input name matches name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *   <li>NAME_NARROWS = 1: input name narrows name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *   <li>NAME_WIDENS = 2: input name widens name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *   <li>NAME_SAME_TYPE = 3: input name does not match or narrow name, but is same type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * </ul>.  These results are used in checking NameConstraints during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * certification path verification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * [RFC2459]    When the subjectAltName extension contains an Internet mail address,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * the address MUST be included as an rfc822Name. The format of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * rfc822Name is an "addr-spec" as defined in RFC 822 [RFC 822]. An
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * addr-spec has the form "local-part@domain". Note that an addr-spec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * has no phrase (such as a common name) before it, has no comment (text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * surrounded in parentheses) after it, and is not surrounded by "&lt;" and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * "&gt;". Note that while upper and lower case letters are allowed in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * RFC 822 addr-spec, no significance is attached to the case.
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   177
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @param inputName to be checked for being constrained
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   179
     * @return constraint type above
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @throws UnsupportedOperationException if name is not exact match, but narrowing and widening are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *          not supported for this name type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public int constrains(GeneralNameInterface inputName) throws UnsupportedOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        int constraintType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (inputName == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            constraintType = NAME_DIFF_TYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        else if (inputName.getType() != (GeneralNameInterface.NAME_RFC822)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            constraintType = NAME_DIFF_TYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            //RFC2459 specifies that case is not significant in RFC822Names
6122
16fa7ed7ff1b 6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents: 5506
diff changeset
   191
            String inName =
16fa7ed7ff1b 6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents: 5506
diff changeset
   192
                (((RFC822Name)inputName).getName()).toLowerCase(Locale.ENGLISH);
16fa7ed7ff1b 6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents: 5506
diff changeset
   193
            String thisName = name.toLowerCase(Locale.ENGLISH);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            if (inName.equals(thisName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                constraintType = NAME_MATCH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            } else if (thisName.endsWith(inName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                /* if both names contain @, then they had to match exactly */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                if (inName.indexOf('@') != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    constraintType = NAME_SAME_TYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                } else if (inName.startsWith(".")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                    constraintType = NAME_WIDENS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    int inNdx = thisName.lastIndexOf(inName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    if (thisName.charAt(inNdx-1) == '@' ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                        constraintType = NAME_WIDENS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                        constraintType = NAME_SAME_TYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            } else if (inName.endsWith(thisName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                /* if thisName contains @, then they had to match exactly */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                if (thisName.indexOf('@') != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    constraintType = NAME_SAME_TYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                } else if (thisName.startsWith(".")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    constraintType = NAME_NARROWS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                    int ndx = inName.lastIndexOf(thisName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    if (inName.charAt(ndx-1) == '@') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                        constraintType = NAME_NARROWS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                        constraintType = NAME_SAME_TYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                constraintType = NAME_SAME_TYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return constraintType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Return subtree depth of this name for purposes of determining
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * NameConstraints minimum and maximum bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   235
     * @return distance of name from root
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @throws UnsupportedOperationException if not supported for this name type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public int subtreeDepth() throws UnsupportedOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        String subtree=name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        int i=1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        /* strip off name@ portion */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        int atNdx = subtree.lastIndexOf('@');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        if (atNdx >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            subtree=subtree.substring(atNdx+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
52856
5f3b9b633731 8213952: Relax DNSName restriction as per RFC 1123
coffeys
parents: 47216
diff changeset
   249
        /* count dots in DNSName, adding one if DNSName preceded by @ */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        for (; subtree.lastIndexOf('.') >= 0; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            subtree=subtree.substring(0,subtree.lastIndexOf('.'));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
}