gnodet commented on PR #31349:
URL: https://github.com/apache/camel/pull/31349#issuecomment-7408758177
## Code Review
**Note:** This PR was closed and consolidated into #31350. This review is
for reference.
### Summary
The changes correctly add default parameter specs for MAYO and SNOVA
algorithms and replace the silent fallback to 256-bit key size with an explicit
exception. The implementation aligns with existing defaults in
`PQCDefaultMAYOMaterial` and `PQCDefaultSNOVAMaterial`.
### Findings
#### 1. ✅ Correct Default Parameter Specs
The added defaults match the existing material classes:
- MAYO → `mayo5` (line 125, matches `PQCDefaultMAYOMaterial.java:54`)
- SNOVA → `SNOVA_24_5_5_SHAKE_SSK` (line 127, matches
`PQCDefaultSNOVAMaterial.java:54`)
#### 2. ⚠️ Unreachable Null Guard (`KeyAlgorithmSupport.java:112-114`)
The null check for `algorithm` parameter is unreachable from
`generateKeyPair()` because `determineProvider(algorithm)` (line 56) would
throw NPE first. This guard has no effect unless the method is called directly
by external code.
**Recommendation:** Either remove the null check or add it at the entry
point of `generateKeyPair()` before calling `determineProvider()`.
#### 3. ⚠️ Test May Pass Without Fix (`KeyAlgorithmSupportTest.java:72-75`)
The RSA test with null spec already throws `InvalidParameterException`
(which extends `IllegalArgumentException`) in standard JDK implementations, so
the assertion may pass even without the fix. The test doesn't verify the new
error message.
**Recommendation:** Assert on the specific error message to ensure the test
validates the actual fix:
```java
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
() -> KeyAlgorithmSupport.generateKeyPair("RSA", null));
assertTrue(ex.getMessage().contains("No default parameter specification
configured"));
assertTrue(ex.getMessage().contains("RSA"));
```
#### 4. ⚠️ Breaking Change Needs Documentation
The removal of the 256-bit fallback is a breaking change. Algorithms like
"EC" that previously generated P-256 keys via `initialize(256)` will now fail
with `IllegalArgumentException`. This should be documented in the upgrade guide.
**Recommendation:** Add an entry to
`docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc` noting
this behavior change.
#### 5. ✅ Comprehensive Test Coverage
The parameterized tests using `@EnumSource` for all `PQCSignatureAlgorithms`
and `PQCKeyEncapsulationAlgorithms` members (lines 48-59) are excellent—they
will catch any future drift between the enum and default parameter mappings.
#### 6. ✅ Proper Exception Handling
The explicit `IllegalArgumentException` with algorithm name (lines 66-67 in
KeyAlgorithmSupport, similar in AWS/Hashicorp managers) is a significant
improvement over the silent fallback, making misconfiguration immediately
visible.
### Security Considerations
✅ No security concerns. The change improves fail-fast behavior for
misconfigured algorithms, which is a security improvement (fail closed vs fail
open).
### Code Quality
✅ Code is clean and well-tested. The only concern is the unreachable null
check and the test assertion that could be more specific.
---
_Claude Code on behalf of Guillaume Nodet_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]