Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/security/Signature/TestCloneable.java
41152 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 signature objects which are cloneable
28
* implement the Cloneable interface
29
* @run testng TestCloneable
30
*/
31
import java.security.NoSuchProviderException;
32
import java.security.NoSuchAlgorithmException;
33
import java.security.Signature;
34
import org.testng.annotations.DataProvider;
35
import org.testng.annotations.Test;
36
import org.testng.Assert;
37
38
public class TestCloneable {
39
40
private static final Class<CloneNotSupportedException> CNSE =
41
CloneNotSupportedException.class;
42
43
@DataProvider
44
public Object[][] testData() {
45
return new Object[][] {
46
{ "SHA1withDSA", "SUN" }, { "NONEwithDSA", "SUN" },
47
{ "SHA224withDSA", "SUN" }, { "SHA256withDSA", "SUN" },
48
{ "EdDSA", "SunEC" }, { "Ed25519", "SunEC" }, { "Ed448", "SunEC" },
49
{ "SHA1withECDSA", "SunEC" }, { "SHA224withECDSA", "SunEC" },
50
{ "SHA256withECDSA", "SunEC" }, { "SHA384withECDSA", "SunEC" },
51
{ "SHA512withECDSA", "SunEC" }, { "NONEwithECDSA", "SunEC" },
52
{ "MD2withRSA", "SunRsaSign" }, { "MD5withRSA", "SunRsaSign" },
53
{ "SHA1withRSA", "SunRsaSign" }, { "SHA224withRSA", "SunRsaSign" },
54
{ "SHA256withRSA", "SunRsaSign" },
55
{ "SHA384withRSA", "SunRsaSign" },
56
{ "SHA512withRSA", "SunRsaSign" },
57
{ "SHA512/224withRSA", "SunRsaSign" },
58
{ "SHA512/256withRSA", "SunRsaSign" },
59
{ "RSASSA-PSS", "SunRsaSign" },
60
{ "NONEwithRSA", "SunMSCAPI" },
61
{ "SHA1withRSA", "SunMSCAPI" }, { "SHA256withRSA", "SunMSCAPI" },
62
{ "SHA384withRSA", "SunMSCAPI" }, { "SHA512withRSA", "SunMSCAPI" },
63
{ "RSASSA-PSS", "SunMSCAPI" },
64
{ "MD5withRSA", "SunMSCAPI" }, { "MD2withRSA", "SunMSCAPI" },
65
{ "SHA1withECDSA", "SunMSCAPI" },
66
{ "SHA224withECDSA", "SunMSCAPI" },
67
{ "SHA256withECDSA", "SunMSCAPI" },
68
{ "SHA384withECDSA", "SunMSCAPI" },
69
{ "SHA512withECDSA", "SunMSCAPI" }
70
};
71
}
72
73
@Test(dataProvider = "testData")
74
public void test(String algo, String provName)
75
throws NoSuchAlgorithmException, CloneNotSupportedException {
76
System.out.print("Testing " + algo + " impl from " + provName);
77
try {
78
Signature sig = Signature.getInstance(algo, provName);
79
if (sig instanceof Cloneable) {
80
System.out.println(": Cloneable");
81
Signature sig2 = (Signature) sig.clone();
82
Assert.assertEquals(sig2.getAlgorithm(), algo);
83
Assert.assertEquals(sig2.getProvider().getName(), provName);
84
Assert.assertTrue(sig2 instanceof Cloneable);
85
} else {
86
System.out.println(": NOT Cloneable");
87
Assert.assertThrows(CNSE, ()->sig.clone());
88
}
89
System.out.println("Test Passed");
90
} catch (NoSuchProviderException nspe) {
91
// skip testing
92
System.out.println("Skip " + provName + " - not available");
93
}
94
}
95
}
96
97