src/java.base/share/classes/sun/security/x509/OIDName.java
author igerasim
Tue, 02 Oct 2018 10:19:07 -0700
changeset 51986 c1db377f6300
parent 47216 71c04702a3d5
child 53082 4c539cb11633
permissions -rw-r--r--
8200381: Typos in javadoc - missing verb "be" and alike Reviewed-by: lancea, darcy, wetmore
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: 30374
diff changeset
     2
 * Copyright (c) 1997, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * This class implements the OIDName as required by the GeneralNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * ASN.1 object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @author Amit Kapoor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @see GeneralName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @see GeneralNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @see GeneralNameInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class OIDName implements GeneralNameInterface {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     private ObjectIdentifier oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * Create the OIDName object from the passed encoded Der value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * @param derValue the encoded DER OIDName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * @exception IOException on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public OIDName(DerValue derValue) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        oid = derValue.getOID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * Create the OIDName object with the specified name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     *
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
    58
     * @param oid the OIDName.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public OIDName(ObjectIdentifier oid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        this.oid = oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Create the OIDName from the String form of the OID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @param name the OIDName in form "x.y.z..."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public OIDName(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            oid = new ObjectIdentifier(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            throw new IOException("Unable to create OIDName: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Return the type of the GeneralName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public int getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        return (GeneralNameInterface.NAME_OID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Encode the OID name into the DerOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param out the DER stream to encode the OIDName to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @exception IOException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public void encode(DerOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        out.putOID(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Convert the name into user readable string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return ("OIDName: " + oid.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Returns this OID name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public ObjectIdentifier getOID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Compares this name with another, for equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @return true iff the names are identical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (this == obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (!(obj instanceof OIDName))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        OIDName other = (OIDName)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
31426
9cd672654f97 8022444: Remove sun.security.util.ObjectIdentifier.equals(ObjectIdentifier other) method
juh
parents: 30374
diff changeset
   123
        return oid.equals(other.oid);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Returns the hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @return a hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return oid.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Return type of constraint inputName places on this name:<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *   <li>NAME_DIFF_TYPE = -1: input name is different type from name (i.e. does not constrain).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *   <li>NAME_MATCH = 0: input name matches name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *   <li>NAME_NARROWS = 1: input name narrows name (is lower in the naming subtree)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *   <li>NAME_WIDENS = 2: input name widens name (is higher in the naming subtree)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *   <li>NAME_SAME_TYPE = 3: input name does not match or narrow name, but is same type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * </ul>.  These results are used in checking NameConstraints during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * certification path verification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @param inputName to be checked for being constrained
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   146
     * @return constraint type above
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @throws UnsupportedOperationException if name is not exact match, but narrowing and widening are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *          not supported for this name type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public int constrains(GeneralNameInterface inputName) throws UnsupportedOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        int constraintType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (inputName == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            constraintType = NAME_DIFF_TYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        else if (inputName.getType() != NAME_OID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            constraintType = NAME_DIFF_TYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        else if (this.equals((OIDName)inputName))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            constraintType = NAME_MATCH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            //widens and narrows not defined in RFC2459 for OIDName (aka registeredID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            throw new UnsupportedOperationException("Narrowing and widening are not supported for OIDNames");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        return constraintType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Return subtree depth of this name for purposes of determining
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * NameConstraints minimum and maximum bounds and for calculating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * path lengths in name subtrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   169
     * @return distance of name from root
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @throws UnsupportedOperationException if not supported for this name type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public int subtreeDepth() throws UnsupportedOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        throw new UnsupportedOperationException("subtreeDepth() not supported for OIDName.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
}