Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/util/misc/SetNullSigParams.java
38854 views
1
/*
2
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 8214096 8216039
27
* @summary Make sure SignatureUtil can accept null algorithm parameters
28
*/
29
import java.security.*;
30
import java.security.spec.AlgorithmParameterSpec;
31
import sun.security.util.SignatureUtil;
32
33
public class SetNullSigParams {
34
35
public static void main(String[] args) throws Exception {
36
Signature sig = new SpecialSigImpl();
37
SignatureUtil.initVerifyWithParam(sig, (PublicKey) null, null);
38
SignatureUtil.initSignWithParam(sig, null, null, null);
39
}
40
41
// Sample Signature impl class which simulates 3rd party provider behavior
42
// and throws NPE when given null algorithm parameters
43
// For max backward-compatibility, sun.security.util.SignatureUtil class
44
// now calls setParameter() only when algorithm parameters is non-null
45
private static class SpecialSigImpl extends Signature {
46
SpecialSigImpl() {
47
super("ANY");
48
}
49
@Override
50
protected void engineInitVerify(PublicKey publicKey)
51
throws InvalidKeyException {}
52
@Override
53
protected void engineInitSign(PrivateKey privateKey)
54
throws InvalidKeyException {}
55
@Override
56
protected void engineUpdate(byte b) throws SignatureException {}
57
@Override
58
protected void engineUpdate(byte[] b, int off, int len)
59
throws SignatureException {}
60
@Override
61
protected byte[] engineSign() throws SignatureException { return null; }
62
@Override
63
protected boolean engineVerify(byte[] sigBytes)
64
throws SignatureException { return false; }
65
@Override
66
protected void engineSetParameter(String param, Object value)
67
throws InvalidParameterException {}
68
@Override
69
protected void engineSetParameter(AlgorithmParameterSpec params)
70
throws InvalidAlgorithmParameterException {
71
if (params == null) throw new NullPointerException("Test Failed");
72
}
73
@Override
74
protected Object engineGetParameter(String param)
75
throws InvalidParameterException { return null; }
76
}
77
}
78
79