From 6f1b5734ec97d4e3a5a4e254f44fe11bf72a1202 Mon Sep 17 00:00:00 2001 From: bhashinee Date: Tue, 5 Dec 2023 11:00:13 +0530 Subject: [PATCH] Address review suggestions --- .../stdlib/crypto/nativeimpl/Decode.java | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/native/src/main/java/io/ballerina/stdlib/crypto/nativeimpl/Decode.java b/native/src/main/java/io/ballerina/stdlib/crypto/nativeimpl/Decode.java index db4d41b4..059a2905 100644 --- a/native/src/main/java/io/ballerina/stdlib/crypto/nativeimpl/Decode.java +++ b/native/src/main/java/io/ballerina/stdlib/crypto/nativeimpl/Decode.java @@ -20,7 +20,6 @@ import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.utils.StringUtils; -import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BString; import io.ballerina.stdlib.crypto.Constants; @@ -75,8 +74,7 @@ private Decode() {} public static Object decodeRsaPrivateKeyFromKeyStore(BMap keyStoreRecord, BString keyAlias, BString keyPassword) { Object decodedPrivateKey = getPrivateKey(keyStoreRecord, keyAlias, keyPassword); - if (decodedPrivateKey instanceof PrivateKey) { - PrivateKey privateKey = (PrivateKey) decodedPrivateKey; + if (decodedPrivateKey instanceof PrivateKey privateKey) { return buildRsPrivateKeyRecord(privateKey); } return decodedPrivateKey; @@ -86,8 +84,7 @@ public static Object decodeEcPrivateKeyFromKeyStore(BMap keySt BString keyPassword) { Object decodedPrivateKey = getPrivateKey(keyStoreRecord, keyAlias, keyPassword); - if (decodedPrivateKey instanceof PrivateKey) { - PrivateKey privateKey = (PrivateKey) decodedPrivateKey; + if (decodedPrivateKey instanceof PrivateKey privateKey) { return buildEcPrivateKeyRecord(privateKey); } return decodedPrivateKey; @@ -182,23 +179,22 @@ private static Object getPrivateKeyRecord(PrivateKey privateKey) { private static Object buildEcPrivateKeyRecord(PrivateKey privateKey) { if (privateKey.getAlgorithm().equals(Constants.EC_ALGORITHM)) { return getPrivateKeyRecord(privateKey); - } else { - return CryptoUtils.createError("Not a valid EC key"); } + return CryptoUtils.createError("Not a valid EC key"); } public static Object decodeRsaPublicKeyFromTrustStore(BMap trustStoreRecord, BString keyAlias) { Object certificate = getPublicKey(trustStoreRecord, keyAlias); - if (certificate instanceof Certificate) { - return buildRsaPublicKeyRecord((Certificate) certificate); + if (certificate instanceof Certificate publicKey) { + return buildRsaPublicKeyRecord(publicKey); } return certificate; } public static Object decodeEcPublicKeyFromTrustStore(BMap trustStoreRecord, BString keyAlias) { Object certificate = getPublicKey(trustStoreRecord, keyAlias); - if (certificate instanceof Certificate) { - return buildEcPublicKeyRecord((Certificate) certificate); + if (certificate instanceof Certificate publicKey) { + return buildEcPublicKeyRecord(publicKey); } return certificate; } @@ -320,8 +316,4 @@ public static Object buildRsaPublicKey(BString modulus, BString exponent) { return CryptoUtils.createError("Algorithm of the key factory is not found: " + e.getMessage()); } } - - public static Object generateBCryptHash(BArray input, int cost) { - return new Object(); - } }