Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/util/misc/SetNullSigParams.java
38854 views
/*1* Copyright (c) 2018, 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 8214096 821603926* @summary Make sure SignatureUtil can accept null algorithm parameters27*/28import java.security.*;29import java.security.spec.AlgorithmParameterSpec;30import sun.security.util.SignatureUtil;3132public class SetNullSigParams {3334public static void main(String[] args) throws Exception {35Signature sig = new SpecialSigImpl();36SignatureUtil.initVerifyWithParam(sig, (PublicKey) null, null);37SignatureUtil.initSignWithParam(sig, null, null, null);38}3940// Sample Signature impl class which simulates 3rd party provider behavior41// and throws NPE when given null algorithm parameters42// For max backward-compatibility, sun.security.util.SignatureUtil class43// now calls setParameter() only when algorithm parameters is non-null44private static class SpecialSigImpl extends Signature {45SpecialSigImpl() {46super("ANY");47}48@Override49protected void engineInitVerify(PublicKey publicKey)50throws InvalidKeyException {}51@Override52protected void engineInitSign(PrivateKey privateKey)53throws InvalidKeyException {}54@Override55protected void engineUpdate(byte b) throws SignatureException {}56@Override57protected void engineUpdate(byte[] b, int off, int len)58throws SignatureException {}59@Override60protected byte[] engineSign() throws SignatureException { return null; }61@Override62protected boolean engineVerify(byte[] sigBytes)63throws SignatureException { return false; }64@Override65protected void engineSetParameter(String param, Object value)66throws InvalidParameterException {}67@Override68protected void engineSetParameter(AlgorithmParameterSpec params)69throws InvalidAlgorithmParameterException {70if (params == null) throw new NullPointerException("Test Failed");71}72@Override73protected Object engineGetParameter(String param)74throws InvalidParameterException { return null; }75}76}777879