Skip to content

Commit

Permalink
Fix build failures
Browse files Browse the repository at this point in the history
  • Loading branch information
hwupathum committed Mar 19, 2024
1 parent cde030f commit 934432b
Showing 1 changed file with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,36 +322,56 @@ private static Object getPublicKey(BMap<BString, BString> trustStoreRecord, BStr
}

public static Object decodeRsaPublicKeyFromCertFile(BString certFilePath) {
X509Certificate certificate = (X509Certificate) getCertificateFromFile(certFilePath);
return buildRsaPublicKeyRecord(certificate);
File certFile = new File(certFilePath.getValue());
try (FileInputStream fileInputStream = new FileInputStream(certFile)) {
CertificateFactory certificateFactory = CertificateFactory.getInstance(Constants.CERTIFICATE_TYPE_X509);
X509Certificate certificate = (X509Certificate) certificateFactory.generateCertificate(fileInputStream);
return buildRsaPublicKeyRecord(certificate);
} catch (FileNotFoundException e) {
return CryptoUtils.createError("Certificate file not found at: " + certFile.getAbsolutePath());
} catch (CertificateException | IOException e) {
return CryptoUtils.createError("Unable to do public key operations: " + e.getMessage());
}
}

public static Object decodeEcPublicKeyFromCertFile(BString certFilePath) {
X509Certificate certificate = (X509Certificate) getCertificateFromFile(certFilePath);
return buildEcPublicKeyRecord(certificate);
File certFile = new File(certFilePath.getValue());
try (FileInputStream fileInputStream = new FileInputStream(certFile)) {
CertificateFactory certificateFactory = CertificateFactory.getInstance(Constants.CERTIFICATE_TYPE_X509);
X509Certificate certificate = (X509Certificate) certificateFactory.generateCertificate(fileInputStream);
return buildEcPublicKeyRecord(certificate);
} catch (FileNotFoundException e) {
return CryptoUtils.createError("Certificate file not found at: " + certFile.getAbsolutePath());
} catch (CertificateException | IOException e) {
return CryptoUtils.createError("Unable to do public key operations: " + e.getMessage());
}
}

public static Object decodeDilithium3PublicKeyFromCertFile(BString certFilePath) {
if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
Security.addProvider(new BouncyCastleProvider());

Check warning on line 352 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#L352

Added line #L352 was not covered by tests
}
X509Certificate certificate = (X509Certificate) getCertificateFromFile(certFilePath);
return buildDilithium3PublicKeyRecord(certificate);
File certFile = new File(certFilePath.getValue());
try (FileInputStream fileInputStream = new FileInputStream(certFile)) {
CertificateFactory certificateFactory = CertificateFactory.getInstance(Constants.CERTIFICATE_TYPE_X509);
X509Certificate certificate = (X509Certificate) certificateFactory.generateCertificate(fileInputStream);
return buildDilithium3PublicKeyRecord(certificate);
} catch (FileNotFoundException e) {
return CryptoUtils.createError("Certificate file not found at: " + certFile.getAbsolutePath());
} catch (CertificateException | IOException e) {
return CryptoUtils.createError("Unable to do public key operations: " + e.getMessage());

Check warning on line 362 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#L354-L362

Added lines #L354 - L362 were not covered by tests
}
}

public static Object decodeKyber768PublicKeyFromCertFile(BString certFilePath) {
if (Security.getProvider(BouncyCastlePQCProvider.PROVIDER_NAME) == null) {
Security.addProvider(new BouncyCastlePQCProvider());

Check warning on line 368 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#L368

Added line #L368 was not covered by tests
}
X509Certificate certificate = (X509Certificate) getCertificateFromFile(certFilePath);
return buildKyber768PublicKeyRecord(certificate);
}

private static Object getCertificateFromFile(BString certFilePath) {
File certFile = new File(certFilePath.getValue());
try (FileInputStream fileInputStream = new FileInputStream(certFile)) {
CertificateFactory certificateFactory = CertificateFactory.getInstance(Constants.CERTIFICATE_TYPE_X509);
return certificateFactory.generateCertificate(fileInputStream);
X509Certificate certificate = (X509Certificate) certificateFactory.generateCertificate(fileInputStream);
return buildKyber768PublicKeyRecord(certificate);
} catch (FileNotFoundException e) {
return CryptoUtils.createError("Certificate file not found at: " + certFile.getAbsolutePath());
} catch (CertificateException | IOException e) {
Expand Down

0 comments on commit 934432b

Please sign in to comment.