Path: blob/master/test/jdk/java/security/Signature/TestCloneable.java
41152 views
/*1* Copyright (c) 2020, 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* @bug 824607726* @summary Make sure that signature objects which are cloneable27* implement the Cloneable interface28* @run testng TestCloneable29*/30import java.security.NoSuchProviderException;31import java.security.NoSuchAlgorithmException;32import java.security.Signature;33import org.testng.annotations.DataProvider;34import org.testng.annotations.Test;35import org.testng.Assert;3637public class TestCloneable {3839private static final Class<CloneNotSupportedException> CNSE =40CloneNotSupportedException.class;4142@DataProvider43public Object[][] testData() {44return new Object[][] {45{ "SHA1withDSA", "SUN" }, { "NONEwithDSA", "SUN" },46{ "SHA224withDSA", "SUN" }, { "SHA256withDSA", "SUN" },47{ "EdDSA", "SunEC" }, { "Ed25519", "SunEC" }, { "Ed448", "SunEC" },48{ "SHA1withECDSA", "SunEC" }, { "SHA224withECDSA", "SunEC" },49{ "SHA256withECDSA", "SunEC" }, { "SHA384withECDSA", "SunEC" },50{ "SHA512withECDSA", "SunEC" }, { "NONEwithECDSA", "SunEC" },51{ "MD2withRSA", "SunRsaSign" }, { "MD5withRSA", "SunRsaSign" },52{ "SHA1withRSA", "SunRsaSign" }, { "SHA224withRSA", "SunRsaSign" },53{ "SHA256withRSA", "SunRsaSign" },54{ "SHA384withRSA", "SunRsaSign" },55{ "SHA512withRSA", "SunRsaSign" },56{ "SHA512/224withRSA", "SunRsaSign" },57{ "SHA512/256withRSA", "SunRsaSign" },58{ "RSASSA-PSS", "SunRsaSign" },59{ "NONEwithRSA", "SunMSCAPI" },60{ "SHA1withRSA", "SunMSCAPI" }, { "SHA256withRSA", "SunMSCAPI" },61{ "SHA384withRSA", "SunMSCAPI" }, { "SHA512withRSA", "SunMSCAPI" },62{ "RSASSA-PSS", "SunMSCAPI" },63{ "MD5withRSA", "SunMSCAPI" }, { "MD2withRSA", "SunMSCAPI" },64{ "SHA1withECDSA", "SunMSCAPI" },65{ "SHA224withECDSA", "SunMSCAPI" },66{ "SHA256withECDSA", "SunMSCAPI" },67{ "SHA384withECDSA", "SunMSCAPI" },68{ "SHA512withECDSA", "SunMSCAPI" }69};70}7172@Test(dataProvider = "testData")73public void test(String algo, String provName)74throws NoSuchAlgorithmException, CloneNotSupportedException {75System.out.print("Testing " + algo + " impl from " + provName);76try {77Signature sig = Signature.getInstance(algo, provName);78if (sig instanceof Cloneable) {79System.out.println(": Cloneable");80Signature sig2 = (Signature) sig.clone();81Assert.assertEquals(sig2.getAlgorithm(), algo);82Assert.assertEquals(sig2.getProvider().getName(), provName);83Assert.assertTrue(sig2 instanceof Cloneable);84} else {85System.out.println(": NOT Cloneable");86Assert.assertThrows(CNSE, ()->sig.clone());87}88System.out.println("Test Passed");89} catch (NoSuchProviderException nspe) {90// skip testing91System.out.println("Skip " + provName + " - not available");92}93}94}959697