SignatureGetAlgorithm.java revision 7390:116050227ee9
190075Sobrien/* 2169689Skan * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3132718Skan * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 490075Sobrien * 590075Sobrien * This code is free software; you can redistribute it and/or modify it 690075Sobrien * under the terms of the GNU General Public License version 2 only, as 790075Sobrien * published by the Free Software Foundation. 890075Sobrien * 990075Sobrien * This code is distributed in the hope that it will be useful, but WITHOUT 1090075Sobrien * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1190075Sobrien * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1290075Sobrien * version 2 for more details (a copy is included in the LICENSE file that 1390075Sobrien * accompanied this code). 1490075Sobrien * 1590075Sobrien * You should have received a copy of the GNU General Public License version 1690075Sobrien * 2 along with this work; if not, write to the Free Software Foundation, 1790075Sobrien * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1890075Sobrien * 19169689Skan * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20169689Skan * or visit www.oracle.com if you need additional information or have any 2190075Sobrien * questions. 2290075Sobrien */ 2390075Sobrien 2490075Sobrien/* 2590075Sobrien * Portions Copyright (c) 2013 IBM Corporation 2690075Sobrien */ 2790075Sobrien 2890075Sobrien/* 2990075Sobrien * @test 3090075Sobrien * @bug 8014620 3190075Sobrien * @summary Signature.getAlgorithm return null in special case 3290075Sobrien * @run main/othervm SignatureGetAlgorithm 33169689Skan * @author youdwei 34169689Skan */ 35169689Skanimport java.security.*; 36169689Skan 37169689Skanpublic class SignatureGetAlgorithm { 38169689Skan 39169689Skan public static void main(String[] args) throws Exception { 40169689Skan Provider testProvider = new TestProvider(); 41132718Skan Security.addProvider(testProvider); 4290075Sobrien Signature sig = Signature.getInstance("MySignatureAlg"); 4390075Sobrien String algorithm = sig.getAlgorithm(); 4490075Sobrien System.out.println("Algorithm Name: " + algorithm); 45117395Skan if (algorithm == null) { 4690075Sobrien throw new Exception("algorithm name should be 'MySignatureAlg'"); 47 } 48 } 49 50 public static class TestProvider extends Provider { 51 TestProvider() { 52 super("test", 1.0, "test"); 53 put("Signature.MySignatureAlg", 54 "SignatureGetAlgorithm$MySignatureAlg"); 55 } 56 } 57 58 public static class MySignatureAlg extends Signature { 59 60 public MySignatureAlg() { 61 super(null); 62 } 63 64 MySignatureAlg(String s) { 65 super(s); 66 } 67 68 @Override 69 protected void engineInitVerify(PublicKey publicKey) 70 throws InvalidKeyException { 71 } 72 73 @Override 74 protected void engineInitSign(PrivateKey privateKey) 75 throws InvalidKeyException { 76 } 77 78 @Override 79 protected void engineUpdate(byte b) throws SignatureException { 80 } 81 82 @Override 83 protected void engineUpdate(byte[] b, int off, int len) 84 throws SignatureException { 85 } 86 87 @Override 88 protected byte[] engineSign() 89 throws SignatureException { 90 return new byte[0]; 91 } 92 93 @Override 94 protected boolean engineVerify(byte[] sigBytes) 95 throws SignatureException { 96 return false; 97 } 98 99 @Override 100 @Deprecated 101 protected void engineSetParameter(String param, Object value) 102 throws InvalidParameterException { 103 } 104 105 @Override 106 @Deprecated 107 protected Object engineGetParameter(String param) 108 throws InvalidParameterException { 109 return null; 110 } 111 } 112} 113