Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/util/DerInputBuffer/DerInputBufferEqualsHashCode.java
38853 views
/*1* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @author Gary Ellison26* @bug 417063527* @summary Verify equals()/hashCode() contract honored28* @run main/othervm/policy=Allow.policy DerInputBufferEqualsHashCode29*/3031import java.io.*;32import sun.security.util.*;33import sun.security.x509.*;34import java.lang.reflect.*;353637public class DerInputBufferEqualsHashCode {3839public static void main(String[] args) throws Exception {4041String name1 = "CN=eve s. dropper";42DerOutputStream deros;43byte[] ba;44// encode45X500Name dn1 = new X500Name(name1);4647deros = new DerOutputStream();48dn1.encode(deros);49ba = deros.toByteArray();5051GetDIBConstructor a = new GetDIBConstructor();52java.security.AccessController.doPrivileged(a);53Constructor c = a.getCons();5455Object[] objs = new Object[1];56objs[0] = ba;5758Object db1 = null, db2 = null;59try {60db1 = c.newInstance(objs);61db2 = c.newInstance(objs);62} catch (Exception e) {63System.out.println("Caught unexpected exception " + e);64throw e;65}6667if ( (db1.equals(db2)) == (db1.hashCode()==db2.hashCode()) )68System.out.println("PASSED");69else70throw new Exception("FAILED equals()/hashCode() contract");7172}73}747576class GetDIBConstructor implements java.security.PrivilegedExceptionAction {7778private Class dibClass = null;79private Constructor dibCons = null;8081public Object run() throws Exception {82try {83dibClass = Class.forName("sun.security.util.DerInputBuffer");84Constructor[] cons = dibClass.getDeclaredConstructors();8586int i;87for (i = 0; i < cons.length; i++) {88Class [] parms = cons[i].getParameterTypes();89if (parms.length == 1) {90if (parms[0].getName().equalsIgnoreCase("[B")) {91cons[i].setAccessible(true);92break;93}94}95}96dibCons = cons[i];97} catch (Exception e) {98System.out.println("Caught unexpected exception " + e);99throw e;100}101return dibCons;102}103104public Constructor getCons(){105return dibCons;106}107108}109110111