You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/08/23 14:45:07 UTC

[commons-crypto] branch master updated (88b8c25 -> 07a9746)

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

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


    from 88b8c25  Format method for longer lines.
     new 0ecd5fe  Sort methods in AB order.
     new 07a9746  Javadoc. Better logging.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/commons/crypto/Crypto.java     |   7 +-
 .../apache/commons/crypto/NativeCodeLoader.java    | 340 +++++++++++----------
 2 files changed, 179 insertions(+), 168 deletions(-)


[commons-crypto] 02/02: Javadoc. Better logging.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 07a9746cab567397751f4a0357320f2ad6d80737
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Aug 23 10:45:01 2020 -0400

    Javadoc. Better logging.
---
 .../java/org/apache/commons/crypto/Crypto.java     |   7 +-
 .../apache/commons/crypto/NativeCodeLoader.java    | 330 +++++++++++----------
 2 files changed, 174 insertions(+), 163 deletions(-)

diff --git a/src/main/java/org/apache/commons/crypto/Crypto.java b/src/main/java/org/apache/commons/crypto/Crypto.java
index bf92e32..ed49610 100644
--- a/src/main/java/org/apache/commons/crypto/Crypto.java
+++ b/src/main/java/org/apache/commons/crypto/Crypto.java
@@ -34,7 +34,7 @@ import org.apache.commons.crypto.random.CryptoRandomFactory;
 public final class Crypto {
 
 	/**
-	 * The prefix of all crypto configuration keys
+	 * The prefix of all crypto configuration keys.
 	 */
 	public static final String CONF_PREFIX = "commons.crypto.";
 
@@ -156,8 +156,9 @@ public final class Crypto {
 				final Properties props = new Properties();
 				props.setProperty(CryptoCipherFactory.CLASSES_KEY,
 						CryptoCipherFactory.CipherProvider.OPENSSL.getClassName());
-				try (CryptoCipher cryptoCipher = CryptoCipherFactory.getCryptoCipher("AES/CTR/NoPadding", props)) {
-					System.out.println("Cipher instance created OK: " + cryptoCipher);
+				final String transformation = "AES/CTR/NoPadding";
+				try (CryptoCipher cryptoCipher = CryptoCipherFactory.getCryptoCipher(transformation, props)) {
+					System.out.printf("Cipher %s instance created OK: %s%n", transformation, cryptoCipher);
 				}
 			}
 			System.out.println("Additional OpenSSL_version(n) details:");
diff --git a/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java b/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
index 6c76a8d..b466e68 100644
--- a/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
+++ b/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
@@ -36,124 +36,123 @@ import org.apache.commons.crypto.utils.Utils;
  */
 final class NativeCodeLoader {
 
-    private static final Throwable loadingError;
+	private static final Throwable loadingError;
 
-    private final static boolean nativeCodeLoaded;
+	private final static boolean nativeCodeLoaded;
 
-    static {
-        loadingError = loadLibrary(); // will be null if loaded OK
+	static {
+		loadingError = loadLibrary(); // will be null if loaded OK
 
-        nativeCodeLoaded = loadingError == null;
-    }
-
-    /**
-     * Checks whether in1 and in2 is equal.
-     *
-     * @param in1 the input1.
-     * @param in2 the input2.
-     * @return true if in1 and in2 is equal, else false.
-     * @throws IOException if an I/O error occurs.
-     */
-    private static boolean contentsEquals(InputStream in1, InputStream in2)
-            throws IOException {
-        if (!(in1 instanceof BufferedInputStream)) {
-            in1 = new BufferedInputStream(in1);
-        }
-        if (!(in2 instanceof BufferedInputStream)) {
-            in2 = new BufferedInputStream(in2);
-        }
+		nativeCodeLoaded = loadingError == null;
+	}
 
-        int ch = in1.read();
-        while (ch != -1) {
-            final int ch2 = in2.read();
-            if (ch != ch2) {
-                return false;
-            }
-            ch = in1.read();
-        }
-        final int ch2 = in2.read();
-        return ch2 == -1;
-    }
+	/**
+	 * Checks whether in1 and in2 is equal.
+	 *
+	 * @param in1 the input1.
+	 * @param in2 the input2.
+	 * @return true if in1 and in2 is equal, else false.
+	 * @throws IOException if an I/O error occurs.
+	 */
+	private static boolean contentsEquals(InputStream in1, InputStream in2) throws IOException {
+		if (!(in1 instanceof BufferedInputStream)) {
+			in1 = new BufferedInputStream(in1);
+		}
+		if (!(in2 instanceof BufferedInputStream)) {
+			in2 = new BufferedInputStream(in2);
+		}
 
-    /**
-     * Extracts the specified library file to the target folder.
-     *
-     * @param libFolderForCurrentOS the library in commons-crypto.lib.path.
-     * @param libraryFileName the library name.
-     * @param targetFolder Target folder for the native lib. Use the value of
-     *        commons-crypto.tempdir or java.io.tmpdir.
-     * @return the library file.
-     */
-    private static File extractLibraryFile(final String libFolderForCurrentOS,
-        final String libraryFileName, final String targetFolder) {
-        final String nativeLibraryFilePath = libFolderForCurrentOS + "/" + libraryFileName;
+		int ch = in1.read();
+		while (ch != -1) {
+			final int ch2 = in2.read();
+			if (ch != ch2) {
+				return false;
+			}
+			ch = in1.read();
+		}
+		final int ch2 = in2.read();
+		return ch2 == -1;
+	}
 
-        // Attach UUID to the native library file to ensure multiple class
-        // loaders
-        // can read the libcommons-crypto multiple times.
-        final String uuid = UUID.randomUUID().toString();
-        final String extractedLibFileName = String.format("commons-crypto-%s-%s", uuid, libraryFileName);
-        final File extractedLibFile = new File(targetFolder, extractedLibFileName);
+	/**
+	 * Extracts the specified library file to the target folder.
+	 *
+	 * @param libFolderForCurrentOS the library in commons-crypto.lib.path.
+	 * @param libraryFileName       the library name.
+	 * @param targetFolder          Target folder for the native lib. Use the value
+	 *                              of commons-crypto.tempdir or java.io.tmpdir.
+	 * @return the library file.
+	 */
+	private static File extractLibraryFile(final String libFolderForCurrentOS, final String libraryFileName,
+			final String targetFolder) {
+		final String nativeLibraryFilePath = libFolderForCurrentOS + "/" + libraryFileName;
 
-        InputStream inputStream = null;
-        try {
-            // Extract a native library file into the target directory
-            inputStream = NativeCodeLoader.class.getResourceAsStream(nativeLibraryFilePath);
-            try (FileOutputStream writer = new FileOutputStream(extractedLibFile)) {
-                final byte[] buffer = new byte[8192];
-                int bytesRead;
-                while ((bytesRead = inputStream.read(buffer)) != -1) {
-                    writer.write(buffer, 0, bytesRead);
-                }
-            } finally {
-                // Delete the extracted lib file on JVM exit.
-                extractedLibFile.deleteOnExit();
+		// Attach UUID to the native library file to ensure multiple class
+		// loaders
+		// can read the libcommons-crypto multiple times.
+		final String uuid = UUID.randomUUID().toString();
+		final String extractedLibFileName = String.format("commons-crypto-%s-%s", uuid, libraryFileName);
+		final File extractedLibFile = new File(targetFolder, extractedLibFileName);
 
-                IoUtils.closeQuietly(inputStream);
-                inputStream = null;
-            }
+		InputStream inputStream = null;
+		try {
+			// Extract a native library file into the target directory
+			inputStream = NativeCodeLoader.class.getResourceAsStream(nativeLibraryFilePath);
+			try (FileOutputStream writer = new FileOutputStream(extractedLibFile)) {
+				final byte[] buffer = new byte[8192];
+				int bytesRead;
+				while ((bytesRead = inputStream.read(buffer)) != -1) {
+					writer.write(buffer, 0, bytesRead);
+				}
+			} finally {
+				// Delete the extracted lib file on JVM exit.
+				extractedLibFile.deleteOnExit();
 
-            // Set executable (x) flag to enable Java to load the native library
-            if (!extractedLibFile.setReadable(true) || !extractedLibFile.setExecutable(true)
-                || !extractedLibFile.setWritable(true, true)) {
-                throw new RuntimeException("Invalid path for library path");
-            }
+				IoUtils.closeQuietly(inputStream);
+				inputStream = null;
+			}
 
-            // Check whether the contents are properly copied from the resource
-            // folder
-            {
-                InputStream nativeIn = null;
-                InputStream extractedLibIn = null;
-                try {
-                    nativeIn = NativeCodeLoader.class.getResourceAsStream(nativeLibraryFilePath);
-                    extractedLibIn = new FileInputStream(extractedLibFile);
-                    if (!contentsEquals(nativeIn, extractedLibIn)) {
-                        throw new RuntimeException(
-                            String.format("Failed to write a native library file at %s", extractedLibFile));
-                    }
-                } finally {
-                    if (nativeIn != null) {
-                        nativeIn.close();
-                    }
-                    if (extractedLibIn != null) {
-                        extractedLibIn.close();
-                    }
-                }
-            }
+			// Set executable (x) flag to enable Java to load the native library
+			if (!extractedLibFile.setReadable(true) || !extractedLibFile.setExecutable(true)
+					|| !extractedLibFile.setWritable(true, true)) {
+				throw new RuntimeException("Invalid path for library path");
+			}
 
-            return extractedLibFile;
-        } catch (final IOException e) {
-            return null;
-        } finally {
-            IoUtils.closeQuietly(inputStream);
-        }
-    }
+			// Check whether the contents are properly copied from the resource
+			// folder
+			{
+				InputStream nativeIn = null;
+				InputStream extractedLibIn = null;
+				try {
+					nativeIn = NativeCodeLoader.class.getResourceAsStream(nativeLibraryFilePath);
+					extractedLibIn = new FileInputStream(extractedLibFile);
+					if (!contentsEquals(nativeIn, extractedLibIn)) {
+						throw new RuntimeException(
+								String.format("Failed to write a native library file at %s", extractedLibFile));
+					}
+				} finally {
+					if (nativeIn != null) {
+						nativeIn.close();
+					}
+					if (extractedLibIn != null) {
+						extractedLibIn.close();
+					}
+				}
+			}
+			debug("Extracted '%s' to '%s'", nativeLibraryFilePath, extractedLibFile);
+			return extractedLibFile;
+		} catch (final IOException e) {
+			return null;
+		} finally {
+			IoUtils.closeQuietly(inputStream);
+		}
+	}
 
-    /**
-     * Finds the native library.
-     *
-     * @return the jar file.
-     */
+	/**
+	 * Finds the native library.
+	 *
+	 * @return the jar file.
+	 */
 	private static File findNativeLibrary() {
 		// Get the properties once
 		final Properties props = Utils.getDefaultProperties();
@@ -186,13 +185,13 @@ final class NativeCodeLoader {
 		}
 
 		if (!hasNativeLib) {
-			final String errorMessage = String.format("no native library is found for os.name=%s and os.arch=%s",
+			final String errorMessage = String.format("No native library is found for os.name=%s and os.arch=%s",
 					OsInfo.getOSName(), OsInfo.getArchName());
 			throw new RuntimeException(errorMessage);
 		}
 
 		// Temporary folder for the native lib. Use the value of
-		// commons-crypto.tempdir or java.io.tmpdir
+		// Crypto.LIB_TEMPDIR_KEY or java.io.tmpdir
 		final String tempFolder = new File(
 				props.getProperty(Crypto.LIB_TEMPDIR_KEY, System.getProperty("java.io.tmpdir"))).getAbsolutePath();
 
@@ -200,60 +199,71 @@ final class NativeCodeLoader {
 		return extractLibraryFile(nativeLibraryPath, nativeLibraryName, tempFolder);
 	}
 
-    /**
-     * Gets the error cause if loading failed.
-     *
-     * @return null, unless loading failed
-     */
-    static Throwable getLoadingError() {
-        return loadingError;
-    }
+	/**
+	 * Gets the error cause if loading failed.
+	 *
+	 * @return null, unless loading failed
+	 */
+	static Throwable getLoadingError() {
+		return loadingError;
+	}
 
-    /**
-     * Checks whether the given path has resource.
-     *
-     * @param path the path.
-     * @return the boolean.
-     */
-    private static boolean hasResource(final String path) {
-        return NativeCodeLoader.class.getResource(path) != null;
-    }
+	/**
+	 * Checks whether the given path has resource.
+	 *
+	 * @param path the path.
+	 * @return the boolean.
+	 */
+	private static boolean hasResource(final String path) {
+		return NativeCodeLoader.class.getResource(path) != null;
+	}
+
+	/**
+	 * Checks whether native code is loaded for this platform.
+	 *
+	 * @return {@code true} if native is loaded, else {@code false}.
+	 */
+	static boolean isNativeCodeLoaded() {
+		return nativeCodeLoaded;
+	}
 
-    /**
-     * Checks whether native code is loaded for this platform.
-     *
-     * @return {@code true} if native is loaded, else {@code false}.
-     */
-    static boolean isNativeCodeLoaded() {
-        return nativeCodeLoaded;
-    }
+	/**
+	 * Loads the library if possible.
+	 *
+	 * @return null if successful, otherwise the Throwable that was caught
+	 */
+	static Throwable loadLibrary() {
+		try {
+			final File nativeLibFile = findNativeLibrary();
+			if (nativeLibFile != null) {
+				// Load extracted or specified native library.
+				System.load(nativeLibFile.getAbsolutePath());
+			} else {
+				// Load preinstalled library (in the path -Djava.library.path)
+				System.loadLibrary("commons-crypto");
+			}
+			return null; // OK
+		} catch (final Exception t) {
+			return t;
+		} catch (final UnsatisfiedLinkError t) {
+			return t;
+		}
+	}
 
-    /**
-     * Loads the library if possible.
-     *
-     * @return null if successful, otherwise the Throwable that was caught
-     */
-    static Throwable loadLibrary() {
-        try {
-            final File nativeLibFile = findNativeLibrary();
-            if (nativeLibFile != null) {
-                // Load extracted or specified native library.
-                System.load(nativeLibFile.getAbsolutePath());
-            } else {
-                // Load preinstalled library (in the path -Djava.library.path)
-                System.loadLibrary("commons-crypto");
-            }
-            return null; // OK
-        } catch (final Exception t) {
-            return t;
-        } catch (final UnsatisfiedLinkError t) {
-            return t;
-        }
-    }
+	/**
+	 * Logs debug information.
+	 *
+	 * @param format See {@link String#format(String, Object...)}.
+	 * @param args See {@link String#format(String, Object...)}.
+	 */
+	static void debug(final String format, Object... args) {
+		// TODO Find a better way to do this later.
+		// System.out.println(String.format(format, args));
+	}
 
-    /**
-     * The private constructor of {@link NativeCodeLoader}.
-     */
-    private NativeCodeLoader() {
-    }
+	/**
+	 * The private constructor of {@link NativeCodeLoader}.
+	 */
+	private NativeCodeLoader() {
+	}
 }


[commons-crypto] 01/02: Sort methods in AB order.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0ecd5fec80f63b6e533fed9f0c9763b7cfdee621
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Aug 23 10:10:39 2020 -0400

    Sort methods in AB order.
---
 .../apache/commons/crypto/NativeCodeLoader.java    | 202 ++++++++++-----------
 1 file changed, 101 insertions(+), 101 deletions(-)

diff --git a/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java b/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
index dcc1044..6c76a8d 100644
--- a/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
+++ b/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
@@ -36,15 +36,9 @@ import org.apache.commons.crypto.utils.Utils;
  */
 final class NativeCodeLoader {
 
-    private final static boolean nativeCodeLoaded;
-
     private static final Throwable loadingError;
 
-    /**
-     * The private constructor of {@link NativeCodeLoader}.
-     */
-    private NativeCodeLoader() {
-    }
+    private final static boolean nativeCodeLoaded;
 
     static {
         loadingError = loadLibrary(); // will be null if loaded OK
@@ -53,80 +47,35 @@ final class NativeCodeLoader {
     }
 
     /**
-     * Loads the library if possible.
+     * Checks whether in1 and in2 is equal.
      *
-     * @return null if successful, otherwise the Throwable that was caught
+     * @param in1 the input1.
+     * @param in2 the input2.
+     * @return true if in1 and in2 is equal, else false.
+     * @throws IOException if an I/O error occurs.
      */
-    static Throwable loadLibrary() {
-        try {
-            final File nativeLibFile = findNativeLibrary();
-            if (nativeLibFile != null) {
-                // Load extracted or specified native library.
-                System.load(nativeLibFile.getAbsolutePath());
-            } else {
-                // Load preinstalled library (in the path -Djava.library.path)
-                System.loadLibrary("commons-crypto");
+    private static boolean contentsEquals(InputStream in1, InputStream in2)
+            throws IOException {
+        if (!(in1 instanceof BufferedInputStream)) {
+            in1 = new BufferedInputStream(in1);
+        }
+        if (!(in2 instanceof BufferedInputStream)) {
+            in2 = new BufferedInputStream(in2);
+        }
+
+        int ch = in1.read();
+        while (ch != -1) {
+            final int ch2 = in2.read();
+            if (ch != ch2) {
+                return false;
             }
-            return null; // OK
-        } catch (final Exception t) {
-            return t;
-        } catch (final UnsatisfiedLinkError t) {
-            return t;
+            ch = in1.read();
         }
+        final int ch2 = in2.read();
+        return ch2 == -1;
     }
 
     /**
-     * Finds the native library.
-     *
-     * @return the jar file.
-     */
-	private static File findNativeLibrary() {
-		// Get the properties once
-		final Properties props = Utils.getDefaultProperties();
-
-		// Try to load the library in commons-crypto.lib.path */
-		String nativeLibraryPath = props.getProperty(Crypto.LIB_PATH_KEY);
-		String nativeLibraryName = props.getProperty(Crypto.LIB_NAME_KEY);
-
-		// Resolve the library file name with a suffix (e.g., dll, .so, etc.)
-		if (nativeLibraryName == null) {
-			nativeLibraryName = System.mapLibraryName("commons-crypto");
-		}
-		if (nativeLibraryPath != null) {
-			final File nativeLib = new File(nativeLibraryPath, nativeLibraryName);
-			if (nativeLib.exists()) {
-				return nativeLib;
-			}
-		}
-
-		// Load an OS-dependent native library inside a jar file
-		nativeLibraryPath = "/org/apache/commons/crypto/native/" + OsInfo.getNativeLibFolderPathForCurrentOS();
-		boolean hasNativeLib = hasResource(nativeLibraryPath + "/" + nativeLibraryName);
-		if (!hasNativeLib) {
-			final String altName = "libcommons-crypto.jnilib";
-			if (OsInfo.getOSName().equals("Mac") && hasResource(nativeLibraryPath + "/" + altName)) {
-				// Fix for openjdk7 for Mac
-				nativeLibraryName = altName;
-				hasNativeLib = true;
-			}
-		}
-
-		if (!hasNativeLib) {
-			final String errorMessage = String.format("no native library is found for os.name=%s and os.arch=%s",
-					OsInfo.getOSName(), OsInfo.getArchName());
-			throw new RuntimeException(errorMessage);
-		}
-
-		// Temporary folder for the native lib. Use the value of
-		// commons-crypto.tempdir or java.io.tmpdir
-		final String tempFolder = new File(
-				props.getProperty(Crypto.LIB_TEMPDIR_KEY, System.getProperty("java.io.tmpdir"))).getAbsolutePath();
-
-		// Extract and load a native library inside the jar file
-		return extractLibraryFile(nativeLibraryPath, nativeLibraryName, tempFolder);
-	}
-
-    /**
      * Extracts the specified library file to the target folder.
      *
      * @param libFolderForCurrentOS the library in commons-crypto.lib.path.
@@ -201,32 +150,63 @@ final class NativeCodeLoader {
     }
 
     /**
-     * Checks whether in1 and in2 is equal.
+     * Finds the native library.
      *
-     * @param in1 the input1.
-     * @param in2 the input2.
-     * @return true if in1 and in2 is equal, else false.
-     * @throws IOException if an I/O error occurs.
+     * @return the jar file.
      */
-    private static boolean contentsEquals(InputStream in1, InputStream in2)
-            throws IOException {
-        if (!(in1 instanceof BufferedInputStream)) {
-            in1 = new BufferedInputStream(in1);
-        }
-        if (!(in2 instanceof BufferedInputStream)) {
-            in2 = new BufferedInputStream(in2);
-        }
+	private static File findNativeLibrary() {
+		// Get the properties once
+		final Properties props = Utils.getDefaultProperties();
 
-        int ch = in1.read();
-        while (ch != -1) {
-            final int ch2 = in2.read();
-            if (ch != ch2) {
-                return false;
-            }
-            ch = in1.read();
-        }
-        final int ch2 = in2.read();
-        return ch2 == -1;
+		// Try to load the library in commons-crypto.lib.path */
+		String nativeLibraryPath = props.getProperty(Crypto.LIB_PATH_KEY);
+		String nativeLibraryName = props.getProperty(Crypto.LIB_NAME_KEY);
+
+		// Resolve the library file name with a suffix (e.g., dll, .so, etc.)
+		if (nativeLibraryName == null) {
+			nativeLibraryName = System.mapLibraryName("commons-crypto");
+		}
+		if (nativeLibraryPath != null) {
+			final File nativeLib = new File(nativeLibraryPath, nativeLibraryName);
+			if (nativeLib.exists()) {
+				return nativeLib;
+			}
+		}
+
+		// Load an OS-dependent native library inside a jar file
+		nativeLibraryPath = "/org/apache/commons/crypto/native/" + OsInfo.getNativeLibFolderPathForCurrentOS();
+		boolean hasNativeLib = hasResource(nativeLibraryPath + "/" + nativeLibraryName);
+		if (!hasNativeLib) {
+			final String altName = "libcommons-crypto.jnilib";
+			if (OsInfo.getOSName().equals("Mac") && hasResource(nativeLibraryPath + "/" + altName)) {
+				// Fix for openjdk7 for Mac
+				nativeLibraryName = altName;
+				hasNativeLib = true;
+			}
+		}
+
+		if (!hasNativeLib) {
+			final String errorMessage = String.format("no native library is found for os.name=%s and os.arch=%s",
+					OsInfo.getOSName(), OsInfo.getArchName());
+			throw new RuntimeException(errorMessage);
+		}
+
+		// Temporary folder for the native lib. Use the value of
+		// commons-crypto.tempdir or java.io.tmpdir
+		final String tempFolder = new File(
+				props.getProperty(Crypto.LIB_TEMPDIR_KEY, System.getProperty("java.io.tmpdir"))).getAbsolutePath();
+
+		// Extract and load a native library inside the jar file
+		return extractLibraryFile(nativeLibraryPath, nativeLibraryName, tempFolder);
+	}
+
+    /**
+     * Gets the error cause if loading failed.
+     *
+     * @return null, unless loading failed
+     */
+    static Throwable getLoadingError() {
+        return loadingError;
     }
 
     /**
@@ -249,11 +229,31 @@ final class NativeCodeLoader {
     }
 
     /**
-     * Gets the error cause if loading failed.
+     * Loads the library if possible.
      *
-     * @return null, unless loading failed
+     * @return null if successful, otherwise the Throwable that was caught
      */
-    static Throwable getLoadingError() {
-        return loadingError;
+    static Throwable loadLibrary() {
+        try {
+            final File nativeLibFile = findNativeLibrary();
+            if (nativeLibFile != null) {
+                // Load extracted or specified native library.
+                System.load(nativeLibFile.getAbsolutePath());
+            } else {
+                // Load preinstalled library (in the path -Djava.library.path)
+                System.loadLibrary("commons-crypto");
+            }
+            return null; // OK
+        } catch (final Exception t) {
+            return t;
+        } catch (final UnsatisfiedLinkError t) {
+            return t;
+        }
+    }
+
+    /**
+     * The private constructor of {@link NativeCodeLoader}.
+     */
+    private NativeCodeLoader() {
     }
 }