Skip to content

Commit

Permalink
Clarify that constant is a property name
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbASF committed Nov 27, 2023
1 parent 472756d commit b297948
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions src/main/java/org/apache/commons/crypto/Crypto.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,23 @@ private static Properties getComponentProperties() {
* 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";
public static final String JNI_LIBRARY_PATH_PROPERTY = "jni.library.path";

/**
* Override property for the default SSL crypto library name when using JNI
*/
public static final String JNI_LIBRARY_NAME = "commons.crypto.OpenSslNativeJni";
public static final String JNI_LIBRARY_NAME_PROPERTY = "commons.crypto.OpenSslNativeJni";

/**
* 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";
public static final String JNA_LIBRARY_PATH_PROPERTY = "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";
public static final String JNA_LIBRARY_NAME_PROPERTY = Crypto.CONF_PREFIX + "OpenSslNativeJna";

/** Default name for loading SSL crypto library using JNA */
public static final String JNA_LIBRARY_NAME_DEFAULT = "crypto";
Expand Down Expand Up @@ -184,8 +184,8 @@ public static boolean isNativeCodeLoaded() {
*/
public static void main(final String[] args) throws Exception {
quiet = args.length == 1 && args[0].equals("-q");
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", JNI_LIBRARY_PATH_PROPERTY, System.getProperty(JNI_LIBRARY_PATH_PROPERTY));
info("%s=%s", JNI_LIBRARY_NAME_PROPERTY, System.getProperty(JNI_LIBRARY_NAME_PROPERTY));
info("%s %s", getComponentName(), getComponentVersion());
if (isNativeCodeLoaded()) {
info("Native code loaded OK: %s", OpenSslInfoNative.NativeVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class LibreSsl20XNativeJna implements OpenSslInterfaceNativeJna {
boolean ok = false;
Throwable thrown = null;
try {
final String libName = System.getProperty(Crypto.JNA_LIBRARY_NAME, Crypto.JNA_LIBRARY_NAME_DEFAULT);
final String libName = System.getProperty(Crypto.JNA_LIBRARY_NAME_PROPERTY, Crypto.JNA_LIBRARY_NAME_DEFAULT);
OpenSslJna.debug("Native.register('%s')", libName);
Native.register(libName);
ok = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class OpenSsl11XNativeJna implements OpenSslInterfaceNativeJna {
boolean ok = false;
Throwable thrown = null;
try {
final String libName = System.getProperty(Crypto.JNA_LIBRARY_NAME, Crypto.JNA_LIBRARY_NAME_DEFAULT);
final String libName = System.getProperty(Crypto.JNA_LIBRARY_NAME_PROPERTY, Crypto.JNA_LIBRARY_NAME_DEFAULT);
OpenSslJna.debug("Native.register('%s')", libName);
Native.register(libName);
ok = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class OpenSsl30XNativeJna implements OpenSslInterfaceNativeJna {
boolean ok = false;
Throwable thrown = null;
try {
final String libName = System.getProperty(Crypto.JNA_LIBRARY_NAME, Crypto.JNA_LIBRARY_NAME_DEFAULT);
final String libName = System.getProperty(Crypto.JNA_LIBRARY_NAME_PROPERTY, Crypto.JNA_LIBRARY_NAME_DEFAULT);
OpenSslJna.debug("Native.register('%s')", libName);
Native.register(libName);
ok = true;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/apache/commons/crypto/jna/OpenSslJna.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public static boolean isEnabled() {
*/
public static void main(final String[] args) throws Throwable {
// These are used by JNA code if defined:
info("%s=%s", Crypto.JNA_LIBRARY_PATH, System.getProperty(Crypto.JNA_LIBRARY_PATH));
info("%s=%s", Crypto.JNA_LIBRARY_PATH_PROPERTY, System.getProperty(Crypto.JNA_LIBRARY_PATH_PROPERTY));
info("jna.platform.library.path=%s", System.getProperty("jna.platform.library.path"));
info("%s=%s\n", Crypto.JNA_LIBRARY_NAME, System.getProperty(Crypto.JNA_LIBRARY_NAME));
info("%s=%s\n", Crypto.JNA_LIBRARY_NAME_PROPERTY, System.getProperty(Crypto.JNA_LIBRARY_NAME_PROPERTY));
// 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ final class OpenSslNativeJna {

static {
OpenSslJna.debug("OpenSslNativeJna static init start");
final String libraryName = System.getProperty(Crypto.JNA_LIBRARY_NAME, Crypto.JNA_LIBRARY_NAME_DEFAULT);
final String libraryName = System.getProperty(Crypto.JNA_LIBRARY_NAME_PROPERTY, Crypto.JNA_LIBRARY_NAME_DEFAULT);
OpenSslJna.debug("OpenSslNativeJna NativeLibrary.getInstance('%s')", libraryName);
// CRYPTO-179 - avoid crash
if ("Mac OS X".equals(System.getProperty("os.name"))
&& System.getProperty(Crypto.JNA_LIBRARY_NAME, "").isEmpty()
&& System.getProperty(Crypto.JNA_LIBRARY_PATH, "").isEmpty()
&& System.getProperty(Crypto.JNA_LIBRARY_NAME_PROPERTY, "").isEmpty()
&& System.getProperty(Crypto.JNA_LIBRARY_PATH_PROPERTY, "").isEmpty()
) {
String ret = OpenSslMacOS.checkLibrary(Crypto.MACOS_LIBRARY_NAME_DEFAULT);
if (ret != null) {
throw new UnsatisfiedLinkError(
String.format("Cannot load default library '%s'; please define %s! (%s)",
Crypto.MACOS_LIBRARY_NAME_DEFAULT, Crypto.JNA_LIBRARY_PATH, ret));
Crypto.MACOS_LIBRARY_NAME_DEFAULT, Crypto.JNA_LIBRARY_PATH_PROPERTY, ret));
}
}
@SuppressWarnings("resource") // NativeLibrary.getInstance returns a singleton
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/apache/commons/crypto/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ public static Properties getProperties(final Properties newProp) {
* Do not change the method name or its signature!
*/
static String libraryPath(final String name) {
final String overridename = System.getProperty(Crypto.JNI_LIBRARY_NAME, name);
final String override = System.getProperty(Crypto.JNI_LIBRARY_PATH);
final String overridename = System.getProperty(Crypto.JNI_LIBRARY_NAME_PROPERTY, name);
final String override = System.getProperty(Crypto.JNI_LIBRARY_PATH_PROPERTY);
if (override != null && new File(override).isDirectory()) {
return new File(override, overridename).getPath();
}
Expand Down

0 comments on commit b297948

Please sign in to comment.