z-kovacs commented on code in PR #20542: URL: https://github.com/apache/pulsar/pull/20542#discussion_r1229305412
########## bouncy-castle/bc-common/src/test/java/org/apache/pulsar/client/impl/crypto/WrappingVersusEncryptionCrossCompatibilityTestBase.java: ########## @@ -0,0 +1,236 @@ +/* + * 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.pulsar.client.impl.crypto; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.testng.AssertJUnit.assertEquals; +import com.google.common.collect.ImmutableMap; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Paths; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.spec.InvalidKeySpecException; +import java.util.Optional; +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKey; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.SecretKeySpec; +import org.apache.commons.io.FileUtils; +import org.apache.pulsar.client.api.PulsarClientException; +import org.apache.pulsar.common.util.SecurityUtility; +import org.hamcrest.Matcher; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +public abstract class WrappingVersusEncryptionCrossCompatibilityTestBase { + + //from https://stackoverflow.com/a/140861 + //TODO use java.format.HexFormat after we move to java17 language features + protected static byte[] hexStringToByteArray(String s/* s must be an even-length string. */) { Review Comment: good shout, fixed ########## bouncy-castle/bc-common/src/main/java/org/apache/pulsar/client/impl/crypto/BcVersionSpecificCryptoUtilityFactory.java: ########## @@ -0,0 +1,48 @@ +/* + * 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.pulsar.client.impl.crypto; + +import java.lang.reflect.InvocationTargetException; +import org.apache.pulsar.common.util.SecurityUtility; + +class BcVersionSpecificCryptoUtilityFactory { + + static BcVersionSpecificCryptoUtility createNewInstance() { + String providerName = SecurityUtility.getProvider().getName(); + try { + switch (providerName) { + case SecurityUtility.BC: + return (BcVersionSpecificCryptoUtility) BcVersionSpecificCryptoUtility.class.getClassLoader() + .loadClass("org.apache.pulsar.client.impl.crypto.bc.BCNonFipsSpecificUtility") + .getConstructor() + .newInstance(); + case SecurityUtility.BC_FIPS: + return (BcVersionSpecificCryptoUtility) BcVersionSpecificCryptoUtility.class.getClassLoader() + .loadClass("org.apache.pulsar.client.impl.bcfips.BCFipsSpecificUtility") + .getConstructor().newInstance(); + default: + throw new IllegalStateException( + "Provider not handled for BC Specific delegate creation: " + providerName); + } + } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException Review Comment: good shout, fixed -- 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]
