jdk/src/share/classes/sun/security/x509/OtherName.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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.lang.reflect.Constructor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * This class represents the OtherName as required by the GeneralNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * ASN.1 object. It supplies the generic framework to allow specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Other Name types, and also provides minimal support for unrecognized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Other Name types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * The ASN.1 definition for OtherName is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * OtherName ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *     type-id    OBJECT IDENTIFIER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *     value      [0] EXPLICIT ANY DEFINED BY type-id
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public class OtherName implements GeneralNameInterface {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private ObjectIdentifier oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private byte[] nameValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private GeneralNameInterface gni = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static final byte TAG_VALUE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private int myhash = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * Create the OtherName object from a passed ObjectIdentfier and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * byte array name value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @param oid ObjectIdentifier of this OtherName object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * @param value the DER-encoded value of the OtherName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public OtherName(ObjectIdentifier oid, byte[] value) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        if (oid == null || value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            throw new NullPointerException("parameters may not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        this.oid = oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        this.nameValue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        gni = getGNI(oid, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        if (gni != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            name = gni.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            name = "Unrecognized ObjectIdentifier: " + oid.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Create the OtherName object from the passed encoded Der value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param derValue the encoded DER OtherName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @exception IOException on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public OtherName(DerValue derValue) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        DerInputStream in = derValue.toDerInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        oid = in.getOID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        DerValue val = in.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        nameValue = val.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        gni = getGNI(oid, nameValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (gni != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            name = gni.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            name = "Unrecognized ObjectIdentifier: " + oid.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
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
     * Get ObjectIdentifier
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
        //XXXX May want to consider cloning this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        return oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Get name value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public byte[] getNameValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        return nameValue.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Get GeneralNameInterface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private GeneralNameInterface getGNI(ObjectIdentifier oid, byte[] nameValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            Class extClass = OIDMap.getClass(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            if (extClass == null) {   // Unsupported OtherName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            Class[] params = { Object.class };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            Constructor cons = ((Class<?>)extClass).getConstructor(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            Object[] passed = new Object[] { nameValue };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            GeneralNameInterface gni =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                       (GeneralNameInterface)cons.newInstance(passed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            return gni;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            throw (IOException)new IOException("Instantiation error: " + e).initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Return the type of the GeneralName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public int getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        return GeneralNameInterface.NAME_ANY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Encode the Other name into the DerOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param out the DER stream to encode the Other-Name to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @exception IOException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public void encode(DerOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (gni != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            // This OtherName has a supported class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            gni.encode(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            // This OtherName has no supporting class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            tmp.putOID(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_VALUE), nameValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            out.write(DerValue.tag_Sequence, tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Compares this name with another, for equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @return true iff the names are identical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public boolean equals(Object other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        if (this == other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if (!(other instanceof OtherName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        OtherName otherOther = (OtherName)other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (!(otherOther.oid.equals(oid))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        GeneralNameInterface otherGNI = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            otherGNI = getGNI(otherOther.oid, otherOther.nameValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        boolean result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (otherGNI != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                result = (otherGNI.constrains(this) == NAME_MATCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            } catch (UnsupportedOperationException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                result = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            result = Arrays.equals(nameValue, otherOther.nameValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Returns the hash code for this OtherName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @return a hash code value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (myhash == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            myhash = 37 + oid.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            for (int i = 0; i < nameValue.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                myhash = 37 * myhash + nameValue[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return myhash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Convert the name into user readable string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        return "Other-Name: " + name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Return type of constraint inputName places on this name:<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *   <li>NAME_DIFF_TYPE = -1: input name is different type from name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *       (i.e. does not constrain).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *   <li>NAME_MATCH = 0: input name matches name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *   <li>NAME_NARROWS = 1: input name narrows name (is lower in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *       naming subtree)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *   <li>NAME_WIDENS = 2: input name widens name (is higher in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *       naming subtree)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *   <li>NAME_SAME_TYPE = 3: input name does not match or narrow name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *       but is same type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * </ul>.  These results are used in checking NameConstraints during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * certification path verification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @param inputName to be checked for being constrained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @returns constraint type above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @throws UnsupportedOperationException if name is same type, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *         comparison operations are not supported for this name type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public int constrains(GeneralNameInterface inputName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        int constraintType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (inputName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            constraintType = NAME_DIFF_TYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        } else if (inputName.getType() != NAME_ANY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            constraintType = NAME_DIFF_TYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            throw new UnsupportedOperationException("Narrowing, widening, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                + "and matching are not supported for OtherName.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return constraintType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * Return subtree depth of this name for purposes of determining
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * NameConstraints minimum and maximum bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @returns distance of name from root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @throws UnsupportedOperationException if not supported for this name type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public int subtreeDepth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        throw new UnsupportedOperationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            ("subtreeDepth() not supported for generic OtherName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
}