Path: blob/master/test/jdk/java/security/Signature/NoProvider.java
41149 views
/*1* Copyright (c) 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* @test25* @bug 816575126* @summary Verify that that a subclass of Signature that does not contain a27* provider can be used to verify.28* @run main/othervm -Djava.security.debug=provider NoProvider29*/3031import java.security.*;3233public class NoProvider {3435private static class NoProviderPublicKey implements PublicKey {3637public String getAlgorithm() {38return "NoProvider";39}40public String getFormat() {41return "none";42}43public byte[] getEncoded() {44return new byte[1];45}46}4748private static class NoProviderSignature extends Signature {4950public NoProviderSignature() {51super("NoProvider");52}5354protected void engineInitVerify(PublicKey publicKey)55throws InvalidKeyException {56// do nothing57}5859protected void engineInitSign(PrivateKey privateKey)60throws InvalidKeyException {61// do nothing62}6364protected void engineUpdate(byte b) throws SignatureException {65// do nothing66}6768protected void engineUpdate(byte[] b, int off, int len)69throws SignatureException {70// do nothing71}7273protected byte[] engineSign() throws SignatureException {74return new byte[1];75}7677protected boolean engineVerify(byte[] sigBytes)78throws SignatureException {79return false;80}8182@Deprecated83protected void engineSetParameter(String param, Object value)84throws InvalidParameterException {85// do nothing86}8788@Deprecated89protected Object engineGetParameter(String param)90throws InvalidParameterException {91return null;92}93}9495public static void main(String[] args) throws Exception {96new NoProviderSignature().initVerify(new NoProviderPublicKey());97}98}99100101