Skip to content

Commit

Permalink
Address review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhashinee committed Dec 5, 2023
1 parent b854d9f commit 6f1b573
Showing 1 changed file with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,8 +74,7 @@ private Decode() {}
public static Object decodeRsaPrivateKeyFromKeyStore(BMap<BString, BString> 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;
Expand All @@ -86,8 +84,7 @@ public static Object decodeEcPrivateKeyFromKeyStore(BMap<BString, BString> 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;

Check warning on line 90 in native/src/main/java/io/ballerina/stdlib/crypto/nativeimpl/Decode.java

View check run for this annotation

Codecov / codecov/patch

native/src/main/java/io/ballerina/stdlib/crypto/nativeimpl/Decode.java#L90

Added line #L90 was not covered by tests
Expand Down Expand Up @@ -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<BString, BString> 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<BString, BString> 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;

Check warning on line 199 in native/src/main/java/io/ballerina/stdlib/crypto/nativeimpl/Decode.java

View check run for this annotation

Codecov / codecov/patch

native/src/main/java/io/ballerina/stdlib/crypto/nativeimpl/Decode.java#L199

Added line #L199 was not covered by tests
}
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 6f1b573

Please sign in to comment.