Skip to content

Commit e60d8b5

Browse files
author
Valerie Peng
committed
8253176: Signature.getParameters should specify that it can throw UnsupportedOperationException
Reviewed-by: weijun
1 parent aa50625 commit e60d8b5

File tree

2 files changed

+58
-56
lines changed

2 files changed

+58
-56
lines changed

src/java.base/share/classes/java/security/Signature.java

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -518,11 +518,11 @@ public final void initVerify(PublicKey publicKey)
518518
* of this call.
519519
*
520520
* @param publicKey the public key of the identity whose signature is
521-
* going to be verified.
522-
* @param params the parameters used for verifying this signature.
521+
* going to be verified
522+
* @param params the parameters used for verifying this signature object
523523
*
524-
* @throws InvalidKeyException if the key is invalid.
525-
* @throws InvalidAlgorithmParameterException if the params is invalid.
524+
* @throws InvalidKeyException if the key is invalid
525+
* @throws InvalidAlgorithmParameterException if the params is invalid
526526
*/
527527
final void initVerify(PublicKey publicKey, AlgorithmParameterSpec params)
528528
throws InvalidKeyException, InvalidAlgorithmParameterException {
@@ -598,13 +598,13 @@ public final void initVerify(Certificate certificate)
598598
* {@code InvalidKeyException} is thrown.
599599
*
600600
* @param certificate the certificate of the identity whose signature is
601-
* going to be verified.
602-
* @param params the parameters used for verifying this signature.
601+
* going to be verified
602+
* @param params the parameters used for verifying this signature object
603603
*
604604
* @throws InvalidKeyException if the public key in the certificate
605605
* is not encoded properly or does not include required parameter
606-
* information or cannot be used for digital signature purposes.
607-
* @throws InvalidAlgorithmParameterException if the params is invalid.
606+
* information or cannot be used for digital signature purposes
607+
* @throws InvalidAlgorithmParameterException if the params is invalid
608608
*
609609
* @since 13
610610
*/
@@ -647,9 +647,9 @@ public final void initSign(PrivateKey privateKey)
647647
* of this call.
648648
*
649649
* @param privateKey the private key of the identity whose signature
650-
* is going to be generated.
650+
* is going to be generated
651651
*
652-
* @param random the source of randomness for this signature.
652+
* @param random the source of randomness for this signature object
653653
*
654654
* @throws InvalidKeyException if the key is invalid.
655655
*/
@@ -670,11 +670,11 @@ public final void initSign(PrivateKey privateKey, SecureRandom random)
670670
* of this call.
671671
*
672672
* @param privateKey the private key of the identity whose signature
673-
* is going to be generated.
674-
* @param params the parameters used for generating signature.
675-
* @param random the source of randomness for this signature.
673+
* is going to be generated
674+
* @param params the parameters used for generating signature
675+
* @param random the source of randomness for this signature object
676676
*
677-
* @throws InvalidKeyException if the key is invalid.
677+
* @throws InvalidKeyException if the key is invalid
678678
* @throws InvalidAlgorithmParameterException if the params is invalid
679679
*/
680680
final void initSign(PrivateKey privateKey,
@@ -967,11 +967,11 @@ public String toString() {
967967
* naming scheme for each parameter is desirable but left unspecified
968968
* at this time.
969969
*
970-
* @param param the string identifier of the parameter.
971-
* @param value the parameter value.
970+
* @param param the string identifier of the parameter
971+
* @param value the parameter value
972972
*
973973
* @throws InvalidParameterException if {@code param} is an
974-
* invalid parameter for this signature algorithm engine,
974+
* invalid parameter for this signature object,
975975
* the parameter is already set
976976
* and cannot be set again, a security exception occurs, and so on.
977977
*
@@ -988,12 +988,12 @@ public final void setParameter(String param, Object value)
988988
}
989989

990990
/**
991-
* Initializes this signature engine with the specified parameter set.
991+
* Initializes this signature object with the specified parameter values.
992992
*
993-
* @param params the parameters
993+
* @param params the parameter values
994994
*
995-
* @throws InvalidAlgorithmParameterException if the given parameters
996-
* are inappropriate for this signature engine
995+
* @throws InvalidAlgorithmParameterException if the given parameter values
996+
* are inappropriate for this signature object
997997
*
998998
* @see #getParameters
999999
*/
@@ -1005,17 +1005,20 @@ public final void setParameter(AlgorithmParameterSpec params)
10051005
/**
10061006
* Returns the parameters used with this signature object.
10071007
*
1008-
* <p> If this signature has been initialized with parameters
1009-
* (by calling {@link #setParameter(AlgorithmParameterSpec)} or
1010-
* {@link #setParameter(String, Object)}) and the underlying signature
1011-
* implementation supports returning the parameters as
1012-
* {@code AlgorithmParameters}, this method returns the same parameters.
1013-
* If the parameters were not set, this method may return a combination
1014-
* of default and randomly generated parameter values if the
1015-
* underlying signature implementation supports it and can successfully
1016-
* generate them. Otherwise, {@code null} is returned.
1017-
*
1018-
* @return the parameters used with this signature, or {@code null}
1008+
* <p>The returned parameters may be the same that were used to initialize
1009+
* this signature object, or may contain additional default or random
1010+
* parameter values used by the underlying signature scheme. If the required
1011+
* parameters were not supplied and can be generated by the signature
1012+
* object, the generated parameters are returned; otherwise {@code null} is
1013+
* returned.
1014+
*
1015+
* <p>However, if the signature scheme does not support returning
1016+
* the parameters as {@code AlgorithmParameters}, {@code null} is always
1017+
* returned.
1018+
*
1019+
* @return the parameters used with this signature object, or {@code null}
1020+
* @throws UnsupportedOperationException if the provider does not support
1021+
* this method
10191022
*
10201023
* @see #setParameter(AlgorithmParameterSpec)
10211024
* @since 1.4

src/java.base/share/classes/java/security/SignatureSpi.java

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -81,7 +81,7 @@ protected abstract void engineInitVerify(PublicKey publicKey)
8181
*
8282
* @param publicKey the public key of the identity whose signature is
8383
* going to be verified.
84-
* @param params the parameters for generating this signature
84+
* @param params the parameters for verifying this signature object
8585
*
8686
* @throws InvalidKeyException if the key is improperly
8787
* encoded, does not work with the given parameters, and so on.
@@ -145,7 +145,7 @@ protected void engineInitSign(PrivateKey privateKey,
145145
*
146146
* @param privateKey the private key of the identity whose signature
147147
* will be generated.
148-
* @param params the parameters for generating this signature
148+
* @param params the parameters for generating signature
149149
* @param random the source of randomness
150150
*
151151
* @throws InvalidKeyException if the key is improperly
@@ -358,7 +358,7 @@ protected boolean engineVerify(byte[] sigBytes, int offset, int length)
358358
* @param value the parameter value.
359359
*
360360
* @throws InvalidParameterException if {@code param} is an
361-
* invalid parameter for this signature algorithm engine,
361+
* invalid parameter for this signature object,
362362
* the parameter is already set
363363
* and cannot be set again, a security exception occurs, and so on.
364364
*
@@ -371,8 +371,7 @@ protected abstract void engineSetParameter(String param, Object value)
371371
throws InvalidParameterException;
372372

373373
/**
374-
* <p>This method is overridden by providers to initialize
375-
* this signature engine with the specified parameter set.
374+
* Initializes this signature object with the specified parameter values.
376375
*
377376
* @param params the parameters
378377
*
@@ -381,31 +380,31 @@ protected abstract void engineSetParameter(String param, Object value)
381380
*
382381
* @throws InvalidAlgorithmParameterException if this method is
383382
* overridden by a provider and the given parameters
384-
* are inappropriate for this signature engine
383+
* are inappropriate for this signature object
385384
*/
386385
protected void engineSetParameter(AlgorithmParameterSpec params)
387386
throws InvalidAlgorithmParameterException {
388387
throw new UnsupportedOperationException();
389388
}
390389

391390
/**
392-
* <p>This method is overridden by providers to return the parameters
393-
* used with this signature engine.
394-
*
395-
* <p> If this signature engine has been initialized with parameters
396-
* (by calling {@link #engineSetParameter(AlgorithmParameterSpec)} or
397-
* {@link #engineSetParameter(String, Object)}) and the underlying signature
398-
* implementation supports returning the parameters as
399-
* {@code AlgorithmParameters}, this method returns the same parameters.
400-
* If the parameters were not set, this method may return a combination
401-
* of default and randomly generated parameter values if the
402-
* underlying signature implementation supports it and can successfully
403-
* generate them. Otherwise, {@code null} is returned.
404-
*
405-
* @return the parameters used with this signature engine, or {@code null}
406-
*
407-
* @throws UnsupportedOperationException if this method is
408-
* not overridden by a provider
391+
* Returns the parameters used with this signature object.
392+
*
393+
* <p>The returned parameters may be the same that were used to initialize
394+
* this signature object, or may contain additional default or random
395+
* parameter values used by the underlying signature scheme. If the required
396+
* parameters were not supplied and can be generated by the signature
397+
* object, the generated parameters are returned; otherwise {@code null} is
398+
* returned.
399+
*
400+
* <p>However, if the signature scheme does not support returning
401+
* the parameters as {@code AlgorithmParameters}, {@code null} is always
402+
* returned.
403+
*
404+
* @return the parameters used with this signature object, or {@code null}
405+
*
406+
* @throws UnsupportedOperationException if this method is not overridden
407+
* by a provider
409408
* @since 1.4
410409
*/
411410
protected AlgorithmParameters engineGetParameters() {

0 commit comments

Comments
 (0)