This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-crypto.git


The following commit(s) were added to refs/heads/master by this push:
     new f75fcd5  Re-use the library once found by NativeLibrary.
f75fcd5 is described below

commit f75fcd5a61a57885b730cbc2fa80ea0ad956e6b2
Author: Sebb <[email protected]>
AuthorDate: Wed Jun 29 00:43:04 2022 +0100

    Re-use the library once found by NativeLibrary.
    
    Saves looking again, and ensures the same library is used.
    This is vital as the first lookup determines which class to use.
---
 .../org/apache/commons/crypto/jna/OpenSsl10XNativeJna.java  |  4 +---
 .../org/apache/commons/crypto/jna/OpenSsl11XNativeJna.java  |  4 +---
 .../org/apache/commons/crypto/jna/OpenSslNativeJna.java     | 13 +++++++------
 3 files changed, 9 insertions(+), 12 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/crypto/jna/OpenSsl10XNativeJna.java 
b/src/main/java/org/apache/commons/crypto/jna/OpenSsl10XNativeJna.java
index 7b7c239..a0914f0 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSsl10XNativeJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSsl10XNativeJna.java
@@ -36,9 +36,7 @@ class OpenSsl10XNativeJna {
         boolean ok = false;
         Throwable thrown = null;
         try {
-            final String libName = OpenSslNativeJna.LIBRARY_NAME;
-            OpenSslJna.debug("Native.register('%s')%n", libName);
-            Native.register(libName);
+            Native.register(OpenSslNativeJna.CRYPTO_LIBRARY);
             ok = true;
         } catch (final Exception | UnsatisfiedLinkError e) {
             thrown = e;
diff --git 
a/src/main/java/org/apache/commons/crypto/jna/OpenSsl11XNativeJna.java 
b/src/main/java/org/apache/commons/crypto/jna/OpenSsl11XNativeJna.java
index fbd1ea9..6c3a4e1 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSsl11XNativeJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSsl11XNativeJna.java
@@ -36,9 +36,7 @@ class OpenSsl11XNativeJna {
         boolean ok = false;
         Throwable thrown = null;
         try {
-            final String libName = OpenSslNativeJna.LIBRARY_NAME;
-            OpenSslJna.debug("Native.register('%s')%n", libName);
-            Native.register(libName);
+            Native.register(OpenSslNativeJna.CRYPTO_LIBRARY);
             ok = true;
         } catch (final Exception | UnsatisfiedLinkError e) {
             thrown = e;
diff --git a/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java 
b/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
index 4831ca2..78c44c7 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
@@ -42,15 +42,16 @@ class OpenSslNativeJna {
     public static final long VERSION_1_0_X = 0x10000000;
     public static final long VERSION_1_1_X = 0x10100000;
 
-    // The same library name is also needed by OpenSsl10XNativeJna and 
OpenSsl11XNativeJna 
-    static final String LIBRARY_NAME = System.getProperty(Crypto.CONF_PREFIX + 
OpenSslNativeJna.class.getSimpleName(), "crypto");
-
+    // Pass the library alreaded to OpenSsl10XNativeJna and 
OpenSsl11XNativeJna 
+    static final NativeLibrary CRYPTO_LIBRARY;
     static {
-        OpenSslJna.debug("NativeLibrary.getInstance('%s')%n", LIBRARY_NAME);
-        final NativeLibrary crypto = NativeLibrary.getInstance(LIBRARY_NAME);
+        final String library_name = System.getProperty(Crypto.CONF_PREFIX + 
OpenSslNativeJna.class.getSimpleName(), "crypto");
+        OpenSslJna.debug("NativeLibrary.getInstance('%s')%n", library_name);
+        CRYPTO_LIBRARY = NativeLibrary.getInstance(library_name);
+        OpenSslJna.debug("%s%n", CRYPTO_LIBRARY.toString()); // show what was 
loaded
         Function version = null;
         try {
-            version = crypto.getFunction("SSLeay");
+            version = CRYPTO_LIBRARY.getFunction("SSLeay");
         } catch (final UnsatisfiedLinkError e) {
             // Swallow the Error.
         }

Reply via email to