gnodet commented on code in PR #31349:
URL: https://github.com/apache/camel/pull/31349#discussion_r4798565532


##########
components/camel-pqc/src/main/java/org/apache/camel/component/pqc/lifecycle/KeyAlgorithmSupport.java:
##########
@@ -114,6 +109,9 @@ public static String getAlgorithmName(String algorithm) {
      * The default parameter set for the given algorithm, or {@code null} when 
it has none.
      */
     public static AlgorithmParameterSpec getDefaultParameterSpec(String 
algorithm) {
+        if (algorithm == null) {

Review Comment:
   The null check here is unreachable from `generateKeyPair()` because 
`determineProvider(algorithm)` at line 56 would throw NPE first. Consider 
either removing this check or adding it at the entry point of 
`generateKeyPair()` before calling `determineProvider()`.
   
   _Claude Code on behalf of Guillaume Nodet_



##########
components/camel-pqc/src/test/java/org/apache/camel/component/pqc/lifecycle/KeyAlgorithmSupportTest.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.pqc.lifecycle;
+
+import java.security.KeyPair;
+import java.security.Security;
+
+import org.apache.camel.component.pqc.PQCKeyEncapsulationAlgorithms;
+import org.apache.camel.component.pqc.PQCSignatureAlgorithms;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class KeyAlgorithmSupportTest {
+
+    @BeforeAll
+    static void startup() {
+        if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
+            Security.addProvider(new BouncyCastleProvider());
+        }
+        if (Security.getProvider(BouncyCastlePQCProvider.PROVIDER_NAME) == 
null) {
+            Security.addProvider(new BouncyCastlePQCProvider());
+        }
+    }
+
+    @ParameterizedTest
+    @EnumSource(PQCSignatureAlgorithms.class)
+    void signatureAlgorithmsHaveDefaultParameterSpec(PQCSignatureAlgorithms 
algorithm) {
+        
assertNotNull(KeyAlgorithmSupport.getDefaultParameterSpec(algorithm.name()),
+                "Expected non-null default parameter spec for signature 
algorithm " + algorithm.name());
+    }
+
+    @ParameterizedTest
+    @EnumSource(PQCKeyEncapsulationAlgorithms.class)
+    void kemAlgorithmsHaveDefaultParameterSpec(PQCKeyEncapsulationAlgorithms 
algorithm) {
+        
assertNotNull(KeyAlgorithmSupport.getDefaultParameterSpec(algorithm.name()),
+                "Expected non-null default parameter spec for KEM algorithm " 
+ algorithm.name());
+    }
+
+    @ParameterizedTest
+    @ValueSource(strings = { "MAYO", "SNOVA" })
+    void generateKeyPairWithoutExplicitSpecSucceeds(String algorithm) throws 
Exception {
+        KeyPair keyPair = KeyAlgorithmSupport.generateKeyPair(algorithm, null);
+        assertNotNull(keyPair);
+        assertNotNull(keyPair.getPublic());
+        assertNotNull(keyPair.getPrivate());
+    }
+
+    @Test
+    void unmappedAlgorithmWithoutSpecThrowsIllegalArgumentException() throws 
Exception {

Review Comment:
   The RSA test may pass without the fix because standard JDK implementations 
already throw `InvalidParameterException` (which extends 
`IllegalArgumentException`) when calling `initialize(256)` on RSA. 
   
   Consider asserting 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"));
   ```
   
   _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]

Reply via email to