0N/A/*
2362N/A * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @author Gary Ellison
0N/A * @bug 4170635
0N/A * @summary Verify equals()/hashCode() contract honored
0N/A * @run main/othervm/policy=Allow.policy DerInputBufferEqualsHashCode
0N/A */
0N/A
0N/Aimport java.io.*;
0N/Aimport sun.security.util.*;
0N/Aimport sun.security.x509.*;
0N/Aimport java.lang.reflect.*;
0N/A
0N/A
0N/Apublic class DerInputBufferEqualsHashCode {
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A
0N/A String name1 = "CN=eve s. dropper";
0N/A DerOutputStream deros;
0N/A byte[] ba;
0N/A // encode
0N/A X500Name dn1 = new X500Name(name1);
0N/A
0N/A deros = new DerOutputStream();
0N/A dn1.encode(deros);
0N/A ba = deros.toByteArray();
0N/A
0N/A GetDIBConstructor a = new GetDIBConstructor();
0N/A java.security.AccessController.doPrivileged(a);
0N/A Constructor c = a.getCons();
0N/A
0N/A Object[] objs = new Object[1];
0N/A objs[0] = ba;
0N/A
0N/A Object db1 = null, db2 = null;
0N/A try {
0N/A db1 = c.newInstance(objs);
0N/A db2 = c.newInstance(objs);
0N/A } catch (Exception e) {
0N/A System.out.println("Caught unexpected exception " + e);
0N/A throw e;
0N/A }
0N/A
0N/A if ( (db1.equals(db2)) == (db1.hashCode()==db2.hashCode()) )
0N/A System.out.println("PASSED");
0N/A else
0N/A throw new Exception("FAILED equals()/hashCode() contract");
0N/A
0N/A }
0N/A}
0N/A
0N/A
0N/Aclass GetDIBConstructor implements java.security.PrivilegedExceptionAction {
0N/A
0N/A private Class dibClass = null;
0N/A private Constructor dibCons = null;
0N/A
0N/A public Object run() throws Exception {
0N/A try {
0N/A dibClass = Class.forName("sun.security.util.DerInputBuffer");
0N/A Constructor[] cons = dibClass.getDeclaredConstructors();
0N/A
0N/A int i;
0N/A for (i = 0; i < cons.length; i++) {
0N/A Class [] parms = cons[i].getParameterTypes();
0N/A if (parms.length == 1) {
0N/A if (parms[0].getName().equalsIgnoreCase("[B")) {
0N/A cons[i].setAccessible(true);
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A dibCons = cons[i];
0N/A } catch (Exception e) {
0N/A System.out.println("Caught unexpected exception " + e);
0N/A throw e;
0N/A }
0N/A return dibCons;
0N/A }
0N/A
0N/A public Constructor getCons(){
0N/A return dibCons;
0N/A }
0N/A
0N/A}