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 a3d4e443 Use constant strings for property names
a3d4e443 is described below
commit a3d4e443e7d6a6e4e14cf3d38ce0360eb357306f
Author: Sebb <[email protected]>
AuthorDate: Tue Nov 21 00:54:41 2023 +0000
Use constant strings for property names
---
.../java/org/apache/commons/crypto/Crypto.java | 31 ++++++++++++++++++++--
.../commons/crypto/jna/LibreSsl20XNativeJna.java | 2 +-
.../commons/crypto/jna/OpenSsl11XNativeJna.java | 2 +-
.../commons/crypto/jna/OpenSsl30XNativeJna.java | 2 +-
.../org/apache/commons/crypto/jna/OpenSslJna.java | 4 +--
.../commons/crypto/jna/OpenSslNativeJna.java | 2 +-
.../org/apache/commons/crypto/utils/Utils.java | 10 +++----
7 files changed, 40 insertions(+), 13 deletions(-)
diff --git a/src/main/java/org/apache/commons/crypto/Crypto.java
b/src/main/java/org/apache/commons/crypto/Crypto.java
index 3a912a0a..3cc225d9 100644
--- a/src/main/java/org/apache/commons/crypto/Crypto.java
+++ b/src/main/java/org/apache/commons/crypto/Crypto.java
@@ -80,6 +80,33 @@ public final class Crypto {
*/
public static final String LIB_TEMPDIR_KEY = Crypto.CONF_PREFIX +
"lib.tempdir";
+ // property names related to SSL crypto library loading
+
+ /**
+ * Where to find the SSL crypto library when using JNI
+ * This is used in Utils.libraryPath()
+ */
+ public static final String JNI_LIBRARY_PATH = "jni.library.path";
+
+ /**
+ * Override property for the default SSL crypto library name when using JNI
+ */
+ public static final String JNI_LIBRARY_NAME = "jni.library.name";
+
+ /**
+ * Where to find the SSL crypto library when using JNA
+ * This is used by the JNA library code
+ */
+ public static final String JNA_LIBRARY_PATH = "jna.library.path";
+
+ /**
+ * Override property for the default SSL crypto library name when using JNA
+ */
+ public static final String JNA_LIBRARY_NAME = Crypto.CONF_PREFIX +
"OpenSslNativeJna";
+
+ /** Default name for loading SSL crypto library using JNA */
+ public static final String JNA_LIBRARY_NAME_DEFAULT = "crypto";
+
private static boolean quiet;
/**
@@ -152,8 +179,8 @@ public final class Crypto {
*/
public static void main(final String[] args) throws Exception {
quiet = args.length == 1 && args[0].equals("-q");
- info("jni.library.path=%s", System.getProperty("jni.library.path"));
- info("jni.library.name=%s", System.getProperty("jni.library.name"));
+ info("%s=%s", JNI_LIBRARY_PATH, System.getProperty(JNI_LIBRARY_PATH));
+ info("%s=%s", JNI_LIBRARY_NAME, System.getProperty(JNI_LIBRARY_NAME));
info("%s %s", getComponentName(), getComponentVersion());
if (isNativeCodeLoaded()) {
info("Native code loaded OK: %s",
OpenSslInfoNative.NativeVersion());
diff --git
a/src/main/java/org/apache/commons/crypto/jna/LibreSsl20XNativeJna.java
b/src/main/java/org/apache/commons/crypto/jna/LibreSsl20XNativeJna.java
index 66561fb8..e849e1f7 100644
--- a/src/main/java/org/apache/commons/crypto/jna/LibreSsl20XNativeJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/LibreSsl20XNativeJna.java
@@ -37,7 +37,7 @@ final class LibreSsl20XNativeJna implements
OpenSslInterfaceNativeJna {
boolean ok = false;
Throwable thrown = null;
try {
- final String libName = System.getProperty(Crypto.CONF_PREFIX +
OpenSslNativeJna.class.getSimpleName(), "crypto");
+ final String libName = System.getProperty(Crypto.JNA_LIBRARY_NAME,
Crypto.JNA_LIBRARY_NAME_DEFAULT);
OpenSslJna.debug("Native.register('%s')", libName);
Native.register(libName);
ok = true;
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 fcecc283..da3e91c6 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSsl11XNativeJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSsl11XNativeJna.java
@@ -36,7 +36,7 @@ final class OpenSsl11XNativeJna implements
OpenSslInterfaceNativeJna {
boolean ok = false;
Throwable thrown = null;
try {
- final String libName = System.getProperty(Crypto.CONF_PREFIX +
OpenSslNativeJna.class.getSimpleName(), "crypto");
+ final String libName = System.getProperty(Crypto.JNA_LIBRARY_NAME,
Crypto.JNA_LIBRARY_NAME_DEFAULT);
OpenSslJna.debug("Native.register('%s')", libName);
Native.register(libName);
ok = true;
diff --git
a/src/main/java/org/apache/commons/crypto/jna/OpenSsl30XNativeJna.java
b/src/main/java/org/apache/commons/crypto/jna/OpenSsl30XNativeJna.java
index ff2aeaf4..f702a016 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSsl30XNativeJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSsl30XNativeJna.java
@@ -38,7 +38,7 @@ final class OpenSsl30XNativeJna implements
OpenSslInterfaceNativeJna {
boolean ok = false;
Throwable thrown = null;
try {
- final String libName = System.getProperty(Crypto.CONF_PREFIX +
OpenSslNativeJna.class.getSimpleName(), "crypto");
+ final String libName = System.getProperty(Crypto.JNA_LIBRARY_NAME,
Crypto.JNA_LIBRARY_NAME_DEFAULT);
OpenSslJna.debug("Native.register('%s')", libName);
Native.register(libName);
ok = true;
diff --git a/src/main/java/org/apache/commons/crypto/jna/OpenSslJna.java
b/src/main/java/org/apache/commons/crypto/jna/OpenSslJna.java
index 66238c0c..9bb1c934 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSslJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSslJna.java
@@ -98,9 +98,9 @@ public final class OpenSslJna {
*/
public static void main(final String[] args) throws Throwable {
// These are used by JNA code if defined:
- info("jna.library.path=%s", System.getProperty("jna.library.path"));
+ info("%s=%s", Crypto.JNA_LIBRARY_PATH,
System.getProperty(Crypto.JNA_LIBRARY_PATH));
info("jna.platform.library.path=%s",
System.getProperty("jna.platform.library.path"));
- info("commons.crypto.OpenSslNativeJna=%s\n",
System.getProperty("commons.crypto.OpenSslNativeJna"));
+ info("%s=%s\n", Crypto.JNA_LIBRARY_NAME,
System.getProperty(Crypto.JNA_LIBRARY_NAME));
// can set jna.debug_load=true for loading info
info(Crypto.getComponentName() + " OpenSslJna: enabled = %s, version =
0x%08X", isEnabled(), OpenSslNativeJna.VERSION);
final Throwable initialisationError = initialisationError();
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 44348c67..8662b026 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
@@ -53,7 +53,7 @@ final class OpenSslNativeJna {
static {
OpenSslJna.debug("OpenSslNativeJna static init start");
- final String libraryName = System.getProperty(Crypto.CONF_PREFIX +
OpenSslNativeJna.class.getSimpleName(), "crypto");
+ final String libraryName = System.getProperty(Crypto.JNA_LIBRARY_NAME,
Crypto.JNA_LIBRARY_NAME_DEFAULT);
OpenSslJna.debug("OpenSslNativeJna NativeLibrary.getInstance('%s')",
libraryName);
@SuppressWarnings("resource") // NativeLibrary.getInstance returns a
singleton
final NativeLibrary crypto = NativeLibrary.getInstance(libraryName);
diff --git a/src/main/java/org/apache/commons/crypto/utils/Utils.java
b/src/main/java/org/apache/commons/crypto/utils/Utils.java
index 3cada761..27afb62b 100644
--- a/src/main/java/org/apache/commons/crypto/utils/Utils.java
+++ b/src/main/java/org/apache/commons/crypto/utils/Utils.java
@@ -192,8 +192,8 @@ public final class Utils {
}
/*
- * Override the default DLL name if jni.library.path is a valid directory
- * If jni.library.name is defined, this overrides the default name.
+ * Override the default DLL name if Crypto.JNI_LIBRARY_PATH is a valid
directory
+ * If Crypto.JNI_LIBRARY_NAME is defined, this overrides the default name.
*
* @param name - the default name, passed from native code
* @return the updated library path
@@ -207,13 +207,13 @@ public final class Utils {
* In each case, there is a link from the canonical name (libcrypto.xx) to
the versioned name (libcrypto-1.2.3.xx)
* However on Windows, all the DLL versions seem to be stored in the same
directory.
* This means that Windows code needs to be given the versioned name (e.g.
libcrypto-1_1-x64)
- * This is done by defining jni.library.name.
+ * This is done by defining Crypto.JNI_LIBRARY_NAME.
*
* Do not change the method name or its signature!
*/
static String libraryPath(final String name) {
- final String overridename = System.getProperty("jni.library.name",
name);
- final String override = System.getProperty("jni.library.path");
+ final String overridename =
System.getProperty(Crypto.JNI_LIBRARY_NAME, name);
+ final String override = System.getProperty(Crypto.JNI_LIBRARY_PATH);
if (override != null && new File(override).isDirectory()) {
return new File(override, overridename).getPath();
}