Skip to content

Commit

Permalink
Show more info on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbASF committed Nov 14, 2023
1 parent 171600d commit 444f98b
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/main/java/org/apache/commons/crypto/Crypto.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,30 @@ public static void main(final String[] args) throws Exception {
info("OpenSSL library info: %s", OpenSslInfoNative.OpenSSLVersion(0));
info("DLL name: %s", OpenSslInfoNative.DLLName());
info("DLL path: %s", OpenSslInfoNative.DLLPath());
{ // CryptoRandom
info("Additional OpenSSL_version(n) details:");
for (int j = 1; j < Utils.OPENSSL_VERSION_MAX_INDEX; j++) { // entry 0 is shown above
String data = OpenSslInfoNative.OpenSSLVersion(j);
if (!"not available".equals(data)) {
info("OpenSSLVersion(%d): %s", j, data);
}
}
try { // CryptoRandom
final Properties props = new Properties();
props.setProperty(CryptoRandomFactory.CLASSES_KEY, CryptoRandomFactory.RandomProvider.OPENSSL.getClassName());
try (CryptoRandom cryptoRandom = CryptoRandomFactory.getCryptoRandom(props)) {
info("Random instance created OK: %s", cryptoRandom);
}
} catch (Exception e) {
info("Failed: %s", e);
}
{ // CryptoCipher
try { // CryptoCipher
final Properties props = new Properties();
props.setProperty(CryptoCipherFactory.CLASSES_KEY, CryptoCipherFactory.CipherProvider.OPENSSL.getClassName());
try (CryptoCipher cryptoCipher = CryptoCipherFactory.getCryptoCipher(AES.CTR_NO_PADDING, props)) {
info("Cipher %s instance created OK: %s", AES.CTR_NO_PADDING, cryptoCipher);
}
}
info("Additional OpenSSL_version(n) details:");
for (int j = 1; j < Utils.OPENSSL_VERSION_MAX_INDEX; j++) { // entry 0 is shown above
String data = OpenSslInfoNative.OpenSSLVersion(j);
if (!"not available".equals(data)) {
info("OpenSSLVersion(%d): %s", j, data);
}
} catch (Exception e) {
info("Failed: %s", e);
}
} else {
Throwable error = getLoadingError();
Expand Down

0 comments on commit 444f98b

Please sign in to comment.