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 11, 2023
1 parent 6c1e44c commit 12b4109
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
48 changes: 24 additions & 24 deletions ballerina/tests/private_public_key_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ isolated function testParseEncryptedPrivateKeyFromP12() returns Error? {
password: "ballerina"
};
PrivateKey result = check decodeRsaPrivateKeyFromKeyStore(keyStore, "ballerina", "ballerina");
test:assertEquals(result["algorithm"], "RSA");
test:assertEquals(result.algorithm, "RSA");
}

@test:Config {}
Expand Down Expand Up @@ -85,13 +85,13 @@ isolated function testReadPrivateKeyFromP12WithInvalidKeyPassword() {
@test:Config {}
isolated function testParsePrivateKeyFromKeyFile() returns Error? {
PrivateKey result = check decodeRsaPrivateKeyFromKeyFile(PRIVATE_KEY_PATH);
test:assertEquals(result["algorithm"], "RSA");
test:assertEquals(result.algorithm, "RSA");
}

@test:Config {}
isolated function testParseEncryptedPrivateKeyFromKeyFile() returns Error? {
PrivateKey result = check decodeRsaPrivateKeyFromKeyFile(ENCRYPTED_PRIVATE_KEY_PATH, "ballerina");
test:assertEquals(result["algorithm"], "RSA");
test:assertEquals(result.algorithm, "RSA");
}

@test:Config {}
Expand All @@ -117,7 +117,7 @@ isolated function testParseEncryptedPrivateKeyFromKeyFileWithNoPassword() {
@test:Config {}
isolated function testParseEncryptedPrivateKeyFromKeyPairFile() returns Error? {
PrivateKey result = check decodeRsaPrivateKeyFromKeyFile(ENCRYPTED_KEY_PAIR_PATH, "ballerina");
test:assertEquals(result["algorithm"], "RSA");
test:assertEquals(result.algorithm, "RSA");
}

@test:Config {}
Expand All @@ -143,13 +143,13 @@ isolated function testParseEncryptedPrivateKeyFromKeyPairFileWithNoPassword() {
@test:Config {}
isolated function testParsePrivateKeyFromKeyPairFile() returns Error? {
PrivateKey result = check decodeRsaPrivateKeyFromKeyFile(KEY_PAIR_PATH);
test:assertEquals(result["algorithm"], "RSA");
test:assertEquals(result.algorithm, "RSA");
}

@test:Config {}
isolated function testParseEcPrivateKeyFromKeyFile() returns Error? {
PrivateKey result = check decodeEcPrivateKeyFromKeyFile(EC_PRIVATE_KEY_PATH);
test:assertEquals(result["algorithm"], "ECDSA");
test:assertEquals(result.algorithm, "ECDSA");
}

@test:Config {}
Expand Down Expand Up @@ -189,13 +189,13 @@ isolated function testParsePublicKeyFromP12() returns Error? {
password: "ballerina"
};
PublicKey publicKey = check decodeRsaPublicKeyFromTrustStore(trustStore, "ballerina");
test:assertEquals(publicKey["algorithm"], "RSA");
Certificate certificate = <Certificate>publicKey["certificate"];
test:assertEquals(publicKey.algorithm, "RSA");
Certificate certificate = <Certificate>publicKey.certificate;

string serial = (<int>certificate["serial"]).toString();
string issuer = <string>certificate["issuer"];
string subject = <string>certificate["subject"];
string signingAlgorithm = <string>certificate["signingAlgorithm"];
string serial = (<int>certificate.serial).toString();
string issuer = <string>certificate.issuer;
string subject = <string>certificate.subject;
string signingAlgorithm = <string>certificate.signingAlgorithm;

test:assertEquals(serial, "2097012467");
test:assertEquals(issuer, "CN=localhost,OU=WSO2,O=WSO2,L=Mountain View,ST=CA,C=US");
Expand Down Expand Up @@ -248,13 +248,13 @@ isolated function testReadPublicKeyFromP12WithInvalidAlias() {
@test:Config {}
isolated function testParsePublicKeyFromX509CertFile() returns Error? {
PublicKey publicKey = check decodeRsaPublicKeyFromCertFile(X509_PUBLIC_CERT_PATH);
test:assertEquals(publicKey["algorithm"], "RSA");
Certificate certificate = <Certificate>publicKey["certificate"];
test:assertEquals(publicKey.algorithm, "RSA");
Certificate certificate = <Certificate>publicKey.certificate;

string serial = (<int>certificate["serial"]).toString();
string issuer = <string>certificate["issuer"];
string subject = <string>certificate["subject"];
string signingAlgorithm = <string>certificate["signingAlgorithm"];
string serial = (<int>certificate.serial).toString();
string issuer = <string>certificate.issuer;
string subject = <string>certificate.subject;
string signingAlgorithm = <string>certificate.signingAlgorithm;

test:assertEquals(serial, "2097012467");
test:assertEquals(issuer, "CN=localhost,OU=WSO2,O=WSO2,L=Mountain View,ST=CA,C=US");
Expand All @@ -265,13 +265,13 @@ isolated function testParsePublicKeyFromX509CertFile() returns Error? {
@test:Config {}
isolated function testParseEcPublicKeyFromX509CertFile() returns Error? {
PublicKey publicKey = check decodeEcPublicKeyFromCertFile(EC_CERT_PATH);
test:assertEquals(publicKey["algorithm"], "EC");
Certificate certificate = <Certificate>publicKey["certificate"];
test:assertEquals(publicKey.algorithm, "EC");
Certificate certificate = <Certificate>publicKey.certificate;

string serial = (<int>certificate["serial"]).toString();
string issuer = <string>certificate["issuer"];
string subject = <string>certificate["subject"];
string signingAlgorithm = <string>certificate["signingAlgorithm"];
string serial = (<int>certificate.serial).toString();
string issuer = <string>certificate.issuer;
string subject = <string>certificate.subject;
string signingAlgorithm = <string>certificate.signingAlgorithm;

test:assertEquals(serial, "813081972327485475");
test:assertEquals(issuer, "CN=sigstore-intermediate,O=sigstore.dev");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ private static Object getPrivateKey(BString keyFilePath, Object keyPassword) {
return CryptoUtils.createError("Failed to parse private key information from: " +
keyFilePath.getValue());
}
PrivateKey privateKey = converter.getPrivateKey(privateKeyInfo);
return privateKey;
return converter.getPrivateKey(privateKeyInfo);
} catch (FileNotFoundException e) {
return CryptoUtils.createError("Key file not found at: " + privateKeyFile.getAbsoluteFile());
} catch (PKCSException | IOException e) {
Expand Down

0 comments on commit 12b4109

Please sign in to comment.