Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/security/MessageDigest/TestCloneable.java
41149 views
1
/*
2
* Copyright (c) 2020, 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
* @bug 8246077
27
* @summary Make sure that digest spi and the resulting digest impl are
28
* consistent in the impl of Cloneable interface
29
* @run testng TestCloneable
30
*/
31
import java.security.*;
32
import java.util.Objects;
33
import org.testng.annotations.DataProvider;
34
import org.testng.annotations.Test;
35
import org.testng.Assert;
36
37
public class TestCloneable {
38
39
private static final Class<CloneNotSupportedException> CNSE =
40
CloneNotSupportedException.class;
41
42
@DataProvider
43
public Object[][] testData() {
44
return new Object[][] {
45
{ "MD2", "SUN" }, { "MD5", "SUN" }, { "SHA-1", "SUN" },
46
{ "SHA-224", "SUN" }, { "SHA-256", "SUN" },
47
{ "SHA-384", "SUN" }, { "SHA-512", "SUN" },
48
{ "SHA3-224", "SUN" }, { "SHA3-256", "SUN" },
49
{ "SHA3-384", "SUN" }, { "SHA3-512", "SUN" }
50
};
51
}
52
53
@Test(dataProvider = "testData")
54
public void test(String algo, String provName)
55
throws NoSuchProviderException, NoSuchAlgorithmException,
56
CloneNotSupportedException {
57
System.out.print("Testing " + algo + " impl from " + provName);
58
Provider p = Security.getProvider(provName);
59
Provider.Service s = p.getService("MessageDigest", algo);
60
Objects.requireNonNull(s);
61
MessageDigestSpi spi = (MessageDigestSpi) s.newInstance(null);
62
MessageDigest md = MessageDigest.getInstance(algo, provName);
63
if (spi instanceof Cloneable) {
64
System.out.println(": Cloneable");
65
Assert.assertTrue(md instanceof Cloneable);
66
MessageDigest md2 = (MessageDigest) md.clone();
67
Assert.assertEquals(md2.getAlgorithm(), algo);
68
Assert.assertEquals(md2.getProvider().getName(), provName);
69
Assert.assertTrue(md2 instanceof Cloneable);
70
} else {
71
System.out.println(": NOT Cloneable");
72
Assert.assertThrows(CNSE, ()->md.clone());
73
}
74
System.out.println("Test Passed");
75
}
76
}
77
78