Skip to content

Throw correct InvalidParameterException from Cipher.init() on unsupported mode#143

Merged
rlm2002 merged 1 commit intowolfSSL:masterfrom
cconlon:CipherInitMode
Aug 21, 2025
Merged

Throw correct InvalidParameterException from Cipher.init() on unsupported mode#143
rlm2002 merged 1 commit intowolfSSL:masterfrom
cconlon:CipherInitMode

Conversation

@cconlon
Copy link
Member

@cconlon cconlon commented Aug 20, 2025

This PR adjusts the exception type thrown by Cipher.init() if an unsupported or incorrect mode is passed in. It was previously InvalidKeyException, but should be InvalidParameterException to match what consumers will expect.

This fixes the OpenJDK SunJCE test: crypto/Cipher/TestCipherMode.java

@cconlon cconlon self-assigned this Aug 20, 2025
@cconlon cconlon requested a review from Copilot August 20, 2025 22:30
@cconlon cconlon changed the title JCE: throw correct InvalidParameterException from Cipher.init() on unsupported mode Throw correct InvalidParameterException from Cipher.init() on unsupported mode Aug 20, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an incorrect exception type in the WolfCrypt JCE provider's Cipher implementation. When an invalid mode is passed to Cipher.init(), the code now throws InvalidParameterException instead of InvalidKeyException to comply with JCE specification expectations.

  • Changed exception type from InvalidKeyException to InvalidParameterException in wolfCryptSetDirection() method
  • Added test case to verify the correct exception is thrown for invalid cipher modes
  • Added necessary import for InvalidParameterException in both files

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/main/java/com/wolfssl/provider/jce/WolfCryptCipher.java Updated exception type and added import for InvalidParameterException
src/test/java/com/wolfssl/provider/jce/test/WolfCryptCipherTest.java Added test case and import to verify correct exception behavior

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@cconlon cconlon assigned rlm2002 and unassigned cconlon Aug 20, 2025
rlm2002
rlm2002 previously approved these changes Aug 21, 2025
@rlm2002 rlm2002 merged commit 85e4a43 into wolfSSL:master Aug 21, 2025
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants