jdk/src/share/classes/sun/security/x509/Extension.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 1997-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.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Arrays;
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
 * Represent a X509 Extension Attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>Extensions are additional attributes which can be inserted in a X509
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * v3 certificate. For example a "Driving License Certificate" could have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * the driving license number as a extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p>Extensions are represented as a sequence of the extension identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * (Object Identifier), a boolean flag stating whether the extension is to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * be treated as being critical and the extension value itself (this is again
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * a DER encoding of the extension value).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * ASN.1 definition of Extension:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Extension ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *      ExtensionId     OBJECT IDENTIFIER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *      critical        BOOLEAN DEFAULT FALSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *      extensionValue  OCTET STRING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * All subclasses need to implement a constructor of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *     <subclass> (Boolean, Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * where the Object is typically an array of DER encoded bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author Amit Kapoor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
public class Extension implements java.security.cert.Extension {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    protected ObjectIdentifier  extensionId = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    protected boolean           critical = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    protected byte[]            extensionValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Default constructor.  Used only by sub-classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public Extension() { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Constructs an extension from a DER encoded array of bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public Extension(DerValue derVal) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        DerInputStream in = derVal.toDerInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        // Object identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        extensionId = in.getOID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        // If the criticality flag was false, it will not have been encoded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        DerValue val = in.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        if (val.tag == DerValue.tag_Boolean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            critical = val.getBoolean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            // Extension value (DER encoded)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            val = in.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            extensionValue = val.getOctetString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            critical = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            extensionValue = val.getOctetString();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Constructs an Extension from individual components of ObjectIdentifier,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * criticality and the DER encoded OctetString.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @param extensionId the ObjectIdentifier of the extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @param critical the boolean indicating if the extension is critical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param extensionValue the DER encoded octet string of the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public Extension(ObjectIdentifier extensionId, boolean critical,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                     byte[] extensionValue) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        this.extensionId = extensionId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        this.critical = critical;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        // passed in a DER encoded octet string, strip off the tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        // and length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        DerValue inDerVal = new DerValue(extensionValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        this.extensionValue = inDerVal.getOctetString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Constructs an Extension from another extension. To be used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * creating decoded subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @param ext the extension to create from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public Extension(Extension ext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        this.extensionId = ext.extensionId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        this.critical = ext.critical;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        this.extensionValue = ext.extensionValue;
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
     * Constructs an Extension from individual components of ObjectIdentifier,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * criticality and the raw encoded extension value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @param extensionId the ObjectIdentifier of the extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @param critical the boolean indicating if the extension is critical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @param rawExtensionValue the raw DER-encoded extension value (this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * is not the encoded OctetString).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public static Extension newExtension(ObjectIdentifier extensionId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        boolean critical, byte[] rawExtensionValue) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        Extension ext = new Extension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        ext.extensionId = extensionId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        ext.critical = critical;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        ext.extensionValue = rawExtensionValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        return ext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public void encode(OutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (out == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        DerOutputStream dos1 = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        DerOutputStream dos2 = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        dos1.putOID(extensionId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (critical) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            dos1.putBoolean(critical);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        dos1.putOctetString(extensionValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        dos2.write(DerValue.tag_Sequence, dos1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        out.write(dos2.toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Write the extension to the DerOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @param out the DerOutputStream to write the extension to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @exception IOException on encoding errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public void encode(DerOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (extensionId == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            throw new IOException("Null OID to encode for the extension!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        if (extensionValue == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            throw new IOException("No value to encode for the extension!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        DerOutputStream dos = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        dos.putOID(extensionId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if (critical)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            dos.putBoolean(critical);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        dos.putOctetString(extensionValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        out.write(DerValue.tag_Sequence, dos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Returns true if extension is critical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public boolean isCritical() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        return critical;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Returns the ObjectIdentifier of the extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public ObjectIdentifier getExtensionId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return extensionId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public byte[] getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        return extensionValue.clone();
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 extension value as an byte array for further processing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Note, this is the raw DER value of the extension, not the DER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * encoded octet string which is in the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * This method does not return a clone; it is the responsibility of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * caller to clone the array if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public byte[] getExtensionValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        return extensionValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public String getId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return extensionId.toString();
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
     * Returns the Extension in user readable form.
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
        String s = "ObjectId: " + extensionId.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (critical) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            s += " Criticality=true\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            s += " Criticality=false\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return (s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    // Value to mix up the hash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    private static final int hashMagic = 31;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Returns a hashcode value for this Extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @return the hashcode value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        int h = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        if (extensionValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            byte[] val = extensionValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            int len = val.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            while (len > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                h += len * val[--len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        h = h * hashMagic + extensionId.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        h = h * hashMagic + (critical?1231:1237);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Compares this Extension for equality with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * object. If the <code>other</code> object is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * <code>instanceof</code> <code>Extension</code>, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * its encoded form is retrieved and compared with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * encoded form of this Extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @param other the object to test for equality with this Extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @return true iff the other object is of type Extension, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * criticality flag, object identifier and encoded extension value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * the two Extensions match, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public boolean equals(Object other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        if (this == other)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        if (!(other instanceof Extension))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        Extension otherExt = (Extension) other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if (critical != otherExt.critical)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        if (!extensionId.equals(otherExt.extensionId))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return Arrays.equals(extensionValue, otherExt.extensionValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
}