Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/util/DerInputBuffer/DerInputBufferEqualsHashCode.java
38853 views
1
/*
2
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @author Gary Ellison
27
* @bug 4170635
28
* @summary Verify equals()/hashCode() contract honored
29
* @run main/othervm/policy=Allow.policy DerInputBufferEqualsHashCode
30
*/
31
32
import java.io.*;
33
import sun.security.util.*;
34
import sun.security.x509.*;
35
import java.lang.reflect.*;
36
37
38
public class DerInputBufferEqualsHashCode {
39
40
public static void main(String[] args) throws Exception {
41
42
String name1 = "CN=eve s. dropper";
43
DerOutputStream deros;
44
byte[] ba;
45
// encode
46
X500Name dn1 = new X500Name(name1);
47
48
deros = new DerOutputStream();
49
dn1.encode(deros);
50
ba = deros.toByteArray();
51
52
GetDIBConstructor a = new GetDIBConstructor();
53
java.security.AccessController.doPrivileged(a);
54
Constructor c = a.getCons();
55
56
Object[] objs = new Object[1];
57
objs[0] = ba;
58
59
Object db1 = null, db2 = null;
60
try {
61
db1 = c.newInstance(objs);
62
db2 = c.newInstance(objs);
63
} catch (Exception e) {
64
System.out.println("Caught unexpected exception " + e);
65
throw e;
66
}
67
68
if ( (db1.equals(db2)) == (db1.hashCode()==db2.hashCode()) )
69
System.out.println("PASSED");
70
else
71
throw new Exception("FAILED equals()/hashCode() contract");
72
73
}
74
}
75
76
77
class GetDIBConstructor implements java.security.PrivilegedExceptionAction {
78
79
private Class dibClass = null;
80
private Constructor dibCons = null;
81
82
public Object run() throws Exception {
83
try {
84
dibClass = Class.forName("sun.security.util.DerInputBuffer");
85
Constructor[] cons = dibClass.getDeclaredConstructors();
86
87
int i;
88
for (i = 0; i < cons.length; i++) {
89
Class [] parms = cons[i].getParameterTypes();
90
if (parms.length == 1) {
91
if (parms[0].getName().equalsIgnoreCase("[B")) {
92
cons[i].setAccessible(true);
93
break;
94
}
95
}
96
}
97
dibCons = cons[i];
98
} catch (Exception e) {
99
System.out.println("Caught unexpected exception " + e);
100
throw e;
101
}
102
return dibCons;
103
}
104
105
public Constructor getCons(){
106
return dibCons;
107
}
108
109
}
110
111