Skip to content

Conversation

@johnpeck-us-ibm
Copy link
Member

@johnpeck-us-ibm johnpeck-us-ibm commented Dec 11, 2025

Add Check for PQCPrivateKey in Decapsulator and add tests for invalid keys.

Signed-off-by: John Peck [email protected]

Copy link
Member

@jasonkatonica jasonkatonica left a comment

Choose a reason for hiding this comment

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

Some tests are also failing with the following unused variables:

Error:  /home/runner/work/OpenJCEPlus/OpenJCEPlus/src/test/java/ibm/jceplus/junit/base/BaseTestKEM.java:190:16: Unused local variable 'encr'. [UnusedLocalVariable]
Error:  /home/runner/work/OpenJCEPlus/OpenJCEPlus/src/test/java/ibm/jceplus/junit/base/BaseTestKEM.java:197:16: Unused local variable 'decr'. [UnusedLocalVariable]
Error:  /home/runner/work/OpenJCEPlus/OpenJCEPlus/src/test/java/ibm/jceplus/junit/base/BaseTestKEM.java:208:16: Unused local variable 'encr'. [UnusedLocalVariable]
Error:  /home/runner/work/OpenJCEPlus/OpenJCEPlus/src/test/java/ibm/jceplus/junit/base/BaseTestKEM.java:215:16: Unused local variable 'decr'. [UnusedLocalVariable]

Copy link
Member

@jasonkatonica jasonkatonica left a comment

Choose a reason for hiding this comment

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

LGTM


PublicKey pubKey = publicKey;
if (pubKey == null) {
throw new InvalidKeyException("unsupported key");
Copy link
Member

Choose a reason for hiding this comment

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

Should we change the exception message here, since in this case the key is missing rather than being unsupported?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated

PrivateKey privKey = privateKey;

if (privKey == null) {
throw new InvalidKeyException("unsupported key");
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated

Comment on lines 194 to 210
// Test null keys
PublicKey pub = null;
PrivateKey priv = null;

try {
kem.newEncapsulator(pub);
fail("testKEMKeys failed - NULL Public key did not cause an Invalid Key Excepton.");
} catch (InvalidKeyException ike) {
assertTrue(ike.getMessage().equals("unsupported key"));
}

try {
kem.newDecapsulator(priv);
fail("testKEMKeys failed - NULL Private key did not cause an Invalid Key Excepton.");
} catch (InvalidKeyException ike) {
assertTrue(ike.getMessage().equals("unsupported key"));
}
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to separate this into another test method?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is doing testing of the keys and we really expect the same Exception. So, I don't thing it needs to be broken up.

@johnpeck-us-ibm johnpeck-us-ibm deleted the PQCKEMPrivKeyCheck branch January 8, 2026 16:53
@johnpeck-us-ibm johnpeck-us-ibm restored the PQCKEMPrivKeyCheck branch January 8, 2026 21:51
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