RFR: 8302017: Allocate BadPaddingException only if it will be thrown [v2]

Anthony Scarpino ascarpino at openjdk.org
Fri Jul 14 05:14:08 UTC 2023


On Wed, 12 Jul 2023 23:12:18 GMT, Valerie Peng <valeriep at openjdk.org> wrote:

>> This change refactors the RSAPadding class to return an output record containing the status instead of relying on exception object to indicate a failure.
>> 
>> Thanks in advance for review~
>> Valerie
>
> Valerie Peng has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Address review feedbacks, e.g. Removed RSAPadding.Output and use byte[] as before.

src/java.base/share/classes/com/sun/crypto/provider/RSACipher.java line 349:

> 347:         byte[] result = null;
> 348:         try {
> 349:             switch (mode) {

Nothing wrong what you did here, but since you used the new style switch elsewhere, you could do:

return switch(mode) {
    case MODE_SIGN -> {
            paddingCopy = padding.pad(buffer, 0, bufOfs);
            if (paddingCopy == null) {
                throw new BadPaddingException("Padding error in signing");
            }
            yield RSACore.rsa(paddingCopy, privateKey, true);
     }

... and so on...

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/14839#discussion_r1263293856


More information about the security-dev mailing list