From 444f98b2cebf8f2ddd8a32a916e88e388914c282 Mon Sep 17 00:00:00 2001 From: Sebb Date: Tue, 14 Nov 2023 14:40:37 +0000 Subject: [PATCH] Show more info on failure --- .../org/apache/commons/crypto/Crypto.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/apache/commons/crypto/Crypto.java b/src/main/java/org/apache/commons/crypto/Crypto.java index f510738bd..3a912a0a5 100644 --- a/src/main/java/org/apache/commons/crypto/Crypto.java +++ b/src/main/java/org/apache/commons/crypto/Crypto.java @@ -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();