Path: blob/master/test/jdk/java/security/Signature/SignatureGetAlgorithm.java
41149 views
/*1* Copyright (c) 2013, 2016, 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* Portions Copyright (c) 2013 IBM Corporation25*/2627/*28* @test29* @bug 8014620 813018130* @summary Signature.getAlgorithm return null in special case31* @run main/othervm SignatureGetAlgorithm32* @author youdwei33*/34import java.security.*;3536public class SignatureGetAlgorithm {3738public static void main(String[] args) throws Exception {39Provider testProvider = new TestProvider();40Security.addProvider(testProvider);41Signature sig = Signature.getInstance("MySignatureAlg");42String algorithm = sig.getAlgorithm();43System.out.println("Algorithm Name: " + algorithm);44if (algorithm == null) {45throw new Exception("algorithm name should be 'MySignatureAlg'");46}47}4849public static class TestProvider extends Provider {50TestProvider() {51super("testSignatureGetAlgorithm", "1.0", "test Signatures");52put("Signature.MySignatureAlg",53"SignatureGetAlgorithm$MySignatureAlg");54}55}5657public static class MySignatureAlg extends Signature {5859public MySignatureAlg() {60super(null);61}6263MySignatureAlg(String s) {64super(s);65}6667@Override68protected void engineInitVerify(PublicKey publicKey)69throws InvalidKeyException {70}7172@Override73protected void engineInitSign(PrivateKey privateKey)74throws InvalidKeyException {75}7677@Override78protected void engineUpdate(byte b) throws SignatureException {79}8081@Override82protected void engineUpdate(byte[] b, int off, int len)83throws SignatureException {84}8586@Override87protected byte[] engineSign()88throws SignatureException {89return new byte[0];90}9192@Override93protected boolean engineVerify(byte[] sigBytes)94throws SignatureException {95return false;96}9798@Override99@Deprecated100protected void engineSetParameter(String param, Object value)101throws InvalidParameterException {102}103104@Override105@Deprecated106protected Object engineGetParameter(String param)107throws InvalidParameterException {108return null;109}110}111}112113114