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 c53701b  Fix up to support LibreSSL
c53701b is described below

commit c53701b526f8d079232c4cf9d29a5e3fe96ebf13
Author: Sebb <s...@apache.org>
AuthorDate: Mon Jul 4 16:59:02 2022 +0100

    Fix up to support LibreSSL
---
 .../commons/crypto/jna/OpenSsl10XNativeJna.java    | 119 +++++++++++++-
 .../commons/crypto/jna/OpenSsl11XNativeJna.java    | 118 +++++++++++++-
 ...l10XNativeJna.java => OpenSsl20XNativeJna.java} | 124 ++++++++++++++-
 .../crypto/jna/OpenSslInterfaceNativeJna.java      |  90 +++++++++++
 .../commons/crypto/jna/OpenSslNativeJna.java       | 172 ++++++---------------
 5 files changed, 489 insertions(+), 134 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 2cf4354..af68e10 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSsl10XNativeJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSsl10XNativeJna.java
@@ -26,7 +26,7 @@ import com.sun.jna.Native;
 import com.sun.jna.NativeLong;
 import com.sun.jna.ptr.PointerByReference;
 
-class OpenSsl10XNativeJna {
+class OpenSsl10XNativeJna implements OpenSslInterfaceNativeJna {
 
     static final boolean INIT_OK;
 
@@ -309,4 +309,121 @@ class OpenSsl10XNativeJna {
      * Initializes the engine.
      */
     public static native void ENGINE_load_rdrand();
+
+
+    // ================== instance interface methods ==================
+
+    public boolean _INIT_OK() {
+        return INIT_OK;
+    }
+
+    public Throwable _INIT_ERROR() {
+        return INIT_ERROR;
+    }
+
+    public PointerByReference _ENGINE_by_id(String string) {
+        return ENGINE_by_id(string);
+    }
+
+    public int _ENGINE_finish(PointerByReference rdrandEngine) {
+        return ENGINE_finish(rdrandEngine);
+    }
+
+    public int _ENGINE_free(PointerByReference rdrandEngine) {
+        return ENGINE_free(rdrandEngine);
+    }
+
+    public int _ENGINE_init(PointerByReference rdrandEngine) {
+        return ENGINE_init(rdrandEngine);
+    }
+
+    public int _ENGINE_set_default(PointerByReference rdrandEngine, int flags) 
{
+        return ENGINE_set_default(rdrandEngine, flags);
+    }
+
+    public String _ERR_error_string(NativeLong err, char[] buff) {
+        return ERR_error_string(err, buff);
+    }
+
+    public NativeLong _ERR_peek_error() {
+        return ERR_peek_error();
+    }
+
+    public PointerByReference _EVP_aes_128_cbc() {
+        return EVP_aes_128_cbc();
+    }
+
+    public PointerByReference _EVP_aes_128_ctr() {
+        return EVP_aes_128_ctr();
+    }
+
+    public PointerByReference _EVP_aes_192_cbc() {
+        return EVP_aes_192_cbc();
+    }
+
+    public PointerByReference _EVP_aes_192_ctr() {
+        return EVP_aes_192_ctr();
+    }
+
+    public PointerByReference _EVP_aes_256_cbc() {
+        return EVP_aes_256_cbc();
+    }
+
+    public PointerByReference _EVP_aes_256_ctr() {
+        return EVP_aes_256_ctr();
+    }
+
+    public void _EVP_CIPHER_CTX_free(PointerByReference context) {
+        EVP_CIPHER_CTX_free(context);
+    }
+
+    public PointerByReference _EVP_CIPHER_CTX_new() {
+        return EVP_CIPHER_CTX_new();
+    }
+
+    public int _EVP_CIPHER_CTX_set_padding(PointerByReference context, int 
padding) {
+        return EVP_CIPHER_CTX_set_padding(context, padding);
+    }
+
+    public int _EVP_CipherFinal_ex(PointerByReference context, ByteBuffer 
outBuffer, int[] outlen) {
+        return EVP_CipherFinal_ex(context, outBuffer, outlen);
+    }
+
+    public int _EVP_CipherInit_ex(PointerByReference context, 
PointerByReference algo, PointerByReference impl, byte[] encoded,
+            byte[] iv, int cipherMode) {
+        return EVP_CipherInit_ex(context, algo, impl, encoded, iv, cipherMode);
+    }
+
+    public int _EVP_CipherUpdate(PointerByReference context, ByteBuffer 
outBuffer, int[] outlen, ByteBuffer inBuffer,
+            int remaining) {
+        return EVP_CipherUpdate(context, outBuffer, outlen, inBuffer, 
remaining);
+    }
+
+    public int _RAND_bytes(ByteBuffer buf, int length) {
+        return RAND_bytes(buf, length) ;
+    }
+
+    public PointerByReference _RAND_get_rand_method() {
+        return RAND_get_rand_method();
+    }
+
+    public PointerByReference _RAND_SSLeay() {
+        return RAND_SSLeay();
+    }
+
+    public String _OpenSSL_version(int i) {
+        return SSLeay_version(i);
+    }
+
+    public void _ENGINE_load_rdrand() {
+        ENGINE_load_rdrand();
+    }
+
+    public int _ENGINE_cleanup() {
+        return ENGINE_cleanup();
+    }
+
+    public void _EVP_CIPHER_CTX_cleanup(PointerByReference context) {
+        EVP_CIPHER_CTX_cleanup(context);
+    }
 }
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 a89a4c7..ed24c91 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSsl11XNativeJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSsl11XNativeJna.java
@@ -26,7 +26,7 @@ import com.sun.jna.Native;
 import com.sun.jna.NativeLong;
 import com.sun.jna.ptr.PointerByReference;
 
-class OpenSsl11XNativeJna {
+class OpenSsl11XNativeJna  implements OpenSslInterfaceNativeJna {
 
     static final boolean INIT_OK;
 
@@ -267,4 +267,120 @@ class OpenSsl11XNativeJna {
      */
     public static native PointerByReference ENGINE_by_id(String id);
 
+    // ================== instance interface methods ==================
+
+    public boolean _INIT_OK() {
+        return INIT_OK;
+    }
+
+    public Throwable _INIT_ERROR() {
+        return INIT_ERROR;
+    }
+
+    public PointerByReference _ENGINE_by_id(String string) {
+        return ENGINE_by_id(string);
+    }
+
+    public int _ENGINE_finish(PointerByReference rdrandEngine) {
+        return ENGINE_finish(rdrandEngine);
+    }
+
+    public int _ENGINE_free(PointerByReference rdrandEngine) {
+        return ENGINE_free(rdrandEngine);
+    }
+
+    public int _ENGINE_init(PointerByReference rdrandEngine) {
+        return ENGINE_init(rdrandEngine);
+    }
+
+    public int _ENGINE_set_default(PointerByReference rdrandEngine, int flags) 
{
+        return ENGINE_set_default(rdrandEngine, flags);
+    }
+
+    public String _ERR_error_string(NativeLong err, char[] buff) {
+        return ERR_error_string(err, buff);
+    }
+
+    public NativeLong _ERR_peek_error() {
+        return ERR_peek_error();
+    }
+
+    public PointerByReference _EVP_aes_128_cbc() {
+        return EVP_aes_128_cbc();
+    }
+
+    public PointerByReference _EVP_aes_128_ctr() {
+        return EVP_aes_128_ctr();
+    }
+
+    public PointerByReference _EVP_aes_192_cbc() {
+        return EVP_aes_192_cbc();
+    }
+
+    public PointerByReference _EVP_aes_192_ctr() {
+        return EVP_aes_192_ctr();
+    }
+
+    public PointerByReference _EVP_aes_256_cbc() {
+        return EVP_aes_256_cbc();
+    }
+
+    public PointerByReference _EVP_aes_256_ctr() {
+        return EVP_aes_256_ctr();
+    }
+
+    public void _EVP_CIPHER_CTX_free(PointerByReference context) {
+        EVP_CIPHER_CTX_free(context);
+    }
+
+    public PointerByReference _EVP_CIPHER_CTX_new() {
+        return EVP_CIPHER_CTX_new();
+    }
+
+    public int _EVP_CIPHER_CTX_set_padding(PointerByReference context, int 
padding) {
+        return EVP_CIPHER_CTX_set_padding(context, padding);
+    }
+
+    public int _EVP_CipherFinal_ex(PointerByReference context, ByteBuffer 
outBuffer, int[] outlen) {
+        return EVP_CipherFinal_ex(context, outBuffer, outlen);
+    }
+
+    public int _EVP_CipherInit_ex(PointerByReference context, 
PointerByReference algo, PointerByReference impl, byte[] encoded,
+            byte[] iv, int cipherMode) {
+        return EVP_CipherInit_ex(context, algo, impl, encoded, iv, cipherMode);
+    }
+
+    public int _EVP_CipherUpdate(PointerByReference context, ByteBuffer 
outBuffer, int[] outlen, ByteBuffer inBuffer,
+            int remaining) {
+        return EVP_CipherUpdate(context, outBuffer, outlen, inBuffer, 
remaining);
+    }
+
+    public int _RAND_bytes(ByteBuffer buf, int length) {
+        return RAND_bytes(buf, length) ;
+    }
+
+    public PointerByReference _RAND_get_rand_method() {
+        return RAND_get_rand_method();
+    }
+
+    public PointerByReference _RAND_SSLeay() {
+        return null; // Not available
+    }
+
+    public String _OpenSSL_version(int i) {
+        return OpenSSL_version(i);
+    }
+
+    public void _ENGINE_load_rdrand() {
+        // Not available
+    }
+
+    public int _ENGINE_cleanup() {
+        return 0; // Not available
+    }
+
+    public void _EVP_CIPHER_CTX_cleanup(PointerByReference context) {
+        // Not available
+    }
+
 }
diff --git 
a/src/main/java/org/apache/commons/crypto/jna/OpenSsl10XNativeJna.java 
b/src/main/java/org/apache/commons/crypto/jna/OpenSsl20XNativeJna.java
similarity index 73%
copy from src/main/java/org/apache/commons/crypto/jna/OpenSsl10XNativeJna.java
copy to src/main/java/org/apache/commons/crypto/jna/OpenSsl20XNativeJna.java
index 2cf4354..633e58d 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSsl10XNativeJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSsl20XNativeJna.java
@@ -26,7 +26,7 @@ import com.sun.jna.Native;
 import com.sun.jna.NativeLong;
 import com.sun.jna.ptr.PointerByReference;
 
-class OpenSsl10XNativeJna {
+class OpenSsl20XNativeJna implements OpenSslInterfaceNativeJna {
 
     static final boolean INIT_OK;
 
@@ -52,7 +52,6 @@ class OpenSsl10XNativeJna {
     // Try to keep methods aligned across versions
 
     /**
-     * @see <a 
href="https://www.openssl.org/docs/man1.0.2/man3/SSLeay.html";>Version Number</a>
      * TODO (does not appear to be used yet)
      * @return OPENSSL_VERSION_NUMBER which is a numeric release version 
identifier
      */
@@ -62,8 +61,6 @@ class OpenSsl10XNativeJna {
      * Retrieves version/build information about OpenSSL library.
      * This is returned by {@link OpenSslNativeJna#OpenSSLVersion(int)}
      *
-     * @see <a 
href="https://www.openssl.org/docs/man1.0.2/man3/SSLeay_version.html";>Version 
Info</a>
-     *
      * @param type
      *            type can be SSLEAY_VERSION, SSLEAY_CFLAGS, SSLEAY_BUILT_ON...
      * @return A pointer to a constant string describing the version of the 
OpenSSL library or
@@ -305,8 +302,119 @@ class OpenSsl10XNativeJna {
      */
     public static native PointerByReference ENGINE_by_id(String id);
 
-    /**
-     * Initializes the engine.
-     */
-    public static native void ENGINE_load_rdrand();
+    // ================== instance interface methods ==================
+
+    public boolean _INIT_OK() {
+        return INIT_OK;
+    }
+
+    public Throwable _INIT_ERROR() {
+        return INIT_ERROR;
+    }
+
+    public PointerByReference _ENGINE_by_id(String string) {
+        return ENGINE_by_id(string);
+    }
+
+    public int _ENGINE_finish(PointerByReference rdrandEngine) {
+        return ENGINE_finish(rdrandEngine);
+    }
+
+    public int _ENGINE_free(PointerByReference rdrandEngine) {
+        return ENGINE_free(rdrandEngine);
+    }
+
+    public int _ENGINE_init(PointerByReference rdrandEngine) {
+        return ENGINE_init(rdrandEngine);
+    }
+
+    public int _ENGINE_set_default(PointerByReference rdrandEngine, int flags) 
{
+        return ENGINE_set_default(rdrandEngine, flags);
+    }
+
+    public String _ERR_error_string(NativeLong err, char[] buff) {
+        return ERR_error_string(err, buff);
+    }
+
+    public NativeLong _ERR_peek_error() {
+        return ERR_peek_error();
+    }
+
+    public PointerByReference _EVP_aes_128_cbc() {
+        return EVP_aes_128_cbc();
+    }
+
+    public PointerByReference _EVP_aes_128_ctr() {
+        return EVP_aes_128_ctr();
+    }
+
+    public PointerByReference _EVP_aes_192_cbc() {
+        return EVP_aes_192_cbc();
+    }
+
+    public PointerByReference _EVP_aes_192_ctr() {
+        return EVP_aes_192_ctr();
+    }
+
+    public PointerByReference _EVP_aes_256_cbc() {
+        return EVP_aes_256_cbc();
+    }
+
+    public PointerByReference _EVP_aes_256_ctr() {
+        return EVP_aes_256_ctr();
+    }
+
+    public void _EVP_CIPHER_CTX_free(PointerByReference context) {
+        EVP_CIPHER_CTX_free(context);
+    }
+
+    public PointerByReference _EVP_CIPHER_CTX_new() {
+        return EVP_CIPHER_CTX_new();
+    }
+
+    public int _EVP_CIPHER_CTX_set_padding(PointerByReference context, int 
padding) {
+        return EVP_CIPHER_CTX_set_padding(context, padding);
+    }
+
+    public int _EVP_CipherFinal_ex(PointerByReference context, ByteBuffer 
outBuffer, int[] outlen) {
+        return EVP_CipherFinal_ex(context, outBuffer, outlen);
+    }
+
+    public int _EVP_CipherInit_ex(PointerByReference context, 
PointerByReference algo, PointerByReference impl, byte[] encoded,
+            byte[] iv, int cipherMode) {
+        return EVP_CipherInit_ex(context, algo, impl, encoded, iv, cipherMode);
+    }
+
+    public int _EVP_CipherUpdate(PointerByReference context, ByteBuffer 
outBuffer, int[] outlen, ByteBuffer inBuffer,
+            int remaining) {
+        return EVP_CipherUpdate(context, outBuffer, outlen, inBuffer, 
remaining);
+    }
+
+    public int _RAND_bytes(ByteBuffer buf, int length) {
+        return RAND_bytes(buf, length) ;
+    }
+
+    public PointerByReference _RAND_get_rand_method() {
+        return RAND_get_rand_method();
+    }
+
+    public PointerByReference _RAND_SSLeay() {
+        return RAND_SSLeay();
+    }
+
+    public String _OpenSSL_version(int i) {
+        return SSLeay_version(i);
+    }
+
+    public void _ENGINE_load_rdrand() {
+        // Not available
+    }
+
+    public int _ENGINE_cleanup() {
+        return ENGINE_cleanup();
+    }
+
+    public void _EVP_CIPHER_CTX_cleanup(PointerByReference context) {
+        EVP_CIPHER_CTX_cleanup(context);
+    }
 }
diff --git 
a/src/main/java/org/apache/commons/crypto/jna/OpenSslInterfaceNativeJna.java 
b/src/main/java/org/apache/commons/crypto/jna/OpenSslInterfaceNativeJna.java
new file mode 100644
index 0000000..9c586c4
--- /dev/null
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSslInterfaceNativeJna.java
@@ -0,0 +1,90 @@
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.crypto.jna;
+
+import java.nio.ByteBuffer;
+
+import com.sun.jna.ptr.PointerByReference;
+import com.sun.jna.NativeLong;
+
+/**
+ * This interface defines the API for the native code.
+ * All methods are listed here; individual implementations may not support 
them all.
+ */
+interface OpenSslInterfaceNativeJna {
+
+    public boolean _INIT_OK();
+
+    public Throwable _INIT_ERROR();
+
+    public PointerByReference _ENGINE_by_id(final String string);
+
+    public int _ENGINE_finish(final PointerByReference rdrandEngine);
+
+    public int _ENGINE_free(final PointerByReference rdrandEngine);
+
+    public int _ENGINE_init(final PointerByReference rdrandEngine);
+
+    public int _ENGINE_set_default(final PointerByReference rdrandEngine, 
final int flags);
+
+    public String _ERR_error_string(final NativeLong err, final char[] buff);
+
+    public NativeLong _ERR_peek_error();
+
+    public PointerByReference _EVP_aes_128_cbc();
+
+    public PointerByReference _EVP_aes_128_ctr();
+
+    public PointerByReference _EVP_aes_192_cbc();
+
+    public PointerByReference _EVP_aes_192_ctr();
+
+    public PointerByReference _EVP_aes_256_cbc();
+
+    public PointerByReference _EVP_aes_256_ctr();
+
+    public void _EVP_CIPHER_CTX_free(final PointerByReference context);
+
+    public PointerByReference _EVP_CIPHER_CTX_new();
+
+    public int _EVP_CIPHER_CTX_set_padding(final PointerByReference context, 
final int padding);
+
+    public int _EVP_CipherFinal_ex(final PointerByReference context, final 
ByteBuffer outBuffer,
+            final int[] outlen);
+
+    public int _EVP_CipherInit_ex(final PointerByReference context, final 
PointerByReference algo,
+            final PointerByReference impl, final byte[] encoded, final byte[] 
iv, final int cipherMode);
+
+    public int _EVP_CipherUpdate(final PointerByReference context, final 
ByteBuffer outBuffer,
+            final int[] outlen, final ByteBuffer inBuffer, final int 
remaining);
+
+    public int _RAND_bytes(final ByteBuffer buf, final int length);
+
+    public PointerByReference _RAND_get_rand_method();
+
+    public PointerByReference _RAND_SSLeay();
+
+    public String _OpenSSL_version(final int i);
+
+    public void _ENGINE_load_rdrand();
+
+    public int _ENGINE_cleanup();
+
+    public void _EVP_CIPHER_CTX_cleanup(final PointerByReference context);
+}
\ No newline at end of file
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 cca8b28..794f57d 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
@@ -41,7 +41,10 @@ class OpenSslNativeJna {
     public static final long VERSION;
     public static final long VERSION_1_0_X = 0x10000000;
     public static final long VERSION_1_1_X = 0x10100000;
+    public static final long VERSION_2_0_X = 0x20000000;
 
+    private static final OpenSslInterfaceNativeJna JnaImplementation;
+  
     static {
         final String libraryName = System.getProperty(Crypto.CONF_PREFIX + 
OpenSslNativeJna.class.getSimpleName(), "crypto");
         OpenSslJna.debug("NativeLibrary.getInstance('%s')%n", libraryName);
@@ -50,225 +53,146 @@ class OpenSslNativeJna {
         try {
             version = crypto.getFunction("SSLeay");
         } catch (final UnsatisfiedLinkError e) {
-            // Swallow the Error.
+            version = crypto.getFunction("OpenSSL_version_num");
         }
+        // Must find one of the above two functions; else give up
 
-        if (version == null) {
-            VERSION = VERSION_1_1_X;
+        VERSION = version.invokeLong(new Object[]{}) & 0xffff0000; // keep 
only major.minor
+        if (VERSION == VERSION_1_0_X) {
+           JnaImplementation = new OpenSsl10XNativeJna();
+        } else if (VERSION == VERSION_1_1_X) {
+            JnaImplementation = new OpenSsl11XNativeJna();
+        } else if (VERSION == VERSION_2_0_X) {
+            JnaImplementation = new OpenSsl20XNativeJna();
         } else {
-            VERSION = VERSION_1_0_X;
+            // TODO: Throw error?
+            JnaImplementation = new OpenSsl10XNativeJna();
         }
+
         OpenSslJna.debug(String.format("Detected version 0x%x", VERSION));
 
-        if (VERSION == VERSION_1_1_X) {
-            INIT_OK = OpenSsl11XNativeJna.INIT_OK;
-        } else {
-            INIT_OK = OpenSsl10XNativeJna.INIT_OK;
-        }
+        INIT_OK = JnaImplementation._INIT_OK();
 
         if (INIT_OK) {
             INIT_ERROR = null;
-        } else if (VERSION == VERSION_1_1_X) {
-            INIT_ERROR = OpenSsl11XNativeJna.INIT_ERROR;
         } else {
-            INIT_ERROR = OpenSsl10XNativeJna.INIT_ERROR;
+            INIT_ERROR = JnaImplementation._INIT_ERROR();
         }
     }
 
+    private OpenSslNativeJna() {
+    }
+
     public static PointerByReference ENGINE_by_id(final String string) {
-        if (VERSION == VERSION_1_1_X) {
-            return OpenSsl11XNativeJna.ENGINE_by_id(string);
-        }
-        return OpenSsl10XNativeJna.ENGINE_by_id(string);
+        return JnaImplementation._ENGINE_by_id(string);
     }
 
     // TODO: native method returns int
     public static void ENGINE_finish(final PointerByReference rdrandEngine) {
-        if (VERSION == VERSION_1_1_X) {
-            OpenSsl11XNativeJna.ENGINE_finish(rdrandEngine);
-        } else {
-            OpenSsl10XNativeJna.ENGINE_finish(rdrandEngine);
-        }
+        JnaImplementation._ENGINE_finish(rdrandEngine);
     }
 
     // TODO: native method returns int
     public static void ENGINE_free(final PointerByReference rdrandEngine) {
-        if (VERSION == VERSION_1_1_X) {
-            OpenSsl11XNativeJna.ENGINE_free(rdrandEngine);
-        } else {
-            OpenSsl10XNativeJna.ENGINE_free(rdrandEngine);
-        }
+        JnaImplementation._ENGINE_free(rdrandEngine);
     }
 
     public static int ENGINE_init(final PointerByReference rdrandEngine) {
-        if (VERSION == VERSION_1_1_X) {
-            return OpenSsl11XNativeJna.ENGINE_init(rdrandEngine);
-        }
-        return OpenSsl10XNativeJna.ENGINE_init(rdrandEngine);
+        return JnaImplementation._ENGINE_init(rdrandEngine);
     }
 
     public static int ENGINE_set_default(final PointerByReference 
rdrandEngine, final int eNGINE_METHOD_RAND) {
-        if (VERSION == VERSION_1_1_X) {
-            return OpenSsl11XNativeJna.ENGINE_set_default(rdrandEngine, 
eNGINE_METHOD_RAND);
-        }
-        return OpenSsl10XNativeJna.ENGINE_set_default(rdrandEngine, 
eNGINE_METHOD_RAND);
+        return JnaImplementation._ENGINE_set_default(rdrandEngine, 
eNGINE_METHOD_RAND);
     }
 
+    // TODO: native method expects char[] buffer
     public static String ERR_error_string(final NativeLong err, final Object 
object) {
-        if (VERSION == VERSION_1_1_X) {
-            return OpenSsl11XNativeJna.ERR_error_string(err, null);
-        }
-        return OpenSsl10XNativeJna.ERR_error_string(err, null);
+        return JnaImplementation._ERR_error_string(err, null);
     }
 
     public static NativeLong ERR_peek_error() {
-        if (VERSION == VERSION_1_1_X) {
-            return OpenSsl11XNativeJna.ERR_peek_error();
-        }
-        return OpenSsl10XNativeJna.ERR_peek_error();
+        return JnaImplementation._ERR_peek_error();
     }
 
     public static PointerByReference EVP_aes_128_cbc() {
-        if (VERSION == VERSION_1_1_X) {
-            return OpenSsl11XNativeJna.EVP_aes_128_cbc();
-        }
-        return OpenSsl10XNativeJna.EVP_aes_128_cbc();
+        return JnaImplementation._EVP_aes_128_cbc();
     }
 
     public static PointerByReference EVP_aes_128_ctr() {
-        if (VERSION == VERSION_1_1_X) {
-            return OpenSsl11XNativeJna.EVP_aes_128_ctr();
-        }
-        return OpenSsl10XNativeJna.EVP_aes_128_ctr();
+        return JnaImplementation._EVP_aes_128_ctr();
     }
 
     public static PointerByReference EVP_aes_192_cbc() {
-        if (VERSION == VERSION_1_1_X) {
-            return OpenSsl11XNativeJna.EVP_aes_192_cbc();
-        }
-        return OpenSsl10XNativeJna.EVP_aes_192_cbc();
+        return JnaImplementation._EVP_aes_192_cbc();
     }
 
     public static PointerByReference EVP_aes_192_ctr() {
-        if (VERSION == VERSION_1_1_X) {
-            return OpenSsl11XNativeJna.EVP_aes_192_ctr();
-        }
-        return OpenSsl10XNativeJna.EVP_aes_192_ctr();
+        return JnaImplementation._EVP_aes_192_ctr();
     }
 
     public static PointerByReference EVP_aes_256_cbc() {
-        if (VERSION == VERSION_1_1_X) {
-            return OpenSsl11XNativeJna.EVP_aes_256_cbc();
-        }
-        return OpenSsl10XNativeJna.EVP_aes_256_cbc();
+        return JnaImplementation._EVP_aes_256_cbc();
     }
 
     public static PointerByReference EVP_aes_256_ctr() {
-        if (VERSION == VERSION_1_1_X) {
-            return OpenSsl11XNativeJna.EVP_aes_256_ctr();
-        }
-        return OpenSsl10XNativeJna.EVP_aes_256_ctr();
+        return JnaImplementation._EVP_aes_256_ctr();
     }
 
     public static void EVP_CIPHER_CTX_free(final PointerByReference context) {
-        if (VERSION == VERSION_1_1_X) {
-            OpenSsl11XNativeJna.EVP_CIPHER_CTX_free(context);
-        } else {
-            OpenSsl10XNativeJna.EVP_CIPHER_CTX_free(context);
-        }
+        JnaImplementation._EVP_CIPHER_CTX_free(context);
     }
 
     public static PointerByReference EVP_CIPHER_CTX_new() {
-        if (VERSION == VERSION_1_1_X) {
-            return OpenSsl11XNativeJna.EVP_CIPHER_CTX_new();
-        }
-        return OpenSsl10XNativeJna.EVP_CIPHER_CTX_new();
+        return JnaImplementation._EVP_CIPHER_CTX_new();
     }
 
     // TODO: native method returns int
     public static void EVP_CIPHER_CTX_set_padding(final PointerByReference 
context, final int padding) {
-        if (VERSION == VERSION_1_1_X) {
-            OpenSsl11XNativeJna.EVP_CIPHER_CTX_set_padding(context, padding);
-        } else {
-            OpenSsl10XNativeJna.EVP_CIPHER_CTX_set_padding(context, padding);
-        }
+        JnaImplementation._EVP_CIPHER_CTX_set_padding(context, padding);
     }
 
     public static int EVP_CipherFinal_ex(final PointerByReference context, 
final ByteBuffer outBuffer,
             final int[] outlen) {
-        if (VERSION == VERSION_1_1_X) {
-            return OpenSsl11XNativeJna.EVP_CipherFinal_ex(context, outBuffer, 
outlen);
-        }
-        return OpenSsl10XNativeJna.EVP_CipherFinal_ex(context, outBuffer, 
outlen);
+        return JnaImplementation._EVP_CipherFinal_ex(context, outBuffer, 
outlen);
     }
 
+    // TODO: native method expects PointerByReference implementation
     public static int EVP_CipherInit_ex(final PointerByReference context, 
final PointerByReference algo,
             final Object object, final byte[] encoded, final byte[] iv, final 
int cipherMode) {
-        if (VERSION == VERSION_1_1_X) {
-            return OpenSsl11XNativeJna.EVP_CipherInit_ex(context, algo, null, 
encoded, iv,
-                    cipherMode);
-        }
-        return OpenSsl10XNativeJna.EVP_CipherInit_ex(context, algo, null, 
encoded, iv,
-                cipherMode);
+        return JnaImplementation._EVP_CipherInit_ex(context, algo, null, 
encoded, iv, cipherMode);
     }
 
     public static int EVP_CipherUpdate(final PointerByReference context, final 
ByteBuffer outBuffer,
             final int[] outlen, final ByteBuffer inBuffer, final int 
remaining) {
-        if (VERSION == VERSION_1_1_X) {
-            return OpenSsl11XNativeJna.EVP_CipherUpdate(context, outBuffer, 
outlen, inBuffer,
-                    remaining);
-        }
-        return OpenSsl10XNativeJna.EVP_CipherUpdate(context, outBuffer, 
outlen, inBuffer,
-                remaining);
+        return JnaImplementation._EVP_CipherUpdate(context, outBuffer, outlen, 
inBuffer, remaining);
     }
 
     public static int RAND_bytes(final ByteBuffer buf, final int length) {
-        if (VERSION == VERSION_1_1_X) {
-            return OpenSsl11XNativeJna.RAND_bytes(buf, length);
-        }
-        return OpenSsl10XNativeJna.RAND_bytes(buf, length);
+        return JnaImplementation._RAND_bytes(buf, length);
     }
 
     public static PointerByReference RAND_get_rand_method() {
-        if (VERSION == VERSION_1_1_X) {
-            return OpenSsl11XNativeJna.RAND_get_rand_method();
-        }
-        return OpenSsl10XNativeJna.RAND_get_rand_method();
+        return JnaImplementation._RAND_get_rand_method();
     }
 
     public static PointerByReference RAND_SSLeay() {
-        if (VERSION == VERSION_1_1_X) {
-            return null;
-        }
-        return OpenSsl10XNativeJna.RAND_SSLeay();
+        return JnaImplementation._RAND_SSLeay();
     }
 
     public static String OpenSSLVersion(final int i) {
-        if (VERSION == VERSION_1_1_X) {
-            return OpenSsl11XNativeJna.OpenSSL_version(i);
-        }
-        return OpenSsl10XNativeJna.SSLeay_version(i);
+        return JnaImplementation._OpenSSL_version(i);
     }
 
     public static void ENGINE_load_rdrand() {
-        if (VERSION == VERSION_1_1_X) {
-            return;
-        }
-        OpenSsl10XNativeJna.ENGINE_load_rdrand();
+        JnaImplementation._ENGINE_load_rdrand();
     }
 
     // TODO: native method returns int
     public static void ENGINE_cleanup() {
-        if (VERSION == VERSION_1_1_X) {
-            return;
-        }
-        OpenSsl10XNativeJna.ENGINE_cleanup();
+        JnaImplementation._ENGINE_cleanup();
     }
 
     public static void EVP_CIPHER_CTX_cleanup(final PointerByReference 
context) {
-        if (VERSION == VERSION_1_1_X) {
-            return;
-        }
-        OpenSsl10XNativeJna.EVP_CIPHER_CTX_cleanup(context);
+        JnaImplementation._EVP_CIPHER_CTX_cleanup(context);
     }
 }
\ No newline at end of file

Reply via email to