You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by sd...@apache.org on 2016/07/22 07:00:29 UTC

[01/50] commons-crypto git commit: Show version if available; warn if JNI/JNA could not be init

Repository: commons-crypto
Updated Branches:
  refs/heads/CRYPTO-1.0.0 1335e165e -> ed1b6097c


Show version if available; warn if JNI/JNA could not be init

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/c4462318
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/c4462318
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/c4462318

Branch: refs/heads/CRYPTO-1.0.0
Commit: c4462318fb061ec454849f1a3beb58c4138a22c0
Parents: d3e86ff
Author: Sebb <se...@apache.org>
Authored: Thu Jul 7 17:56:36 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Thu Jul 7 17:56:36 2016 +0100

----------------------------------------------------------------------
 .../org/apache/commons/crypto/NativeCodeLoaderTest.java | 12 ++++++++++++
 1 file changed, 12 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/c4462318/src/test/java/org/apache/commons/crypto/NativeCodeLoaderTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/NativeCodeLoaderTest.java b/src/test/java/org/apache/commons/crypto/NativeCodeLoaderTest.java
index f4fa6e3..ff871de 100644
--- a/src/test/java/org/apache/commons/crypto/NativeCodeLoaderTest.java
+++ b/src/test/java/org/apache/commons/crypto/NativeCodeLoaderTest.java
@@ -31,6 +31,18 @@ import org.junit.Test;
 public class NativeCodeLoaderTest {
 
     @Test
+    public void test() {
+        if (NativeCodeLoader.isNativeCodeLoaded()) {
+            // TODO display versions once available
+            System.out.println("** INFO: Native (JNI) code loaded successfully");
+        } else {
+            System.out.println("** WARN: Native (JNI) code was not loaded: " 
+                + NativeCodeLoader.getLoadingError());
+        }
+        assertNotNull(NativeCodeLoader.getVersion());
+    }
+
+    @Test
     public void testGetVersion() {
         assertNotNull(NativeCodeLoader.getVersion());
     }


[47/50] commons-crypto git commit: CRYPTO-117: Define WINDOWS when _WIN64 and CYGWIN defined

Posted by sd...@apache.org.
CRYPTO-117: Define WINDOWS when _WIN64 and CYGWIN defined


Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/6488aa6e
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/6488aa6e
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/6488aa6e

Branch: refs/heads/CRYPTO-1.0.0
Commit: 6488aa6e9a617b0f27af6c1c4a8febd4540f37b1
Parents: 514dc16
Author: Sun Dapeng <sd...@apache.org>
Authored: Tue Jul 19 17:32:20 2016 +0800
Committer: Sun Dapeng <sd...@apache.org>
Committed: Tue Jul 19 17:32:20 2016 +0800

----------------------------------------------------------------------
 .../native/org/apache/commons/crypto/org_apache_commons_crypto.h   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/6488aa6e/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
----------------------------------------------------------------------
diff --git a/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h b/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
index 4671314..1edc4ee 100644
--- a/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
+++ b/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
@@ -24,7 +24,7 @@
 #if !defined ORG_APACHE_COMMONS_CRYPTO_H
 #define ORG_APACHE_COMMONS_CRYPTO_H
 
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
 #undef UNIX
 #define WINDOWS
 #else


[18/50] commons-crypto git commit: CRYPTO-110 Provide component version and name

Posted by sd...@apache.org.
CRYPTO-110 Provide component version and name

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/c4db965e
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/c4db965e
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/c4db965e

Branch: refs/heads/CRYPTO-1.0.0
Commit: c4db965e38b7a101b2747d845d757ac5dba17aba
Parents: d58e6f3
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 13:42:02 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 13:42:02 2016 +0100

----------------------------------------------------------------------
 .../java/org/apache/commons/crypto/Crypto.java  | 51 ++++++++++++++++++++
 .../apache/commons/crypto/component.properties  | 20 ++++++++
 .../org/apache/commons/crypto/CryptoTest.java   | 43 +++++++++++++++++
 3 files changed, 114 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/c4db965e/src/main/java/org/apache/commons/crypto/Crypto.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/Crypto.java b/src/main/java/org/apache/commons/crypto/Crypto.java
index e7aa101..d913878 100644
--- a/src/main/java/org/apache/commons/crypto/Crypto.java
+++ b/src/main/java/org/apache/commons/crypto/Crypto.java
@@ -17,6 +17,11 @@
  */
 package org.apache.commons.crypto;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Properties;
+
 /**
  * Provides diagnostic information about Commons Crypto and keys for native class loading
  */
@@ -45,6 +50,23 @@ public final class Crypto {
     public static final String LIB_TEMPDIR_KEY = Crypto.CONF_PREFIX
             + "lib.tempdir";
 
+    private static class ComponentPropertiesHolder {
+        static final Properties PROPERTIES = getComponentProperties();
+
+        private static Properties getComponentProperties() {
+            URL url = Crypto.class.getResource("/org/apache/commons/crypto/component.properties");
+            if (url != null) {
+                Properties versionData = new Properties();
+                try (InputStream openStream = url.openStream()) {
+                    versionData.load(openStream);
+                    return versionData;
+                } catch (IOException e) {
+                }
+            }
+            return new Properties(); // make sure field is not null
+        }
+     }
+
     /**
      * Checks whether the native code has been successfully loaded for the platform.
      * 
@@ -62,4 +84,33 @@ public final class Crypto {
     public static Throwable getLoadingError() {
         return NativeCodeLoader.getLoadingError();
     }
+
+    /**
+     * Gets the component version of Apache Commons Crypto.
+     * <p>
+     * This implementation relies on the VERSION properties file which
+     * must be set up with the correct contents by the build process.
+     * This is done automatically by Maven.
+     *
+     * @return the version; may be null if not found
+     */
+    public static String getComponentVersion() {
+        // Note: the component properties file allows the method to work without needing the jar
+        return ComponentPropertiesHolder.PROPERTIES.getProperty("VERSION");
+    }
+
+    /**
+     * Gets the component version of Apache Commons Crypto.
+     * <p>
+     * This implementation relies on the VERSION properties file which
+     * must be set up with the correct contents by the build process.
+     * This is done automatically by Maven.
+     *
+     * @return the version; may be null if not found
+     */
+    public static String getComponentName() {
+        // Note: the component properties file allows the method to work without needing the jar
+        return ComponentPropertiesHolder.PROPERTIES.getProperty("NAME");
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/c4db965e/src/main/resources/org/apache/commons/crypto/component.properties
----------------------------------------------------------------------
diff --git a/src/main/resources/org/apache/commons/crypto/component.properties b/src/main/resources/org/apache/commons/crypto/component.properties
new file mode 100644
index 0000000..3889e45
--- /dev/null
+++ b/src/main/resources/org/apache/commons/crypto/component.properties
@@ -0,0 +1,20 @@
+# 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.
+#
+
+# This file gives access to the component string from Java
+
+VERSION=${project.version}
+NAME=${project.name}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/c4db965e/src/test/java/org/apache/commons/crypto/CryptoTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/CryptoTest.java b/src/test/java/org/apache/commons/crypto/CryptoTest.java
new file mode 100644
index 0000000..065ea77
--- /dev/null
+++ b/src/test/java/org/apache/commons/crypto/CryptoTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class CryptoTest {
+
+    @Test
+    // This test may fail unless the code was built by Maven, as
+    // it relies on the VERSION file being set up correctly
+    public void testGetComponentVersion() {
+        String version = Crypto.getComponentVersion();
+        Assert.assertNotNull("Should not be null",version);
+        Assert.assertTrue(version,version.matches("^\\d+\\.\\d+.*"));
+    }
+
+    @Test
+    // This test may fail unless the code was built by Maven, as
+    // it relies on the VERSION file being set up correctly
+    public void testGetComponentName() {
+        String version = Crypto.getComponentName();
+        Assert.assertNotNull("Should not be null",version);
+        Assert.assertTrue(version,version.matches("^Apache Commons Crypto.*"));
+    }
+
+}


[08/50] commons-crypto git commit: Formatting: Missing spaces.

Posted by sd...@apache.org.
Formatting: Missing spaces.

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/9e83ff37
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/9e83ff37
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/9e83ff37

Branch: refs/heads/CRYPTO-1.0.0
Commit: 9e83ff37380517964033a183e5501a2409fea018
Parents: 2a9b994
Author: ggregory <gg...@apache.org>
Authored: Fri Jul 8 09:18:37 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Fri Jul 8 09:18:37 2016 -0700

----------------------------------------------------------------------
 .../org/apache/commons/crypto/random/AbstractRandomTest.java   | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9e83ff37/src/test/java/org/apache/commons/crypto/random/AbstractRandomTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/random/AbstractRandomTest.java b/src/test/java/org/apache/commons/crypto/random/AbstractRandomTest.java
index fe75490..1d49bc4 100644
--- a/src/test/java/org/apache/commons/crypto/random/AbstractRandomTest.java
+++ b/src/test/java/org/apache/commons/crypto/random/AbstractRandomTest.java
@@ -50,7 +50,7 @@ public abstract class AbstractRandomTest {
         final CryptoRandom random = getCryptoRandom();
         final List<Thread> threads = new ArrayList<>(threadCount);
 
-        for(int i=0; i< threadCount; i++) {
+        for (int i = 0; i < threadCount; i++) {
             Thread t = new Thread(new Runnable() {
                 @Override
                 public void run() {
@@ -63,8 +63,8 @@ public abstract class AbstractRandomTest {
             threads.add(t);
         }
 
-        for(Thread t: threads) {
-            if(!t.getState().equals(State.NEW)) {
+        for (Thread t : threads) {
+            if (!t.getState().equals(State.NEW)) {
                 t.join();
             }
         }


[33/50] commons-crypto git commit: And class name

Posted by sd...@apache.org.
And class name

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/bc7c1167
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/bc7c1167
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/bc7c1167

Branch: refs/heads/CRYPTO-1.0.0
Commit: bc7c11671931745c46a9b0a5647a57f259eee7c7
Parents: 64ad87d
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 23:51:22 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 23:51:22 2016 +0100

----------------------------------------------------------------------
 .../org/apache/commons/crypto/random/OpenSslCryptoRandomTest.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/bc7c1167/src/test/java/org/apache/commons/crypto/random/OpenSslCryptoRandomTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/random/OpenSslCryptoRandomTest.java b/src/test/java/org/apache/commons/crypto/random/OpenSslCryptoRandomTest.java
index 4784b18..1039023 100644
--- a/src/test/java/org/apache/commons/crypto/random/OpenSslCryptoRandomTest.java
+++ b/src/test/java/org/apache/commons/crypto/random/OpenSslCryptoRandomTest.java
@@ -25,7 +25,7 @@ import org.junit.Assume;
 
 import static org.junit.Assert.fail;
 
-public class OpensslCryptoRandomTest extends AbstractRandomTest {
+public class OpenSslCryptoRandomTest extends AbstractRandomTest {
 
     @Override
     public CryptoRandom getCryptoRandom() throws GeneralSecurityException {


[26/50] commons-crypto git commit: CRYPTO-112 OpenSslCipher.loadingFailureReason should be a Throwable

Posted by sd...@apache.org.
CRYPTO-112 OpenSslCipher.loadingFailureReason should be a Throwable

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/b17af9d9
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/b17af9d9
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/b17af9d9

Branch: refs/heads/CRYPTO-1.0.0
Commit: b17af9d959fbf653c5597369dbb83ca8545b56f3
Parents: f4d5737
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 17:50:40 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 17:50:40 2016 +0100

----------------------------------------------------------------------
 .../java/org/apache/commons/crypto/cipher/OpenSsl.java  | 12 ++++++------
 .../org/apache/commons/crypto/cipher/OpenSslCipher.java |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/b17af9d9/src/main/java/org/apache/commons/crypto/cipher/OpenSsl.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/OpenSsl.java b/src/main/java/org/apache/commons/crypto/cipher/OpenSsl.java
index 0898158..1820b47 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/OpenSsl.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/OpenSsl.java
@@ -86,20 +86,20 @@ final class OpenSsl {
     private final int algorithm;
     private final int padding;
 
-    private static final String loadingFailureReason;
+    private static final Throwable loadingFailureReason;
 
     static {
-        String loadingFailure = null;
+        Throwable loadingFailure = null;
         try {
             if (Crypto.isNativeCodeLoaded()) {
                 OpenSslNative.initIDs();
             } else {
-                loadingFailure = Crypto.getLoadingError().getMessage();
+                loadingFailure = Crypto.getLoadingError();
             }
         } catch (Exception t) {
-            loadingFailure = t.getMessage();
+            loadingFailure = t;
         } catch (UnsatisfiedLinkError t) {
-            loadingFailure = t.getMessage();            
+            loadingFailure = t;            
         } finally {
             loadingFailureReason = loadingFailure;
         }
@@ -110,7 +110,7 @@ final class OpenSsl {
      *
      * @return the failure reason; null if it was loaded and initialised successfully
      */
-    public static String getLoadingFailureReason() {
+    public static Throwable getLoadingFailureReason() {
         return loadingFailureReason;
     }
 

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/b17af9d9/src/main/java/org/apache/commons/crypto/cipher/OpenSslCipher.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/OpenSslCipher.java b/src/main/java/org/apache/commons/crypto/cipher/OpenSslCipher.java
index c8fe0b5..dff7dad 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/OpenSslCipher.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/OpenSslCipher.java
@@ -54,7 +54,7 @@ class OpenSslCipher implements CryptoCipher {
             throws GeneralSecurityException {
         this.transformation = transformation;
 
-        String loadingFailureReason = OpenSsl.getLoadingFailureReason();
+        Throwable loadingFailureReason = OpenSsl.getLoadingFailureReason();
         if (loadingFailureReason != null) {
             throw new RuntimeException(loadingFailureReason);
         }


[35/50] commons-crypto git commit: CRYPTO-114 exception.c/exception.h are not used

Posted by sd...@apache.org.
CRYPTO-114 exception.c/exception.h are not used

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/4ac4fedf
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/4ac4fedf
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/4ac4fedf

Branch: refs/heads/CRYPTO-1.0.0
Commit: 4ac4fedf1bbe662e8c485eee653f9dbe34f2b853
Parents: 79502d4
Author: Sebb <se...@apache.org>
Authored: Sun Jul 10 12:50:21 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sun Jul 10 12:50:21 2016 +0100

----------------------------------------------------------------------
 .../org/apache/commons/crypto/exception.c       | 124 -------------------
 .../org/apache/commons/crypto/exception.h       | 104 ----------------
 2 files changed, 228 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/4ac4fedf/src/main/native/org/apache/commons/crypto/exception.c
----------------------------------------------------------------------
diff --git a/src/main/native/org/apache/commons/crypto/exception.c b/src/main/native/org/apache/commons/crypto/exception.c
deleted file mode 100644
index fc072e8..0000000
--- a/src/main/native/org/apache/commons/crypto/exception.c
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- * 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.
- */
-
-#include "exception.h"
-
-#include <jni.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-jthrowable newExceptionV(JNIEnv* env, const char *name,
-                         const char *fmt, va_list ap)
-{
-  int need;
-  char buf[1], *msg = NULL;
-  va_list ap2;
-  jstring jstr = NULL;
-  jthrowable jthr;
-  jclass clazz;
-  jmethodID excCtor;
-
-  va_copy(ap2, ap);
-  clazz = (*env)->FindClass(env, name);
-  if (!clazz) {
-    jthr = (*env)->ExceptionOccurred(env);
-    (*env)->ExceptionClear(env);
-    goto done;
-  }
-  excCtor = (*env)->GetMethodID(env,
-        clazz, "<init>", "(Ljava/lang/String;)V");
-  if (!excCtor) {
-    jthr = (*env)->ExceptionOccurred(env);
-    (*env)->ExceptionClear(env);
-    goto done;
-  }
-  need = vsnprintf(buf, sizeof(buf), fmt, ap);
-  if (need < 0) {
-    fmt = "vsnprintf error";
-    need = strlen(fmt);
-  }
-  msg = malloc(need + 1);
-  vsnprintf(msg, need + 1, fmt, ap2);
-  jstr = (*env)->NewStringUTF(env, msg);
-  if (!jstr) {
-    jthr = (*env)->ExceptionOccurred(env);
-    (*env)->ExceptionClear(env);
-    goto done;
-  }
-  jthr = (*env)->NewObject(env, clazz, excCtor, jstr);
-  if (!jthr) {
-    jthr = (*env)->ExceptionOccurred(env);
-    (*env)->ExceptionClear(env);
-    goto done;
-  }
-
-done:
-  free(msg);
-  va_end(ap2);
-  (*env)->DeleteLocalRef(env, jstr);
-  return jthr;
-}
-
-jthrowable newException(JNIEnv* env, const char *name, const char *fmt, ...)
-{
-  va_list ap;
-  jthrowable jthr;
-
-  va_start(ap, fmt);
-  jthr = newExceptionV(env, name, fmt, ap);
-  va_end(ap);
-  return jthr;
-}
-
-jthrowable newRuntimeException(JNIEnv* env, const char *fmt, ...)
-{
-  va_list ap;
-  jthrowable jthr;
-
-  va_start(ap, fmt);
-  jthr = newExceptionV(env, "java/lang/RuntimeException", fmt, ap);
-  va_end(ap);
-  return jthr;
-}
-
-jthrowable newIOException(JNIEnv* env, const char *fmt, ...)
-{
-  va_list ap;
-  jthrowable jthr;
-
-  va_start(ap, fmt);
-  jthr = newExceptionV(env, "java/io/IOException", fmt, ap);
-  va_end(ap);
-  return jthr;
-}
-
-const char* terror(int errnum)
-{
-
-#if defined(__sun)
-// MT-Safe under Solaris which doesn't support sys_errlist/sys_nerr
-  return strerror(errnum); 
-#else
-  if ((errnum < 0) || (errnum >= sys_nerr)) {
-    return "unknown error.";
-  }
-  return sys_errlist[errnum];
-#endif
-}
-

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/4ac4fedf/src/main/native/org/apache/commons/crypto/exception.h
----------------------------------------------------------------------
diff --git a/src/main/native/org/apache/commons/crypto/exception.h b/src/main/native/org/apache/commons/crypto/exception.h
deleted file mode 100644
index d67d553..0000000
--- a/src/main/native/org/apache/commons/crypto/exception.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- *  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.
- */
-#ifndef COMMONS_CRYPTO_NATIVE_SRC_EXCEPTION_H
-#define COMMONS_CRYPTO_NATIVE_SRC_EXCEPTION_H
-
-#include <jni.h> /* for jthrowable */
-#include <stdarg.h> /* for va_list */
-#include "org_apache_commons_crypto.h"
-
-#ifdef WINDOWS
-/*
- * gcc-style type-checked format arguments are not supported on Windows, so just
- * stub this macro.
- */
-#define TYPE_CHECKED_PRINTF_FORMAT(formatArg, varArgs)
-# else
-/* Use gcc type-checked format arguments. */
-#define TYPE_CHECKED_PRINTF_FORMAT(formatArg, varArgs) \
-  __attribute__((format(printf, formatArg, varArgs)))
-#endif
-
-/**
- * Create a new Exception.
- *
- * No exceptions will be pending on return.
- *
- * @param env           The JNI environment
- * @param name          full name of the Java exception class
- * @param fmt           printf-style format string
- * @param ap            printf-style arguments
- *
- * @return              The RuntimeException
- */
-jthrowable newExceptionV(JNIEnv* env, const char *name,
-                         const char *fmt, va_list ap);
-
-/**
- * Create a new Exception.
- *
- * No exceptions will be pending on return.
- *
- * @param env           The JNI environment
- * @param name          full name of the Java exception class
- * @param fmt           printf-style format string
- * @param ...           printf-style arguments
- *
- * @return              The RuntimeException
- */
-jthrowable newException(JNIEnv* env, const char *name, const char *fmt, ...)
-    TYPE_CHECKED_PRINTF_FORMAT(3, 4);
-
-/**
- * Create a new RuntimeException.
- *
- * No exceptions will be pending on return.
- *
- * @param env           The JNI environment
- * @param fmt           printf-style format string
- * @param ...           printf-style arguments
- *
- * @return              The RuntimeException
- */
-jthrowable newRuntimeException(JNIEnv* env, const char *fmt, ...)
-    TYPE_CHECKED_PRINTF_FORMAT(2, 3);
-
-/**
- * Create a new IOException.
- *
- * No exceptions will be pending on return.
- *
- * @param env           The JNI environment
- * @param fmt           printf-style format string
- * @param ...           printf-style arguments
- *
- * @return              The IOException, or another exception if we failed
- *                      to create the NativeIOException.
- */
-jthrowable newIOException(JNIEnv* env, const char *fmt, ...)
-    TYPE_CHECKED_PRINTF_FORMAT(2, 3);
-
-/**
- * Thread-safe strerror alternative.
- *
- * @param errnum        Error number.
- * @return              Statically allocated error string.
- */
-const char* terror(int errnum);
-
-#undef TYPE_CHECKED_PRINTF_FORMAT
-#endif


[15/50] commons-crypto git commit: Javadoc

Posted by sd...@apache.org.
Javadoc

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/211498eb
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/211498eb
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/211498eb

Branch: refs/heads/CRYPTO-1.0.0
Commit: 211498ebd6e0cf795d6a62c3277cf645ab17e8b3
Parents: e5a6548
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 12:04:39 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 12:04:39 2016 +0100

----------------------------------------------------------------------
 src/main/java/org/apache/commons/crypto/OsInfo.java | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/211498eb/src/main/java/org/apache/commons/crypto/OsInfo.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/OsInfo.java b/src/main/java/org/apache/commons/crypto/OsInfo.java
index e7373de..4c2e20f 100644
--- a/src/main/java/org/apache/commons/crypto/OsInfo.java
+++ b/src/main/java/org/apache/commons/crypto/OsInfo.java
@@ -23,6 +23,7 @@ import java.util.Locale;
 
 /**
  * Provides OS name and architecture name.
+ * Used by the JNI make process to get information from the build environment.
  */
 final class OsInfo {
     private final static HashMap<String, String> archMapping = new HashMap<>();


[22/50] commons-crypto git commit: /lib/ directory contains valid source files!

Posted by sd...@apache.org.
/lib/ directory contains valid source files!

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/de52abef
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/de52abef
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/de52abef

Branch: refs/heads/CRYPTO-1.0.0
Commit: de52abeffa44dc7f4b2df9112e82c240c7ba68f8
Parents: 1214484
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 15:29:29 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 15:29:29 2016 +0100

----------------------------------------------------------------------
 .gitignore | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/de52abef/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index f5a8711..ba3f194 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,7 +31,6 @@ checkpoint
 derby.log
 dist/
 unit-tests.log
-/lib/
 src/main/resources/com/intel/chimera/native/
 src/main/resources/com/intel/chimera/native/*
 .externalToolBuilders/*


[23/50] commons-crypto git commit: Fix up Windows build:

Posted by sd...@apache.org.
Fix up Windows build:

Needs config.h
Needs Unicode String

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/2d38230a
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/2d38230a
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/2d38230a

Branch: refs/heads/CRYPTO-1.0.0
Commit: 2d38230a36503dada2aadfd430369ab47fb5f715
Parents: de52abe
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 15:30:33 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 15:30:33 2016 +0100

----------------------------------------------------------------------
 lib/include/config.h                                               | 2 +-
 .../native/org/apache/commons/crypto/org_apache_commons_crypto.h   | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/2d38230a/lib/include/config.h
----------------------------------------------------------------------
diff --git a/lib/include/config.h b/lib/include/config.h
index 8b4c1d4..93d90ef 100755
--- a/lib/include/config.h
+++ b/lib/include/config.h
@@ -20,7 +20,7 @@
 #define __CONFIG_H
 
 #if defined(WINDOWS)
-    #define COMMONS_CRYPTO_OPENSSL_LIBRARY "libcrypto.dll"
+    #define COMMONS_CRYPTO_OPENSSL_LIBRARY L"libcrypto.dll"
 #elif defined(MAC_OS)
     #define COMMONS_CRYPTO_OPENSSL_LIBRARY "libcrypto.dylib"
 #else

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/2d38230a/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
----------------------------------------------------------------------
diff --git a/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h b/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
index d0e58a5..f39faa7 100644
--- a/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
+++ b/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
@@ -193,6 +193,7 @@ static FARPROC WINAPI do_dlsym(JNIEnv *env, HMODULE handle, LPCSTR symbol) {
 #endif
 
 #ifdef WINDOWS
+#include "config.h"
 #include "winutils.h"
 #endif
 


[31/50] commons-crypto git commit: winutils.h not needed on Windows

Posted by sd...@apache.org.
winutils.h not needed on Windows

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/fab44563
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/fab44563
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/fab44563

Branch: refs/heads/CRYPTO-1.0.0
Commit: fab44563bddf4e8d5df6cf9a88bfa0e1a76495e7
Parents: f880ccf
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 23:32:14 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 23:32:14 2016 +0100

----------------------------------------------------------------------
 .../org/apache/commons/crypto/org_apache_commons_crypto.h     | 7 -------
 1 file changed, 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/fab44563/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
----------------------------------------------------------------------
diff --git a/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h b/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
index 4fbcc83..4671314 100644
--- a/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
+++ b/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
@@ -190,14 +190,7 @@ static FARPROC WINAPI do_dlsym(JNIEnv *env, HMODULE handle, LPCSTR symbol) {
   ret = expr; \
 } while ((ret == -1) && (errno == EINTR));
 
-#ifdef UNIX
-#include "config.h"
-#endif
-
-#ifdef WINDOWS
 #include "config.h"
-#include "winutils.h"
-#endif
 
 #include <openssl/aes.h>
 #include <openssl/evp.h>


[40/50] commons-crypto git commit: CRYPTO-104 Native code should provide getVersion() methods

Posted by sd...@apache.org.
CRYPTO-104 Native code should provide getVersion() methods

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/eaed08d0
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/eaed08d0
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/eaed08d0

Branch: refs/heads/CRYPTO-1.0.0
Commit: eaed08d07d0d7800c48e428061d919130fba0733
Parents: dba8b4a
Author: Sebb <se...@apache.org>
Authored: Mon Jul 11 00:45:55 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Mon Jul 11 00:45:55 2016 +0100

----------------------------------------------------------------------
 Makefile                                        |   9 +-
 pom.xml                                         |   1 +
 .../java/org/apache/commons/crypto/Crypto.java  |  11 +-
 .../commons/crypto/OpenSslInfoNative.java       |  41 ++++++
 .../apache/commons/crypto/OpenSslInfoNative.c   | 137 +++++++++++++++++++
 5 files changed, 196 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/eaed08d0/Makefile
----------------------------------------------------------------------
diff --git a/Makefile b/Makefile
index e579664..b6e8648 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@
 include Makefile.common
 
 COMMONS_CRYPTO_OUT:=$(TARGET)/$(commons-crypto)-$(os_arch)
-COMMONS_CRYPTO_OBJ:=$(addprefix $(COMMONS_CRYPTO_OUT)/,OpenSslCryptoRandomNative.o OpenSslNative.o)
+COMMONS_CRYPTO_OBJ:=$(addprefix $(COMMONS_CRYPTO_OUT)/,OpenSslCryptoRandomNative.o OpenSslNative.o OpenSslInfoNative.o)
 
 # Windows uses different path separators
 ifeq ($(OS_NAME),Windows)
@@ -43,6 +43,9 @@ $(TARGET)/jni-classes/org/apache/commons/crypto/cipher/OpenSslNative.h: $(TARGET
 $(TARGET)/jni-classes/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.h: $(TARGET)/classes/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.class
 	$(JAVAH) -force -classpath $(TARGET)/classes -o $@ org.apache.commons.crypto.random.OpenSslCryptoRandomNative
 
+$(TARGET)/jni-classes/org/apache/commons/crypto/OpenSslInfoNative.h: $(TARGET)/classes/org/apache/commons/crypto/OpenSslInfoNative.class
+	$(JAVAH) -force -classpath $(TARGET)/classes -o $@ org.apache.commons.crypto.OpenSslInfoNative
+
 $(COMMONS_CRYPTO_OUT)/OpenSslNative.o : $(SRC_NATIVE)/org/apache/commons/crypto/cipher/OpenSslNative.c $(TARGET)/jni-classes/org/apache/commons/crypto/cipher/OpenSslNative.h
 	@mkdir -p $(@D)
 	$(CC) $(CFLAGS) -c $< -o $@
@@ -51,6 +54,10 @@ $(COMMONS_CRYPTO_OUT)/OpenSslCryptoRandomNative.o : $(SRC_NATIVE)/org/apache/com
 	@mkdir -p $(@D)
 	$(CC) $(CFLAGS) -c $< -o $@
 
+$(COMMONS_CRYPTO_OUT)/OpenSslInfoNative.o : $(SRC_NATIVE)/org/apache/commons/crypto/OpenSslInfoNative.c $(TARGET)/jni-classes/org/apache/commons/crypto/OpenSslInfoNative.h
+	@mkdir -p $(@D)
+	$(CC) $(CFLAGS) -DVERSION='"$(VERSION)"' -DPROJECT_NAME='"$(PROJECT_NAME)"' -I"$(TARGET)/jni-classes/org/apache/commons/crypto" -c $< -o $@
+
 $(COMMONS_CRYPTO_OUT)/$(LIBNAME): $(COMMONS_CRYPTO_OBJ)
 	$(CXX) $(CXXFLAGS) -o $@ $+ $(LINKFLAGS)
 	$(STRIP) $@

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/eaed08d0/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index fc27e2c..45a2a3f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -480,6 +480,7 @@ The following provides more details on the included cryptographic software:
                          classpathref="maven.plugin.classpath"/>
                 <exec executable="make" failonerror="true" dir="${project.basedir}">
                   <env key="VERSION" value="${project.version}"/>
+                  <env key="PROJECT_NAME" value="${project.name}"/>
                   <!-- For debugging: -->
                   <!-- <arg value="-d"/> -->
                   <arg value="${target.name}"/>

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/eaed08d0/src/main/java/org/apache/commons/crypto/Crypto.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/Crypto.java b/src/main/java/org/apache/commons/crypto/Crypto.java
index 12e55c3..7c86ee8 100644
--- a/src/main/java/org/apache/commons/crypto/Crypto.java
+++ b/src/main/java/org/apache/commons/crypto/Crypto.java
@@ -119,20 +119,27 @@ public final class Crypto {
     public static void main(String args[]) throws Exception {
         System.out.println(getComponentName() + " " + getComponentVersion());
         if (isNativeCodeLoaded()) {
-            System.out.println("Native code loaded OK, version: TBA"); // TODO get VERSION from native code
+            System.out.println("Native code loaded OK " + OpenSslInfoNative.NativeVersion());
+            System.out.println("Native Name " + OpenSslInfoNative.NativeName());
+            System.out.println("Native Built " + OpenSslInfoNative.NativeTimeStamp());
+            System.out.println("OpenSSL library loaded OK, version: 0x" + Long.toHexString(OpenSslInfoNative.SSLeay()));
+            System.out.println(OpenSslInfoNative.SSLeayVersion(0));
             {
                 Properties props = new Properties();
                 props.setProperty(CryptoRandomFactory.CLASSES_KEY, CryptoRandomFactory.RandomProvider.OPENSSL.getClassName());
                 CryptoRandomFactory.getCryptoRandom(props);
                 System.out.println("Random instance created OK");
             }
-            System.out.println("OpenSSL library loaded OK, version: TBA"); // TODO get SSLeay() etc. from library
             {
                 Properties props = new Properties();
                 props.setProperty(CryptoCipherFactory.CLASSES_KEY, CryptoCipherFactory.CipherProvider.OPENSSL.getClassName());
                 CryptoCipherFactory.getCryptoCipher("AES/CTR/NoPadding", props);
                 System.out.println("Cipher instance created OK");
             }
+            System.out.println("Additional SSLeay_version(n) details:");
+            for(int j=1;j<6;j++) {
+                System.out.println(j+": "+ OpenSslInfoNative.SSLeayVersion(j));
+            }
         } else {
             System.out.println("Native load failed: " + getLoadingError());            
         }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/eaed08d0/src/main/java/org/apache/commons/crypto/OpenSslInfoNative.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/OpenSslInfoNative.java b/src/main/java/org/apache/commons/crypto/OpenSslInfoNative.java
new file mode 100644
index 0000000..3aa394f
--- /dev/null
+++ b/src/main/java/org/apache/commons/crypto/OpenSslInfoNative.java
@@ -0,0 +1,41 @@
+/**
+ * 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;
+
+/**
+ * JNI interface of {@link CryptoRandom} implementation for OpenSSL.
+ * The native method in this class is defined in 
+ * OpenSslCryptoRandomNative.h (generated at build time by javah)
+ * and implemented in the file
+ * src/main/native/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c
+ */
+class OpenSslInfoNative {
+
+    private OpenSslInfoNative() {
+    }
+
+    public static native String NativeVersion();
+
+    public static native String NativeName();
+
+    public static native String NativeTimeStamp();
+
+    public static native long SSLeay();
+
+    public static native String SSLeayVersion(int type);
+}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/eaed08d0/src/main/native/org/apache/commons/crypto/OpenSslInfoNative.c
----------------------------------------------------------------------
diff --git a/src/main/native/org/apache/commons/crypto/OpenSslInfoNative.c b/src/main/native/org/apache/commons/crypto/OpenSslInfoNative.c
new file mode 100644
index 0000000..85d1407
--- /dev/null
+++ b/src/main/native/org/apache/commons/crypto/OpenSslInfoNative.c
@@ -0,0 +1,137 @@
+/**
+ * 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.
+ */
+
+#include "org_apache_commons_crypto.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef UNIX
+#include <unistd.h>
+#include <sys/types.h>
+#endif
+
+#ifdef WINDOWS
+#include <windows.h>
+#endif
+
+// export the native interfaces
+#ifdef JNIEXPORT
+#undef JNIEXPORT
+#endif
+#define JNIEXPORT __attribute__((__visibility__("default")))
+#include "OpenSslInfoNative.h"
+
+#ifdef UNIX
+static unsigned long (*dlsym_SSLeay) (void);
+static char * (*dlsym_SSLeay_version) (int);
+static void *openssl;
+#endif
+
+#ifdef WINDOWS
+typedef unsigned long (__cdecl *__dlsym_SSLeay) (void);
+static __dlsym_SSLeay dlsym_SSLeay;
+typedef char * (__cdecl *__dlsym_SSLeay_version) (int);
+static __dlsym_SSLeay dlsym_SSLeay;
+static __dlsym_SSLeay_version dlsym_SSLeay_version;
+HMODULE openssl;
+#endif
+
+#ifdef UNIX
+static void get_methods(JNIEnv *env, void *openssl)
+#endif
+#ifdef WINDOWS
+static void get_methods(JNIEnv *env, HMODULE openssl)
+#endif
+{
+#ifdef UNIX
+  dlerror();  // Clear any existing error
+  LOAD_DYNAMIC_SYMBOL(dlsym_SSLeay, env, openssl, "SSLeay");
+  LOAD_DYNAMIC_SYMBOL(dlsym_SSLeay_version, env, openssl, "SSLeay_version");
+#endif
+
+#ifdef WINDOWS
+  LOAD_DYNAMIC_SYMBOL(__dlsym_SSLeay, dlsym_SSLeay, env, openssl, "SSLeay");
+  LOAD_DYNAMIC_SYMBOL(__dlsym_SSLeay_version, dlsym_SSLeay_version, env, openssl, "SSLeay_version");
+#endif
+}
+static int load_library(JNIEnv *env)
+{
+	char msg[100];
+#ifdef UNIX
+  openssl = dlopen(COMMONS_CRYPTO_OPENSSL_LIBRARY, RTLD_LAZY | RTLD_GLOBAL);
+#endif
+
+#ifdef WINDOWS
+  openssl = LoadLibrary(TEXT(COMMONS_CRYPTO_OPENSSL_LIBRARY));
+#endif
+
+  if (!openssl) {
+#ifdef UNIX
+    snprintf(msg, sizeof(msg), "Cannot load %s (%s)!", COMMONS_CRYPTO_OPENSSL_LIBRARY,  \
+        dlerror());
+#endif
+#ifdef WINDOWS
+    snprintf(msg, sizeof(msg), "Cannot load %s (%d)!", COMMONS_CRYPTO_OPENSSL_LIBRARY,  \
+    		GetLastError());
+#endif
+    THROW(env, "java/lang/UnsatisfiedLinkError", msg);
+    return 0;
+  }
+  get_methods(env, openssl);
+  return 1;
+}
+
+JNIEXPORT jstring JNICALL Java_org_apache_commons_crypto_OpenSslInfoNative_SSLeayVersion
+    (JNIEnv *env, jclass clazz, jint type)
+{
+	if (!load_library(env)) {
+		return NULL;
+	}
+
+	jstring answer = (*env)->NewStringUTF(env,dlsym_SSLeay_version(type));
+	return answer;
+}
+
+JNIEXPORT jlong JNICALL Java_org_apache_commons_crypto_OpenSslInfoNative_SSLeay
+    (JNIEnv *env, jobject object)
+{
+	if (!load_library(env)) {
+		return 0;
+	}
+	return dlsym_SSLeay();
+}
+
+JNIEXPORT jstring JNICALL Java_org_apache_commons_crypto_OpenSslInfoNative_NativeVersion
+    (JNIEnv *env, jobject object)
+{
+	return (*env)->NewStringUTF(env, VERSION);
+}
+
+JNIEXPORT jstring JNICALL Java_org_apache_commons_crypto_OpenSslInfoNative_NativeTimeStamp
+    (JNIEnv *env, jobject object)
+{
+	return (*env)->NewStringUTF(env, __DATE__);
+}
+
+JNIEXPORT jstring JNICALL Java_org_apache_commons_crypto_OpenSslInfoNative_NativeName
+    (JNIEnv *env, jobject object)
+{
+	return (*env)->NewStringUTF(env, PROJECT_NAME);
+}


[07/50] commons-crypto git commit: Use try-with-resources.

Posted by sd...@apache.org.
Use try-with-resources.

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/2a9b994f
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/2a9b994f
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/2a9b994f

Branch: refs/heads/CRYPTO-1.0.0
Commit: 2a9b994f77ad581595fdc9992482de5fdce448f1
Parents: 5119f84
Author: ggregory <gg...@apache.org>
Authored: Fri Jul 8 09:18:00 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Fri Jul 8 09:18:00 2016 -0700

----------------------------------------------------------------------
 .../crypto/random/AbstractRandomTest.java       | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/2a9b994f/src/test/java/org/apache/commons/crypto/random/AbstractRandomTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/random/AbstractRandomTest.java b/src/test/java/org/apache/commons/crypto/random/AbstractRandomTest.java
index 8193451..fe75490 100644
--- a/src/test/java/org/apache/commons/crypto/random/AbstractRandomTest.java
+++ b/src/test/java/org/apache/commons/crypto/random/AbstractRandomTest.java
@@ -32,16 +32,16 @@ public abstract class AbstractRandomTest {
 
     @Test(timeout = 120000)
     public void testRandomBytes() throws Exception {
-        CryptoRandom random = getCryptoRandom();
-        // len = 16
-        checkRandomBytes(random, 16);
-        // len = 32
-        checkRandomBytes(random, 32);
-        // len = 128
-        checkRandomBytes(random, 128);
-        // len = 256
-        checkRandomBytes(random, 256);
-        random.close();
+        try (CryptoRandom random = getCryptoRandom()) {
+            // len = 16
+            checkRandomBytes(random, 16);
+            // len = 32
+            checkRandomBytes(random, 32);
+            // len = 128
+            checkRandomBytes(random, 128);
+            // len = 256
+            checkRandomBytes(random, 256);
+        }
     }
 
     @Test(timeout = 120000)


[19/50] commons-crypto git commit: It works on MacOSX

Posted by sd...@apache.org.
It works on MacOSX

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/47061e66
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/47061e66
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/47061e66

Branch: refs/heads/CRYPTO-1.0.0
Commit: 47061e66d028cfb47ee95ad1081f40adadb490ec
Parents: c4db965
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 13:53:31 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 13:53:31 2016 +0100

----------------------------------------------------------------------
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/47061e66/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 6950f69..d6829fa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -39,7 +39,7 @@ Features
 2. Java stream API (CryptoInputStream/CryptoOutputStream) for high level stream encyrption/decryption.
 3. Both optimized with high performance AES encryption/decryption. (1400 MB/s - 1700 MB/s throughput in modern Xeon processors).
 4. JNI-based implementation to achieve comparable performance to the native C++ version based on OpenSsl.
-5. Portable across various operating systems (currently only Linux);
+5. Portable across various operating systems (currently only Linux/MacOSX);
    Apache Commons Crypto loads the library according to your machine environment (it checks system properties, `os.name` and `os.arch`).
 6. Simple usage. Add the commons-crypto-(version).jar file to your classpath.
 


[45/50] commons-crypto git commit: Windows works

Posted by sd...@apache.org.
Windows works

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/ffde3138
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/ffde3138
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/ffde3138

Branch: refs/heads/CRYPTO-1.0.0
Commit: ffde31380017545f5dacdfa04b29b232d6690735
Parents: a827107
Author: Sebb <se...@apache.org>
Authored: Wed Jul 13 18:58:34 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Wed Jul 13 18:58:34 2016 +0100

----------------------------------------------------------------------
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ffde3138/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 45a2a3f..6fe3f2b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -39,7 +39,7 @@ Features
 2. Java stream API (CryptoInputStream/CryptoOutputStream) for high level stream encyrption/decryption.
 3. Both optimized with high performance AES encryption/decryption. (1400 MB/s - 1700 MB/s throughput in modern Xeon processors).
 4. JNI-based implementation to achieve comparable performance to the native C++ version based on OpenSsl.
-5. Portable across various operating systems (currently only Linux/MacOSX);
+5. Portable across various operating systems (currently only Linux/MacOSX/Windows);
    Apache Commons Crypto loads the library according to your machine environment (it checks system properties, `os.name` and `os.arch`).
 6. Simple usage. Add the commons-crypto-(version).jar file to your classpath.
 


[36/50] commons-crypto git commit: CRYPTO-111 Include minimal main class to show that the code is working

Posted by sd...@apache.org.
CRYPTO-111 Include minimal main class to show that the code is working

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/403c632f
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/403c632f
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/403c632f

Branch: refs/heads/CRYPTO-1.0.0
Commit: 403c632fb9068ee72a1cc2d5be13f837a85f3b9c
Parents: 4ac4fed
Author: Sebb <se...@apache.org>
Authored: Sun Jul 10 13:39:33 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sun Jul 10 13:39:33 2016 +0100

----------------------------------------------------------------------
 pom.xml                                         | 12 ++++++++++
 .../java/org/apache/commons/crypto/Crypto.java  | 25 ++++++++++++++++++++
 2 files changed, 37 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/403c632f/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index d6829fa..fc27e2c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -440,6 +440,18 @@ The following provides more details on the included cryptographic software:
     </pluginManagement>
     <plugins>
       <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <configuration>
+          <archive>
+            <manifestEntries>
+              <!-- Helper application -->
+              <Main-Class>org.apache.commons.crypto.Crypto</Main-Class>
+            </manifestEntries>
+          </archive>
+        </configuration>
+      </plugin>
+      <plugin>
         <artifactId>maven-resources-plugin</artifactId>
         <version>2.7</version>
         <executions>

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/403c632f/src/main/java/org/apache/commons/crypto/Crypto.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/Crypto.java b/src/main/java/org/apache/commons/crypto/Crypto.java
index d913878..47575d4 100644
--- a/src/main/java/org/apache/commons/crypto/Crypto.java
+++ b/src/main/java/org/apache/commons/crypto/Crypto.java
@@ -20,8 +20,12 @@ package org.apache.commons.crypto;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.security.GeneralSecurityException;
 import java.util.Properties;
 
+import org.apache.commons.crypto.cipher.CryptoCipherFactory;
+import org.apache.commons.crypto.random.CryptoRandomFactory;
+
 /**
  * Provides diagnostic information about Commons Crypto and keys for native class loading
  */
@@ -113,4 +117,25 @@ public final class Crypto {
         return ComponentPropertiesHolder.PROPERTIES.getProperty("NAME");
     }
 
+    public static void main(String args[]) throws Exception {
+        System.out.println(getComponentName() + " " + getComponentVersion());
+        if (isNativeCodeLoaded()) {
+            System.out.println("Native code loaded OK, version: TBA"); // TODO get VERSION from native code
+            {
+                Properties props = new Properties();
+                props.setProperty(CryptoRandomFactory.CLASSES_KEY, CryptoRandomFactory.RandomProvider.OPENSSL.getClassName());
+                CryptoRandomFactory.getCryptoRandom(props);
+                System.out.println("Random instance created OK");
+            }
+            System.out.println("OpenSSL library loaded OK, version: TBA"); // TODO get SSLeay() etc. from library
+            {
+                Properties props = new Properties();
+                props.setProperty(CryptoCipherFactory.CLASSES_KEY, CryptoCipherFactory.CipherProvider.OPENSSL.getClassName());
+                CryptoCipherFactory.getCryptoCipher("AES/CTR/NoPadding", props);
+                System.out.println("Cipher instance created OK");
+            }
+        } else {
+            System.out.println("Native load failed: " + getLoadingError());            
+        }
+    }
 }


[05/50] commons-crypto git commit: Unused import: org.apache.commons.crypto.Crypto.

Posted by sd...@apache.org.
Unused import: org.apache.commons.crypto.Crypto.

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/a3128504
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/a3128504
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/a3128504

Branch: refs/heads/CRYPTO-1.0.0
Commit: a3128504c5a1ac1194994265db397d3858fa26c9
Parents: 72dd5bf
Author: ggregory <gg...@apache.org>
Authored: Fri Jul 8 09:15:54 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Fri Jul 8 09:15:54 2016 -0700

----------------------------------------------------------------------
 .../org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java   | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/a3128504/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java b/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java
index d53d3bf..f47e7e0 100644
--- a/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java
+++ b/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java
@@ -20,7 +20,6 @@ package org.apache.commons.crypto.cipher;
 import java.security.GeneralSecurityException;
 import java.util.Properties;
 
-import org.apache.commons.crypto.Crypto;
 import org.junit.Assert;
 import org.junit.Test;
 


[27/50] commons-crypto git commit: No need to save the libary pointer once initialised

Posted by sd...@apache.org.
No need to save the libary pointer once initialised

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/56894ba1
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/56894ba1
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/56894ba1

Branch: refs/heads/CRYPTO-1.0.0
Commit: 56894ba1f6770f8fd1791ecab5b8804b764cb194
Parents: b17af9d
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 18:07:20 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 18:07:20 2016 +0100

----------------------------------------------------------------------
 .../apache/commons/crypto/cipher/OpenSslNative.c    | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/56894ba1/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c
----------------------------------------------------------------------
diff --git a/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c b/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c
index fd35f61..5d90c06 100644
--- a/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c
+++ b/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c
@@ -46,7 +46,6 @@ static EVP_CIPHER * (*dlsym_EVP_aes_128_ctr)(void);
 static EVP_CIPHER * (*dlsym_EVP_aes_256_cbc)(void);
 static EVP_CIPHER * (*dlsym_EVP_aes_192_cbc)(void);
 static EVP_CIPHER * (*dlsym_EVP_aes_128_cbc)(void);
-static void *openssl;
 #endif
 
 #ifdef WINDOWS
@@ -82,10 +81,15 @@ static __dlsym_EVP_aes_128_ctr dlsym_EVP_aes_128_ctr;
 static __dlsym_EVP_aes_256_cbc dlsym_EVP_aes_256_cbc;
 static __dlsym_EVP_aes_192_cbc dlsym_EVP_aes_192_cbc;
 static __dlsym_EVP_aes_128_cbc dlsym_EVP_aes_128_cbc;
-static HMODULE openssl;
 #endif
 
-static void loadAes(JNIEnv *env)
+#ifdef UNIX
+static void loadAes(JNIEnv *env, void *openssl)
+#endif
+
+#ifdef WINDOWS
+static void loadAes(JNIEnv *env, HMODULE openssl)
+#endif
 {
 #ifdef UNIX
   LOAD_DYNAMIC_SYMBOL(dlsym_EVP_aes_256_ctr, env, openssl, "EVP_aes_256_ctr");
@@ -117,11 +121,11 @@ JNIEXPORT void JNICALL Java_org_apache_commons_crypto_cipher_OpenSslNative_initI
 {
   char msg[1000];
 #ifdef UNIX
-  openssl = dlopen(COMMONS_CRYPTO_OPENSSL_LIBRARY, RTLD_LAZY | RTLD_GLOBAL);
+  void *openssl = dlopen(COMMONS_CRYPTO_OPENSSL_LIBRARY, RTLD_LAZY | RTLD_GLOBAL);
 #endif
 
 #ifdef WINDOWS
-  openssl = LoadLibrary(COMMONS_CRYPTO_OPENSSL_LIBRARY);
+  HMODULE openssl = LoadLibrary(COMMONS_CRYPTO_OPENSSL_LIBRARY);
 #endif
 
   if (!openssl) {
@@ -172,7 +176,7 @@ JNIEXPORT void JNICALL Java_org_apache_commons_crypto_cipher_OpenSslNative_initI
                       env, openssl, "EVP_CipherFinal_ex");
 #endif
 
-  loadAes(env);
+  loadAes(env, openssl);
   jthrowable jthr = (*env)->ExceptionOccurred(env);
   if (jthr) {
     (*env)->DeleteLocalRef(env, jthr);


[04/50] commons-crypto git commit: The declared exception GeneralSecurityException is not actually thrown by the method testDummmyRandom() from type CryptoRandomFactoryTest.

Posted by sd...@apache.org.
The declared exception GeneralSecurityException is not actually thrown
by the method testDummmyRandom() from type CryptoRandomFactoryTest.

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/72dd5bf1
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/72dd5bf1
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/72dd5bf1

Branch: refs/heads/CRYPTO-1.0.0
Commit: 72dd5bf13f1e577fcafcf22a1db8a20b9a2b237f
Parents: 8773c32
Author: ggregory <gg...@apache.org>
Authored: Fri Jul 8 09:15:18 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Fri Jul 8 09:15:18 2016 -0700

----------------------------------------------------------------------
 .../org/apache/commons/crypto/random/CryptoRandomFactoryTest.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/72dd5bf1/src/test/java/org/apache/commons/crypto/random/CryptoRandomFactoryTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/random/CryptoRandomFactoryTest.java b/src/test/java/org/apache/commons/crypto/random/CryptoRandomFactoryTest.java
index 2f78347..2901404 100644
--- a/src/test/java/org/apache/commons/crypto/random/CryptoRandomFactoryTest.java
+++ b/src/test/java/org/apache/commons/crypto/random/CryptoRandomFactoryTest.java
@@ -101,7 +101,7 @@ public class CryptoRandomFactoryTest {
     }
 
     @Test
-    public void testDummmyRandom() throws GeneralSecurityException {
+    public void testDummmyRandom() {
         Properties props = new Properties();
         props.setProperty(CryptoRandomFactory.CLASSES_KEY, DummyRandom.class.getName());
         try {


[16/50] commons-crypto git commit: CRYPTO-103 NativeCodeLoader.getVersion() is not needed

Posted by sd...@apache.org.
CRYPTO-103 NativeCodeLoader.getVersion() is not needed

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/fd2b9347
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/fd2b9347
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/fd2b9347

Branch: refs/heads/CRYPTO-1.0.0
Commit: fd2b93472cc8438c17874635e674d1cf1a84864e
Parents: 211498e
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 13:20:42 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 13:20:42 2016 +0100

----------------------------------------------------------------------
 .../java/org/apache/commons/crypto/Crypto.java  |  9 ------
 .../apache/commons/crypto/NativeCodeLoader.java | 29 ++------------------
 .../commons/crypto/NativeCodeLoaderTest.java    |  6 ----
 3 files changed, 2 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/fd2b9347/src/main/java/org/apache/commons/crypto/Crypto.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/Crypto.java b/src/main/java/org/apache/commons/crypto/Crypto.java
index 85e2186..e7aa101 100644
--- a/src/main/java/org/apache/commons/crypto/Crypto.java
+++ b/src/main/java/org/apache/commons/crypto/Crypto.java
@@ -46,15 +46,6 @@ public final class Crypto {
             + "lib.tempdir";
 
     /**
-     * Gets the currently active version of Apache Commons Crypto.
-     * 
-     * @return the version
-     */
-    public static String getVersion() {
-        return NativeCodeLoader.getVersion();
-    }
-
-    /**
      * Checks whether the native code has been successfully loaded for the platform.
      * 
      * @return true if the native code has been loaded successfully.

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/fd2b9347/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java b/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
index 4d4dbcb..4b5a765 100644
--- a/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
+++ b/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
@@ -149,8 +149,8 @@ final class NativeCodeLoader {
         // loaders
         // can read the libcommons-crypto multiple times.
         String uuid = UUID.randomUUID().toString();
-        String extractedLibFileName = String.format("commons-crypto-%s-%s-%s",
-                getVersion(), uuid, libraryFileName);
+        String extractedLibFileName = String.format("commons-crypto-%s-%s",
+                uuid, libraryFileName);
         File extractedLibFile = new File(targetFolder, extractedLibFileName);
 
         InputStream reader = null;
@@ -215,31 +215,6 @@ final class NativeCodeLoader {
     }
 
     /**
-     * Gets the version by reading pom.properties embedded in jar. This version
-     * data is used as a suffix of a dll file extracted from the jar.
-     *
-     * @return the version string
-     */
-    static String getVersion() {
-        URL versionFile = NativeCodeLoader.class
-                .getResource("/META-INF/maven/org.apache.commons.crypto/commons-crypto/pom.properties");
-        String version = "unknown";
-        if (versionFile != null) {
-            Properties versionData = new Properties();
-            try {
-                versionData.load(versionFile.openStream());
-                version = versionData.getProperty("version", version);
-                if (version.equals("unknown")) {
-                    version = versionData.getProperty("VERSION", version);
-                }
-                version = version.trim().replaceAll("[^0-9M\\.]", "");
-            } catch (IOException e) { // NOPMD
-            }
-        }
-        return version;
-    }
-
-    /**
      * Checks whether in1 and in2 is equal.
      *
      * @param in1 the input1.

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/fd2b9347/src/test/java/org/apache/commons/crypto/NativeCodeLoaderTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/NativeCodeLoaderTest.java b/src/test/java/org/apache/commons/crypto/NativeCodeLoaderTest.java
index ff871de..02b60de 100644
--- a/src/test/java/org/apache/commons/crypto/NativeCodeLoaderTest.java
+++ b/src/test/java/org/apache/commons/crypto/NativeCodeLoaderTest.java
@@ -39,12 +39,6 @@ public class NativeCodeLoaderTest {
             System.out.println("** WARN: Native (JNI) code was not loaded: " 
                 + NativeCodeLoader.getLoadingError());
         }
-        assertNotNull(NativeCodeLoader.getVersion());
-    }
-
-    @Test
-    public void testGetVersion() {
-        assertNotNull(NativeCodeLoader.getVersion());
     }
 
     @Test


[09/50] commons-crypto git commit: Use try-with-resources.

Posted by sd...@apache.org.
Use try-with-resources.

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/6f6d6b0c
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/6f6d6b0c
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/6f6d6b0c

Branch: refs/heads/CRYPTO-1.0.0
Commit: 6f6d6b0c9c6cf3d9c991c7e50a5671210b4a74e3
Parents: 9e83ff3
Author: ggregory <gg...@apache.org>
Authored: Fri Jul 8 09:19:01 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Fri Jul 8 09:19:01 2016 -0700

----------------------------------------------------------------------
 .../crypto/random/AbstractRandomTest.java       | 38 ++++++++++----------
 1 file changed, 19 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/6f6d6b0c/src/test/java/org/apache/commons/crypto/random/AbstractRandomTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/random/AbstractRandomTest.java b/src/test/java/org/apache/commons/crypto/random/AbstractRandomTest.java
index 1d49bc4..619c1a3 100644
--- a/src/test/java/org/apache/commons/crypto/random/AbstractRandomTest.java
+++ b/src/test/java/org/apache/commons/crypto/random/AbstractRandomTest.java
@@ -47,29 +47,29 @@ public abstract class AbstractRandomTest {
     @Test(timeout = 120000)
     public void testRandomBytesMultiThreaded() throws Exception {
         final int threadCount = 100;
-        final CryptoRandom random = getCryptoRandom();
-        final List<Thread> threads = new ArrayList<>(threadCount);
+        try (final CryptoRandom random = getCryptoRandom()) {
+            final List<Thread> threads = new ArrayList<>(threadCount);
 
-        for (int i = 0; i < threadCount; i++) {
-            Thread t = new Thread(new Runnable() {
-                @Override
-                public void run() {
-                    checkRandomBytes(random, 10);
-                    checkRandomBytes(random, 1000);
-                    checkRandomBytes(random, 100000);
-                }
-            });
-            t.start();
-            threads.add(t);
-        }
+            for (int i = 0; i < threadCount; i++) {
+                Thread t = new Thread(new Runnable() {
+                    @Override
+                    public void run() {
+                        checkRandomBytes(random, 10);
+                        checkRandomBytes(random, 1000);
+                        checkRandomBytes(random, 100000);
+                    }
+                });
+                t.start();
+                threads.add(t);
+            }
 
-        for (Thread t : threads) {
-            if (!t.getState().equals(State.NEW)) {
-                t.join();
+            for (Thread t : threads) {
+                if (!t.getState().equals(State.NEW)) {
+                    t.join();
+                }
             }
-        }
 
-        random.close();
+        }
     }
 
     /**


[43/50] commons-crypto git commit: Docn

Posted by sd...@apache.org.
Docn

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/0c07adb0
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/0c07adb0
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/0c07adb0

Branch: refs/heads/CRYPTO-1.0.0
Commit: 0c07adb081283a86376329cb531419e989b8b016
Parents: 5e5cf6d
Author: Sebb <se...@apache.org>
Authored: Wed Jul 13 10:22:22 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Wed Jul 13 10:22:22 2016 +0100

----------------------------------------------------------------------
 src/changes/changes.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/0c07adb0/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 5ded7b0..aab782b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -61,7 +61,7 @@
    -->
 
   <body>
-    <release version="1.0.0" date="2016-06-06" description="Feature and bug fix release">
+    <release version="1.0.0" date="2016-07-??" description="Initial release">
       <action issue="CRYPTO-68" type="add" dev="britter" >Enable common code quality reports.</action>
       <action issue="CRYPTO-65" type="fix" dev="britter" due-to="sebb">Warnings compiling on MacOSX - JNIEXPORT redefined.</action>
       <action issue="CRYPTO-11" type="add" dev="Ke Jia" due-to="Ke Jia, Jerry Chen">User guide documentation .</action>


[32/50] commons-crypto git commit: Fix file name

Posted by sd...@apache.org.
Fix file name

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/64ad87d0
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/64ad87d0
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/64ad87d0

Branch: refs/heads/CRYPTO-1.0.0
Commit: 64ad87d016e8fe28bf8a4c51c3d26272e343ce02
Parents: fab4456
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 23:50:24 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 23:50:24 2016 +0100

----------------------------------------------------------------------
 .../crypto/random/OpenSslCryptoRandomTest.java  | 45 ++++++++++++++++++++
 .../crypto/random/OpensslCryptoRandomTest.java  | 45 --------------------
 2 files changed, 45 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/64ad87d0/src/test/java/org/apache/commons/crypto/random/OpenSslCryptoRandomTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/random/OpenSslCryptoRandomTest.java b/src/test/java/org/apache/commons/crypto/random/OpenSslCryptoRandomTest.java
new file mode 100644
index 0000000..4784b18
--- /dev/null
+++ b/src/test/java/org/apache/commons/crypto/random/OpenSslCryptoRandomTest.java
@@ -0,0 +1,45 @@
+/**
+ * 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.random;
+
+import java.security.GeneralSecurityException;
+import java.util.Properties;
+
+import org.apache.commons.crypto.Crypto;
+import org.junit.Assume;
+
+import static org.junit.Assert.fail;
+
+public class OpensslCryptoRandomTest extends AbstractRandomTest {
+
+    @Override
+    public CryptoRandom getCryptoRandom() throws GeneralSecurityException {
+        Assume.assumeTrue(Crypto.isNativeCodeLoaded());
+        Properties props = new Properties();
+        props.setProperty(
+                CryptoRandomFactory.CLASSES_KEY,
+                OpenSslCryptoRandom.class.getName());
+        CryptoRandom random = CryptoRandomFactory.getCryptoRandom(props);
+        if (!(random instanceof OpenSslCryptoRandom)) {
+            fail("The CryptoRandom should be: "
+                    + OpenSslCryptoRandom.class.getName());
+        }
+        return random;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/64ad87d0/src/test/java/org/apache/commons/crypto/random/OpensslCryptoRandomTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/random/OpensslCryptoRandomTest.java b/src/test/java/org/apache/commons/crypto/random/OpensslCryptoRandomTest.java
deleted file mode 100644
index 4784b18..0000000
--- a/src/test/java/org/apache/commons/crypto/random/OpensslCryptoRandomTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * 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.random;
-
-import java.security.GeneralSecurityException;
-import java.util.Properties;
-
-import org.apache.commons.crypto.Crypto;
-import org.junit.Assume;
-
-import static org.junit.Assert.fail;
-
-public class OpensslCryptoRandomTest extends AbstractRandomTest {
-
-    @Override
-    public CryptoRandom getCryptoRandom() throws GeneralSecurityException {
-        Assume.assumeTrue(Crypto.isNativeCodeLoaded());
-        Properties props = new Properties();
-        props.setProperty(
-                CryptoRandomFactory.CLASSES_KEY,
-                OpenSslCryptoRandom.class.getName());
-        CryptoRandom random = CryptoRandomFactory.getCryptoRandom(props);
-        if (!(random instanceof OpenSslCryptoRandom)) {
-            fail("The CryptoRandom should be: "
-                    + OpenSslCryptoRandom.class.getName());
-        }
-        return random;
-    }
-
-}


[34/50] commons-crypto git commit: CRYPTO-113 Improve error reporting by factories

Posted by sd...@apache.org.
CRYPTO-113 Improve error reporting by factories

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/79502d45
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/79502d45
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/79502d45

Branch: refs/heads/CRYPTO-1.0.0
Commit: 79502d4544d42c020520d7f6cdb69ff9c1631554
Parents: bc7c116
Author: Sebb <se...@apache.org>
Authored: Sun Jul 10 00:47:59 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sun Jul 10 00:47:59 2016 +0100

----------------------------------------------------------------------
 .../crypto/cipher/CryptoCipherFactory.java      |  4 +-
 .../crypto/random/CryptoRandomFactory.java      |  6 ++-
 .../crypto/random/CryptoRandomFactoryTest.java  | 18 +++++++++
 .../commons/crypto/random/FailingRandom.java    | 39 ++++++++++++++++++++
 .../crypto/random/OsCryptoRandomTest.java       | 27 ++++++++++++++
 5 files changed, 92 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/79502d45/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java b/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
index 7f63376..c34753a 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
@@ -148,6 +148,7 @@ public class CryptoCipherFactory {
             throw new IllegalArgumentException("No classname(s) provided");            
         }
         CryptoCipher cipher = null;
+        Exception lastException = null;
 
         StringBuilder errorMessage = new StringBuilder("CryptoCipher ");
         for (String klass : names) {
@@ -159,6 +160,7 @@ public class CryptoCipherFactory {
                     break;
                 }
             } catch (Exception e) {
+                lastException = e;
                 errorMessage.append("{" + klass + "}");
             }
         }
@@ -168,7 +170,7 @@ public class CryptoCipherFactory {
         }
         errorMessage.append(" is not available or transformation " +
                 transformation + " is not supported.");
-        throw new GeneralSecurityException(errorMessage.toString());
+        throw new GeneralSecurityException(errorMessage.toString(), lastException);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/79502d45/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java b/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
index aa046ec..853a079 100644
--- a/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
+++ b/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
@@ -188,6 +188,7 @@ public class CryptoRandomFactory {
         }
         StringBuilder errorMessage = new StringBuilder();
         CryptoRandom random = null;
+        Exception lastException = null;
         for (String klassName : names) {
             try {
                 final Class<?> klass = ReflectionUtils.getClassByName(klassName);
@@ -196,10 +197,13 @@ public class CryptoRandomFactory {
                     break;
                 }
             } catch (ClassCastException e) {
+                lastException = e;
                 errorMessage.append("Class: [" + klassName + "] is not a CryptoRandom.");
             } catch (ClassNotFoundException e) {
+                lastException = e;
                 errorMessage.append("CryptoRandom: [" + klassName + "] not found.");
             } catch (Exception e) {
+                lastException = e;
                 errorMessage.append("CryptoRandom: [" + klassName + "] failed with " + e.getMessage());
             }
         }
@@ -207,7 +211,7 @@ public class CryptoRandomFactory {
         if (random != null) {
             return random;
         }
-        throw new GeneralSecurityException(errorMessage.toString());
+        throw new GeneralSecurityException(errorMessage.toString(), lastException);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/79502d45/src/test/java/org/apache/commons/crypto/random/CryptoRandomFactoryTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/random/CryptoRandomFactoryTest.java b/src/test/java/org/apache/commons/crypto/random/CryptoRandomFactoryTest.java
index 2901404..f4f1397 100644
--- a/src/test/java/org/apache/commons/crypto/random/CryptoRandomFactoryTest.java
+++ b/src/test/java/org/apache/commons/crypto/random/CryptoRandomFactoryTest.java
@@ -17,6 +17,7 @@
  */
 package org.apache.commons.crypto.random;
 
+import java.lang.reflect.InvocationTargetException;
 import java.security.GeneralSecurityException;
 import java.util.Properties;
 
@@ -122,4 +123,21 @@ public class CryptoRandomFactoryTest {
         CryptoRandomFactory.getCryptoRandom(props);
     }
 
+    @Test
+    public void testFailingRandom() {
+        Properties props = new Properties();
+        props.setProperty(CryptoRandomFactory.CLASSES_KEY, FailingRandom.class.getName());
+        try {
+            CryptoRandomFactory.getCryptoRandom(props);
+            Assert.fail("Expected GeneralSecurityException");
+        } catch (GeneralSecurityException e) {
+            Throwable cause = e.getCause();
+            Assert.assertEquals(RuntimeException.class, cause.getClass());
+            cause = cause.getCause();
+            Assert.assertEquals(InvocationTargetException.class, cause.getClass());
+            cause = cause.getCause();
+            Assert.assertEquals(UnsatisfiedLinkError.class, cause.getClass());
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/79502d45/src/test/java/org/apache/commons/crypto/random/FailingRandom.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/random/FailingRandom.java b/src/test/java/org/apache/commons/crypto/random/FailingRandom.java
new file mode 100644
index 0000000..ce19126
--- /dev/null
+++ b/src/test/java/org/apache/commons/crypto/random/FailingRandom.java
@@ -0,0 +1,39 @@
+/*
+ * 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.random;
+
+import java.io.IOException;
+import java.util.Properties;
+
+class FailingRandom implements CryptoRandom {
+
+    // Should fail with NoSuchMethodException
+    FailingRandom(Properties props) {
+        NoSuchMethod();
+    }
+
+    @Override
+    public void close() throws IOException {
+    }
+
+    @Override
+    public void nextBytes(byte[] bytes) {
+    }
+
+    public static native void NoSuchMethod();
+}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/79502d45/src/test/java/org/apache/commons/crypto/random/OsCryptoRandomTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/random/OsCryptoRandomTest.java b/src/test/java/org/apache/commons/crypto/random/OsCryptoRandomTest.java
index 69f6d6a..6382771 100644
--- a/src/test/java/org/apache/commons/crypto/random/OsCryptoRandomTest.java
+++ b/src/test/java/org/apache/commons/crypto/random/OsCryptoRandomTest.java
@@ -19,10 +19,15 @@ package org.apache.commons.crypto.random;
 
 import static org.junit.Assert.fail;
 
+import java.io.FileNotFoundException;
+import java.lang.reflect.InvocationTargetException;
 import java.security.GeneralSecurityException;
 import java.util.Properties;
 
 import org.junit.Assume;
+import org.junit.Test;
+
+import junit.framework.Assert;
 
 public class OsCryptoRandomTest extends AbstractRandomTest {
 
@@ -41,4 +46,26 @@ public class OsCryptoRandomTest extends AbstractRandomTest {
         }
         return random;
     }
+
+    @Test
+    public void testInvalidRansom() {
+        Properties props = new Properties();
+        props.setProperty(CryptoRandomFactory.CLASSES_KEY, OsCryptoRandom.class.getName());
+        // Invalid device
+        props.setProperty(CryptoRandomFactory.DEVICE_FILE_PATH_KEY, "");
+        try {
+            CryptoRandomFactory.getCryptoRandom(props);
+            fail("Expected GeneralSecurityException");
+        } catch (GeneralSecurityException e) {
+            Throwable cause;
+            cause = e.getCause();
+            Assert.assertEquals(RuntimeException.class, cause.getClass());
+            cause = cause.getCause();
+            Assert.assertEquals(InvocationTargetException.class, cause.getClass());
+            cause = cause.getCause();
+            Assert.assertEquals(RuntimeException.class, cause.getClass());
+            cause = cause.getCause();
+            Assert.assertEquals(FileNotFoundException.class, cause.getClass());
+        }
+    }
 }


[17/50] commons-crypto git commit: Unused import

Posted by sd...@apache.org.
Unused import

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/d58e6f35
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/d58e6f35
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/d58e6f35

Branch: refs/heads/CRYPTO-1.0.0
Commit: d58e6f35fb77c7b5a88166b03ab82c3bba52e234
Parents: fd2b934
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 13:24:05 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 13:24:05 2016 +0100

----------------------------------------------------------------------
 src/main/java/org/apache/commons/crypto/NativeCodeLoader.java | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/d58e6f35/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java b/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
index 4b5a765..c765340 100644
--- a/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
+++ b/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
@@ -23,7 +23,6 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.URL;
 import java.util.Properties;
 import java.util.UUID;
 


[13/50] commons-crypto git commit: Classpath does not need jni-classes

Posted by sd...@apache.org.
Classpath does not need jni-classes

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/c27ed6e1
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/c27ed6e1
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/c27ed6e1

Branch: refs/heads/CRYPTO-1.0.0
Commit: c27ed6e152a260684cba48cb7d7c20ee4c3251cc
Parents: 495b053
Author: Sebb <se...@apache.org>
Authored: Fri Jul 8 17:55:21 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Fri Jul 8 17:55:21 2016 +0100

----------------------------------------------------------------------
 Makefile | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/c27ed6e1/Makefile
----------------------------------------------------------------------
diff --git a/Makefile b/Makefile
index 728f89d..2d35d29 100644
--- a/Makefile
+++ b/Makefile
@@ -22,13 +22,10 @@ COMMONS_CRYPTO_OBJ:=$(addprefix $(COMMONS_CRYPTO_OUT)/,OpensslCryptoRandom.o Ope
 
 # Windows uses different path separators
 ifeq ($(OS_NAME),Windows)
-  # Classpath separator
-  SEP := ;
   DELTREE := CMD /C DEL /S/Q
   # The separator used for file paths
   FSEP := \\
 else
-  SEP := :
   DELTREE := rm -rf
   FSEP := /
 endif
@@ -41,10 +38,10 @@ NATIVE_DLL:=$(NATIVE_TARGET_DIR)/$(LIBNAME)
 all: $(NATIVE_DLL)
 
 $(TARGET)/jni-classes/org/apache/commons/crypto/cipher/OpenSslNative.h: $(TARGET)/classes/org/apache/commons/crypto/cipher/OpenSslNative.class
-	$(JAVAH) -force -classpath $(TARGET)/jni-classes$(SEP)$(TARGET)/classes -o $@ org.apache.commons.crypto.cipher.OpenSslNative
+	$(JAVAH) -force -classpath $(TARGET)/classes -o $@ org.apache.commons.crypto.cipher.OpenSslNative
 
 $(TARGET)/jni-classes/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.h: $(TARGET)/classes/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.class
-	$(JAVAH) -force -classpath $(TARGET)/jni-classes$(SEP)$(TARGET)/classes -o $@ org.apache.commons.crypto.random.OpenSslCryptoRandomNative
+	$(JAVAH) -force -classpath $(TARGET)/classes -o $@ org.apache.commons.crypto.random.OpenSslCryptoRandomNative
 
 $(COMMONS_CRYPTO_OUT)/OpenSslNative.o : $(SRC_NATIVE)/org/apache/commons/crypto/cipher/OpenSslNative.c $(TARGET)/jni-classes/org/apache/commons/crypto/cipher/OpenSslNative.h
 	@mkdir -p $(@D)


[20/50] commons-crypto git commit: Already included near top of file

Posted by sd...@apache.org.
Already included near top of file

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/999c0dee
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/999c0dee
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/999c0dee

Branch: refs/heads/CRYPTO-1.0.0
Commit: 999c0deeeb6ee34d69aed7431b5277af64c86676
Parents: 47061e6
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 14:45:11 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 14:45:11 2016 +0100

----------------------------------------------------------------------
 .../native/org/apache/commons/crypto/org_apache_commons_crypto.h    | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/999c0dee/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
----------------------------------------------------------------------
diff --git a/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h b/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
index 71ea6fd..d0e58a5 100644
--- a/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
+++ b/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
@@ -189,7 +189,6 @@ static FARPROC WINAPI do_dlsym(JNIEnv *env, HMODULE handle, LPCSTR symbol) {
 } while ((ret == -1) && (errno == EINTR));
 
 #ifdef UNIX
-#include <dlfcn.h>
 #include "config.h"
 #endif
 


[12/50] commons-crypto git commit: Use try-with-resources.

Posted by sd...@apache.org.
Use try-with-resources.

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/495b0533
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/495b0533
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/495b0533

Branch: refs/heads/CRYPTO-1.0.0
Commit: 495b0533a3bc8d14bc9742aaa7f3d769c4a4efe2
Parents: d3a7742
Author: ggregory <gg...@apache.org>
Authored: Fri Jul 8 09:24:39 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Fri Jul 8 09:24:39 2016 -0700

----------------------------------------------------------------------
 .../stream/PositionedCryptoInputStreamTest.java | 130 +++++++++----------
 1 file changed, 63 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/495b0533/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java b/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java
index f796c0c..0d6ce16 100644
--- a/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java
+++ b/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java
@@ -113,35 +113,34 @@ public class PositionedCryptoInputStreamTest {
     // when there are multiple positioned read actions and one read action,
     // they will not interfere each other.
     private void doMultipleReadTest(String cipherClass) throws Exception {
-        PositionedCryptoInputStream in = getCryptoInputStream(
-                getCipher(cipherClass), bufferSize);
-        int position = 0;
-        while (in.available() > 0) {
-            ByteBuffer buf = ByteBuffer.allocate(length);
-            byte[] bytes1 = new byte[length];
-            byte[] bytes2 = new byte[lengthLess];
-            // do the read and position read
-            int pn1 = in.read(position, bytes1, 0, length);
-            int n = in.read(buf);
-            int pn2 = in.read(position, bytes2, 0, lengthLess);
-
-            // verify the result
-            if (pn1 > 0) {
-                compareByteArray(testData, position, bytes1, pn1);
-            }
-
-            if (pn2 > 0) {
-                compareByteArray(testData, position, bytes2, pn2);
-            }
-
-            if (n > 0) {
-                compareByteArray(testData, position, buf.array(), n);
-                position += n;
-            } else {
-                break;
+        try (PositionedCryptoInputStream in = getCryptoInputStream(getCipher(cipherClass), bufferSize)) {
+            int position = 0;
+            while (in.available() > 0) {
+                ByteBuffer buf = ByteBuffer.allocate(length);
+                byte[] bytes1 = new byte[length];
+                byte[] bytes2 = new byte[lengthLess];
+                // do the read and position read
+                int pn1 = in.read(position, bytes1, 0, length);
+                int n = in.read(buf);
+                int pn2 = in.read(position, bytes2, 0, lengthLess);
+
+                // verify the result
+                if (pn1 > 0) {
+                    compareByteArray(testData, position, bytes1, pn1);
+                }
+
+                if (pn2 > 0) {
+                    compareByteArray(testData, position, bytes2, pn2);
+                }
+
+                if (n > 0) {
+                    compareByteArray(testData, position, buf.array(), n);
+                    position += n;
+                } else {
+                    break;
+                }
             }
         }
-        in.close();
     }
 
     private void doPositionedReadTests(String cipherClass) throws Exception {
@@ -190,20 +189,19 @@ public class PositionedCryptoInputStreamTest {
 
     private void testSeekLoop(String cipherClass, int position, int length,
             int bufferSize) throws Exception {
-        PositionedCryptoInputStream in = getCryptoInputStream(
-                getCipher(cipherClass), bufferSize);
-        while (in.available() > 0) {
-            in.seek(position);
-            ByteBuffer buf = ByteBuffer.allocate(length);
-            int n = in.read(buf);
-            if (n > 0) {
-                compareByteArray(testData, position, buf.array(), n);
-                position += n;
-            } else {
-                break;
+        try (PositionedCryptoInputStream in = getCryptoInputStream(getCipher(cipherClass), bufferSize)) {
+            while (in.available() > 0) {
+                in.seek(position);
+                ByteBuffer buf = ByteBuffer.allocate(length);
+                int n = in.read(buf);
+                if (n > 0) {
+                    compareByteArray(testData, position, buf.array(), n);
+                    position += n;
+                } else {
+                    break;
+                }
             }
         }
-        in.close();
     }
 
     // test for the out of index position, eg, -1.
@@ -221,47 +219,45 @@ public class PositionedCryptoInputStreamTest {
 
     private void testPositionedReadLoop(String cipherClass, int position,
             int length, int bufferSize, int total) throws Exception {
-        PositionedCryptoInputStream in = getCryptoInputStream(
-                getCipher(cipherClass), bufferSize);
-        // do the position read until the end of data
-        while (position < total) {
-            byte[] bytes = new byte[length];
-            int n = in.read(position, bytes, 0, length);
-            if (n >= 0) {
-                compareByteArray(testData, position, bytes, n);
-                position += n;
-            } else {
-                break;
+        try (PositionedCryptoInputStream in = getCryptoInputStream(getCipher(cipherClass), bufferSize)) {
+            // do the position read until the end of data
+            while (position < total) {
+                byte[] bytes = new byte[length];
+                int n = in.read(position, bytes, 0, length);
+                if (n >= 0) {
+                    compareByteArray(testData, position, bytes, n);
+                    position += n;
+                } else {
+                    break;
+                }
             }
         }
-        in.close();
     }
 
     // test for the out of index position, eg, -1.
     private void testPositionedReadNone(String cipherClass, int position,
             int length, int bufferSize) throws Exception {
-        PositionedCryptoInputStream in = getCryptoInputStream(
-                getCipher(cipherClass), bufferSize);
-        byte[] bytes = new byte[length];
-        int n = in.read(position, bytes, 0, length);
-        Assert.assertEquals(n, -1);
-        in.close();
+        try (PositionedCryptoInputStream in = getCryptoInputStream(getCipher(cipherClass), bufferSize)) {
+            byte[] bytes = new byte[length];
+            int n = in.read(position, bytes, 0, length);
+            Assert.assertEquals(n, -1);
+        }
     }
 
     private void testReadFullyLoop(String cipherClass, int position,
             int length, int bufferSize, int total) throws Exception {
-        PositionedCryptoInputStream in = getCryptoInputStream(
-                getCipher(cipherClass), bufferSize);
+        try (PositionedCryptoInputStream in = getCryptoInputStream(
+                getCipher(cipherClass), bufferSize)) {
+
+            // do the position read full until remain < length
+            while (position + length <= total) {
+                byte[] bytes = new byte[length];
+                in.readFully(position, bytes, 0, length);
+                compareByteArray(testData, position, bytes, length);
+                position += length;
+            }
 
-        // do the position read full until remain < length
-        while (position + length <= total) {
-            byte[] bytes = new byte[length];
-            in.readFully(position, bytes, 0, length);
-            compareByteArray(testData, position, bytes, length);
-            position += length;
         }
-
-        in.close();
     }
 
     // test for the End of file reached before reading fully


[49/50] commons-crypto git commit: CRYPTO-118: Fix pmd and findbugs issues

Posted by sd...@apache.org.
CRYPTO-118: Fix pmd and findbugs issues


Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/5a3bf996
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/5a3bf996
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/5a3bf996

Branch: refs/heads/CRYPTO-1.0.0
Commit: 5a3bf996afa6c7c44ed4aefd5e54b7629f56c075
Parents: 7eac68d
Author: Sun Dapeng <sd...@apache.org>
Authored: Thu Jul 21 11:03:32 2016 +0800
Committer: Sun Dapeng <sd...@apache.org>
Committed: Fri Jul 22 14:38:40 2016 +0800

----------------------------------------------------------------------
 findbugs-exclude.xml                                           | 5 +++++
 src/main/java/org/apache/commons/crypto/Crypto.java            | 2 +-
 .../org/apache/commons/crypto/cipher/CryptoCipherFactory.java  | 1 -
 .../java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java   | 2 +-
 .../org/apache/commons/crypto/jna/OpenSslJnaCryptoRandom.java  | 2 +-
 .../org/apache/commons/crypto/random/CryptoRandomFactory.java  | 1 -
 .../org/apache/commons/crypto/random/OpenSslCryptoRandom.java  | 2 +-
 .../org/apache/commons/crypto/random/OsCryptoRandomTest.java   | 6 ++----
 8 files changed, 11 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/5a3bf996/findbugs-exclude.xml
----------------------------------------------------------------------
diff --git a/findbugs-exclude.xml b/findbugs-exclude.xml
index 82fc9b2..29f446a 100644
--- a/findbugs-exclude.xml
+++ b/findbugs-exclude.xml
@@ -55,5 +55,10 @@
     <Bug pattern="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD,UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD"/>
   </Match>
 
+  <Match>
+    <Class name="org.apache.commons.crypto.NativeCodeLoader" />
+    <Method name="extractLibraryFile" />
+    <Bug pattern="OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE" />
+  </Match>
 </FindBugsFilter>
 

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/5a3bf996/src/main/java/org/apache/commons/crypto/Crypto.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/Crypto.java b/src/main/java/org/apache/commons/crypto/Crypto.java
index 7c86ee8..d72fa4e 100644
--- a/src/main/java/org/apache/commons/crypto/Crypto.java
+++ b/src/main/java/org/apache/commons/crypto/Crypto.java
@@ -63,7 +63,7 @@ public final class Crypto {
                 try (InputStream openStream = url.openStream()) {
                     versionData.load(openStream);
                     return versionData;
-                } catch (IOException e) {
+                } catch (IOException e) {  // NOPMD
                 }
             }
             return new Properties(); // make sure field is not null

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/5a3bf996/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java b/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
index c34753a..2fa6346 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
@@ -56,7 +56,6 @@ public class CryptoCipherFactory {
      * Defines the internal CryptoCipher implementations.
      * <p>
      * Usage:
-     * <p>
      * <blockquote><pre>
      * props.setProperty(CryptoCipherFactory.CLASSES_KEY, CipherProvider.OPENSSL.getClassName());
      * props.setProperty(...); // if required by the implementation

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/5a3bf996/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java b/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
index f8ba94f..e9a0588 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
@@ -59,7 +59,7 @@ class OpenSslJnaCipher implements CryptoCipher {
      * @param transformation transformation for OpenSSL cipher
      * @throws GeneralSecurityException if OpenSSL cipher initialize failed
      */
-    public OpenSslJnaCipher(Properties props, String transformation)
+    public OpenSslJnaCipher(Properties props, String transformation) // NOPMD
             throws GeneralSecurityException {
         if (!OpenSslJna.isEnabled()) {
             throw new GeneralSecurityException("Could not enable JNA access", OpenSslJna.initialisationError());

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/5a3bf996/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCryptoRandom.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCryptoRandom.java b/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCryptoRandom.java
index aa245e6..c9c0419 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCryptoRandom.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCryptoRandom.java
@@ -57,7 +57,7 @@ class OpenSslJnaCryptoRandom extends Random implements CryptoRandom {
      * @param props the configuration properties (not used)
      * @throws GeneralSecurityException  if could not enable JNA access
      */
-    public OpenSslJnaCryptoRandom(Properties props)
+    public OpenSslJnaCryptoRandom(Properties props) //NOPMD
             throws GeneralSecurityException {
         if (!OpenSslJna.isEnabled()) {
             throw new GeneralSecurityException("Could not enable JNA access", OpenSslJna.initialisationError());

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/5a3bf996/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java b/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
index 853a079..5416cc7 100644
--- a/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
+++ b/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
@@ -74,7 +74,6 @@ public class CryptoRandomFactory {
      * Defines the internal CryptoRandom implementations.
      * <p>
      * Usage:
-     * <p>
      * <blockquote><pre>
      * props.setProperty(CryptoRandomFactory.CLASSES_KEY, RandomProvider.OPENSSL.getClassName());
      * props.setProperty(...); // if required by the implementation

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/5a3bf996/src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java b/src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java
index 54c0697..8c9f48b 100644
--- a/src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java
+++ b/src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java
@@ -82,7 +82,7 @@ class OpenSslCryptoRandom extends Random implements CryptoRandom {
      */
     // N.B. this class is not public/protected so does not appear in the main Javadoc
     // Please ensure that property use is documented in the enum CryptoRandomFactory.RandomProvider
-    public OpenSslCryptoRandom(Properties props) throws GeneralSecurityException {
+    public OpenSslCryptoRandom(Properties props) throws GeneralSecurityException { // NOPMD
         if (!nativeEnabled) {
             if (initException != null) {
                 throw new GeneralSecurityException("Native library could not be initialised", initException);

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/5a3bf996/src/test/java/org/apache/commons/crypto/random/OsCryptoRandomTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/random/OsCryptoRandomTest.java b/src/test/java/org/apache/commons/crypto/random/OsCryptoRandomTest.java
index 6382771..4b6e922 100644
--- a/src/test/java/org/apache/commons/crypto/random/OsCryptoRandomTest.java
+++ b/src/test/java/org/apache/commons/crypto/random/OsCryptoRandomTest.java
@@ -17,17 +17,15 @@
  */
 package org.apache.commons.crypto.random;
 
-import static org.junit.Assert.fail;
-
 import java.io.FileNotFoundException;
 import java.lang.reflect.InvocationTargetException;
 import java.security.GeneralSecurityException;
 import java.util.Properties;
 
+import org.junit.Assert;
 import org.junit.Assume;
 import org.junit.Test;
-
-import junit.framework.Assert;
+import static org.junit.Assert.fail;
 
 public class OsCryptoRandomTest extends AbstractRandomTest {
 


[21/50] commons-crypto git commit: Already included in org_apache_commons_crypto.h

Posted by sd...@apache.org.
Already included in org_apache_commons_crypto.h

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/12144845
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/12144845
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/12144845

Branch: refs/heads/CRYPTO-1.0.0
Commit: 121448459fd6b6277f435ca8b9b1fec183adfc78
Parents: 999c0de
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 14:46:40 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 14:46:40 2016 +0100

----------------------------------------------------------------------
 .../crypto/random/org_apache_commons_crypto_random.h      | 10 ----------
 1 file changed, 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/12144845/src/main/native/org/apache/commons/crypto/random/org_apache_commons_crypto_random.h
----------------------------------------------------------------------
diff --git a/src/main/native/org/apache/commons/crypto/random/org_apache_commons_crypto_random.h b/src/main/native/org/apache/commons/crypto/random/org_apache_commons_crypto_random.h
index 7adb060..7040f0a 100644
--- a/src/main/native/org/apache/commons/crypto/random/org_apache_commons_crypto_random.h
+++ b/src/main/native/org/apache/commons/crypto/random/org_apache_commons_crypto_random.h
@@ -21,20 +21,10 @@
 
 #include "org_apache_commons_crypto.h"
 
-#ifdef UNIX
-#include <dlfcn.h>
-#include "config.h"
-#endif
-
-#ifdef WINDOWS
-#include "winutils.h"
-#endif
-
 #define UNUSED(x) ((void)(x))
 
 #include <openssl/crypto.h>
 #include <openssl/engine.h>
 #include <openssl/rand.h>
-#include <openssl/err.h>
 
 #endif //ORG_APACHE_COMMONS_CRYPTO_RANDOM_H


[38/50] commons-crypto git commit: CRYPTO-63 Add JNA binding

Posted by sd...@apache.org.
CRYPTO-63 Add JNA binding

Work-round for JVM crash if close called more than once

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/6ed9de8a
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/6ed9de8a
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/6ed9de8a

Branch: refs/heads/CRYPTO-1.0.0
Commit: 6ed9de8acbe16298350f4a2099776b3537d0bfb4
Parents: 94844c8
Author: Sebb <se...@apache.org>
Authored: Sun Jul 10 14:01:56 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sun Jul 10 14:01:56 2016 +0100

----------------------------------------------------------------------
 .../org/apache/commons/crypto/jna/OpenSslJnaCipher.java   | 10 +++++++++-
 .../apache/commons/crypto/jna/OpenSslJnaCipherTest.java   |  9 ---------
 2 files changed, 9 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/6ed9de8a/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java b/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
index 285fbe7..f8ba94f 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
@@ -239,7 +239,10 @@ class OpenSslJnaCipher implements CryptoCipher {
     public void close() {
         if (context != null) {
             OpenSslNativeJna.EVP_CIPHER_CTX_cleanup(context);
-            OpenSslNativeJna.EVP_CIPHER_CTX_free(context);
+            // Freeing the context multiple times causes a JVM crash
+            // A work-round is to only free it at finalize time
+            // TODO is that sufficient?
+//            OpenSslNativeJna.EVP_CIPHER_CTX_free(context);
         }
     }
     
@@ -328,4 +331,9 @@ class OpenSslJnaCipher implements CryptoCipher {
         return transformation;
     }
 
+    @Override
+    protected void finalize() throws Throwable {
+        OpenSslNativeJna.EVP_CIPHER_CTX_free(context);
+        super.finalize();
+    }
 }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/6ed9de8a/src/test/java/org/apache/commons/crypto/jna/OpenSslJnaCipherTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/jna/OpenSslJnaCipherTest.java b/src/test/java/org/apache/commons/crypto/jna/OpenSslJnaCipherTest.java
index a84fb6f..4b69ac9 100644
--- a/src/test/java/org/apache/commons/crypto/jna/OpenSslJnaCipherTest.java
+++ b/src/test/java/org/apache/commons/crypto/jna/OpenSslJnaCipherTest.java
@@ -35,13 +35,4 @@ public class OpenSslJnaCipherTest extends OpenSslCipherTest {
         cipherClass = OpenSslJnaCipher.class.getName();
     }
 
-    @Override
-    public void closeTestRepeat() {
-        System.err.println("closeTestRepeat() Causes JVM crash");
-    }
-
-    @Override
-    public void reInitAfterClose() {
-        System.err.println("reInitAfterClose() Causes JVM crash");
-    }
 }


[42/50] commons-crypto git commit: Docn

Posted by sd...@apache.org.
Docn

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/5e5cf6d3
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/5e5cf6d3
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/5e5cf6d3

Branch: refs/heads/CRYPTO-1.0.0
Commit: 5e5cf6d3096b4ebee59b658bcd20fdd835718d78
Parents: c22d723
Author: Sebb <se...@apache.org>
Authored: Wed Jul 13 10:15:47 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Wed Jul 13 10:15:47 2016 +0100

----------------------------------------------------------------------
 src/changes/changes.xml | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/5e5cf6d3/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index d6d41ca..5ded7b0 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -29,14 +29,37 @@
   SVN commits. Set the project.properties' maven.changelog.range
   property to the number of days since the last release.
 
+  To generate the release notes from this file:
+  
+  mvn changes:announcement-generate -Prelease-notes [-Dchanges.version=nnn]
+  
+  then tweak the formatting if necessary
+  and commit
 
   The <action> type attribute can be add,update,fix,remove.
 -->
 
 <document>
   <properties>
-    <title>Release Notes</title>
+    <title>Changes</title>
   </properties>
+
+  <!-- NOTE:
+  The description below is specially formatted so as to improve the layout of the generated release notes:
+  The parsing process removes all line feeds, replacing them with a single space.
+  The Velocity template in resources/templates has been enhanced to replace pairs of adjacent spaces
+  with a new-line in the release notes. (These spaces are ignored when displaying HTML).
+  If the output is not quite correct, check for invisible trailing spaces!
+
+  N.B. The release notes template groups actions by type, and only extracts data for the current release.
+  The changes report outputs actions in the order they appear in this file.
+
+  To regenerate the release notes:
+  mvn changes:announcement-generate -Prelease-notes [-Dchanges.version=nnn]
+
+  Defining changes.version allows one to create the RN without first removing the SNAPSHOT suffix.
+   -->
+
   <body>
     <release version="1.0.0" date="2016-06-06" description="Feature and bug fix release">
       <action issue="CRYPTO-68" type="add" dev="britter" >Enable common code quality reports.</action>


[11/50] commons-crypto git commit: Use try-with-resources.

Posted by sd...@apache.org.
Use try-with-resources.

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/d3a77423
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/d3a77423
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/d3a77423

Branch: refs/heads/CRYPTO-1.0.0
Commit: d3a77423a3d54c83e2c6f1ef018b2ebb06b05f12
Parents: 0715c6c
Author: ggregory <gg...@apache.org>
Authored: Fri Jul 8 09:20:11 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Fri Jul 8 09:20:11 2016 -0700

----------------------------------------------------------------------
 .../commons/crypto/examples/RandomExample.java       | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/d3a77423/src/test/java/org/apache/commons/crypto/examples/RandomExample.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/examples/RandomExample.java b/src/test/java/org/apache/commons/crypto/examples/RandomExample.java
index 5206049..5505ee5 100644
--- a/src/test/java/org/apache/commons/crypto/examples/RandomExample.java
+++ b/src/test/java/org/apache/commons/crypto/examples/RandomExample.java
@@ -40,17 +40,16 @@ public class RandomExample {
             CryptoRandomFactory.RandomProvider.OPENSSL.getClassName());
 
         // Gets the 'CryptoRandom' instance.
-        CryptoRandom random = CryptoRandomFactory.getCryptoRandom(properties);
+        try (CryptoRandom random = CryptoRandomFactory.getCryptoRandom(properties)) {
 
-        // Show the actual class (may be different from the one requested)
-        System.out.println(random.getClass().getCanonicalName());
+            // Show the actual class (may be different from the one requested)
+            System.out.println(random.getClass().getCanonicalName());
 
-        // Generate random bytes and places them into the byte arrays.
-        random.nextBytes(key);
-        random.nextBytes(iv);
+            // Generate random bytes and places them into the byte arrays.
+            random.nextBytes(key);
+            random.nextBytes(iv);
 
-        // Closes the CryptoRandom.
-        random.close();
+        }
 
         // Show the generated output
         System.out.println(Arrays.toString(key));


[02/50] commons-crypto git commit: Show JNA status

Posted by sd...@apache.org.
Show JNA status

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/d3bb874a
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/d3bb874a
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/d3bb874a

Branch: refs/heads/CRYPTO-1.0.0
Commit: d3bb874acf65b26e06417fd096496f48c4296cd9
Parents: c446231
Author: Sebb <se...@apache.org>
Authored: Thu Jul 7 18:05:17 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Thu Jul 7 18:05:17 2016 +0100

----------------------------------------------------------------------
 .../crypto/jna/OpenSslNativeJnaTest.java        | 33 ++++++++++++++++++++
 1 file changed, 33 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/d3bb874a/src/test/java/org/apache/commons/crypto/jna/OpenSslNativeJnaTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/jna/OpenSslNativeJnaTest.java b/src/test/java/org/apache/commons/crypto/jna/OpenSslNativeJnaTest.java
new file mode 100644
index 0000000..28b3381
--- /dev/null
+++ b/src/test/java/org/apache/commons/crypto/jna/OpenSslNativeJnaTest.java
@@ -0,0 +1,33 @@
+/**
+ * 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 org.junit.Test;
+
+public class OpenSslNativeJnaTest {
+
+    @Test
+    public void test() {
+        if (OpenSslJna.isEnabled()) {
+            System.out.println("** INFO: JNA is using: " + OpenSslNativeJna.SSLeay_version(0));
+        } else {
+            System.out.println("** WARN: JNA could not be enabled: " + OpenSslJna.initialisationError().getMessage());
+        }
+    }
+}


[37/50] commons-crypto git commit: Unused

Posted by sd...@apache.org.
Unused

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/94844c8b
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/94844c8b
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/94844c8b

Branch: refs/heads/CRYPTO-1.0.0
Commit: 94844c8bb4752200f441fd26edd1e74bf3aba2be
Parents: 403c632
Author: Sebb <se...@apache.org>
Authored: Sun Jul 10 13:40:12 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sun Jul 10 13:40:12 2016 +0100

----------------------------------------------------------------------
 src/main/java/org/apache/commons/crypto/Crypto.java | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/94844c8b/src/main/java/org/apache/commons/crypto/Crypto.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/Crypto.java b/src/main/java/org/apache/commons/crypto/Crypto.java
index 47575d4..12e55c3 100644
--- a/src/main/java/org/apache/commons/crypto/Crypto.java
+++ b/src/main/java/org/apache/commons/crypto/Crypto.java
@@ -20,7 +20,6 @@ package org.apache.commons.crypto;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
-import java.security.GeneralSecurityException;
 import java.util.Properties;
 
 import org.apache.commons.crypto.cipher.CryptoCipherFactory;


[03/50] commons-crypto git commit: Add missing '@Override' annotations.

Posted by sd...@apache.org.
Add missing '@Override' annotations.

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/8773c328
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/8773c328
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/8773c328

Branch: refs/heads/CRYPTO-1.0.0
Commit: 8773c328c54d3ecddfd0dc8d3654f57c8dbf5611
Parents: d3bb874
Author: ggregory <gg...@apache.org>
Authored: Fri Jul 8 09:14:28 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Fri Jul 8 09:14:28 2016 -0700

----------------------------------------------------------------------
 .../apache/commons/crypto/jna/AbstractCipherJnaStreamTest.java   | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/8773c328/src/test/java/org/apache/commons/crypto/jna/AbstractCipherJnaStreamTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/jna/AbstractCipherJnaStreamTest.java b/src/test/java/org/apache/commons/crypto/jna/AbstractCipherJnaStreamTest.java
index e0d4523..5770a3f 100644
--- a/src/test/java/org/apache/commons/crypto/jna/AbstractCipherJnaStreamTest.java
+++ b/src/test/java/org/apache/commons/crypto/jna/AbstractCipherJnaStreamTest.java
@@ -35,6 +35,7 @@ public abstract class AbstractCipherJnaStreamTest extends AbstractCipherStreamTe
     }
 
     /** Test skip. */
+    @Override
     @Test(timeout = 120000)
     public void testSkip() throws Exception {
         doSkipTest(CIPHER_OPENSSL_JNA, false);
@@ -43,6 +44,7 @@ public abstract class AbstractCipherJnaStreamTest extends AbstractCipherStreamTe
     }
 
     /** Test byte buffer read with different buffer size. */
+    @Override
     @Test(timeout = 120000)
     public void testByteBufferRead() throws Exception {
         doByteBufferRead(CIPHER_OPENSSL_JNA, false);
@@ -51,6 +53,7 @@ public abstract class AbstractCipherJnaStreamTest extends AbstractCipherStreamTe
     }
 
     /** Test byte buffer write. */
+    @Override
     @Test(timeout = 120000)
     public void testByteBufferWrite() throws Exception {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -59,6 +62,7 @@ public abstract class AbstractCipherJnaStreamTest extends AbstractCipherStreamTe
         doByteBufferWrite(CIPHER_OPENSSL_JNA, baos, true);
     }
 
+    @Override
     @Test
     public void testReadWrite() throws Exception {
         doReadWriteTest(0, CIPHER_OPENSSL_JNA, CIPHER_OPENSSL_JNA, iv);


[29/50] commons-crypto git commit: Better fix for LoadLibrary parameter on Windows

Posted by sd...@apache.org.
Better fix for LoadLibrary parameter on Windows

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/e8fd891f
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/e8fd891f
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/e8fd891f

Branch: refs/heads/CRYPTO-1.0.0
Commit: e8fd891f329b97a89e0ded65386677d446ed1286
Parents: 5a4c805
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 19:38:29 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 19:38:29 2016 +0100

----------------------------------------------------------------------
 lib/include/config.h                                               | 2 +-
 src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c   | 2 +-
 .../org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/e8fd891f/lib/include/config.h
----------------------------------------------------------------------
diff --git a/lib/include/config.h b/lib/include/config.h
index 93d90ef..8b4c1d4 100755
--- a/lib/include/config.h
+++ b/lib/include/config.h
@@ -20,7 +20,7 @@
 #define __CONFIG_H
 
 #if defined(WINDOWS)
-    #define COMMONS_CRYPTO_OPENSSL_LIBRARY L"libcrypto.dll"
+    #define COMMONS_CRYPTO_OPENSSL_LIBRARY "libcrypto.dll"
 #elif defined(MAC_OS)
     #define COMMONS_CRYPTO_OPENSSL_LIBRARY "libcrypto.dylib"
 #else

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/e8fd891f/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c
----------------------------------------------------------------------
diff --git a/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c b/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c
index 5d90c06..bae10cd 100644
--- a/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c
+++ b/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c
@@ -125,7 +125,7 @@ JNIEXPORT void JNICALL Java_org_apache_commons_crypto_cipher_OpenSslNative_initI
 #endif
 
 #ifdef WINDOWS
-  HMODULE openssl = LoadLibrary(COMMONS_CRYPTO_OPENSSL_LIBRARY);
+  HMODULE openssl = LoadLibrary(TEXT(COMMONS_CRYPTO_OPENSSL_LIBRARY));
 #endif
 
   if (!openssl) {

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/e8fd891f/src/main/native/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c
----------------------------------------------------------------------
diff --git a/src/main/native/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c b/src/main/native/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c
index a6f0b72..20b9d7a 100644
--- a/src/main/native/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c
+++ b/src/main/native/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c
@@ -100,7 +100,7 @@ JNIEXPORT void JNICALL Java_org_apache_commons_crypto_random_OpenSslCryptoRandom
 #endif
 
 #ifdef WINDOWS
-  HMODULE openssl = LoadLibrary(COMMONS_CRYPTO_OPENSSL_LIBRARY);
+  HMODULE openssl = LoadLibrary(TEXT(COMMONS_CRYPTO_OPENSSL_LIBRARY));
 #endif
 
   if (!openssl) {


[48/50] commons-crypto git commit: CRYPTO-116: Fix compile error at 64 bits windows

Posted by sd...@apache.org.
CRYPTO-116: Fix compile error at 64 bits windows


Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/7eac68da
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/7eac68da
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/7eac68da

Branch: refs/heads/CRYPTO-1.0.0
Commit: 7eac68da9407b31bcf318a53b928ceb835e88869
Parents: 6488aa6
Author: Xianda Ke <xi...@intel.com>
Authored: Tue Jul 19 17:36:53 2016 +0800
Committer: Sun Dapeng <sd...@apache.org>
Committed: Tue Jul 19 17:36:53 2016 +0800

----------------------------------------------------------------------
 Makefile.common | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/7eac68da/Makefile.common
----------------------------------------------------------------------
diff --git a/Makefile.common b/Makefile.common
index 7a1e543..ceecbaf 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -245,8 +245,8 @@ Windows-x86_COMMONS_CRYPTO_FLAGS :=
 Windows-x86_64_CC           := $(CROSS_PREFIX)gcc
 Windows-x86_64_CXX          := $(CROSS_PREFIX)g++
 Windows-x86_64_STRIP        := $(CROSS_PREFIX)strip
-Windows-x86_64_CFLAGS       := -I"$(JAVA_HOME)/include" -Ilib/inc_win -O2
-Windows-x86_64_CXXFLAGS     := -I"$(JAVA_HOME)/include" -Ilib/inc_win -O2
+Windows-x86_64_CFLAGS       := -I"$(JAVA_HOME)/include" -Ilib/inc_win -O2 -fno-inline
+Windows-x86_64_CXXFLAGS     := -I"$(JAVA_HOME)/include" -Ilib/inc_win -O2 -fno-inline
 Windows-x86_64_LINKFLAGS    := -Wl,--kill-at -shared -static
 Windows-x86_64_LIBNAME      := commons-crypto.dll
 Windows-x86_64_COMMONS-CRYPTO_FLAGS :=


[46/50] commons-crypto git commit: Docn

Posted by sd...@apache.org.
Docn

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/514dc16e
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/514dc16e
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/514dc16e

Branch: refs/heads/CRYPTO-1.0.0
Commit: 514dc16e98e5c38bf0640745147f54b689482c29
Parents: ffde313
Author: Sebb <se...@apache.org>
Authored: Wed Jul 13 19:00:31 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Wed Jul 13 19:00:31 2016 +0100

----------------------------------------------------------------------
 RELEASE-NOTES.txt       |  7 ++++++-
 src/changes/changes.xml | 11 ++++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/514dc16e/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 67be48b..f98d1c4 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -16,7 +16,7 @@ Features
 2. Java stream API (CryptoInputStream/CryptoOutputStream) for high level stream encyrption/decryption.
 3. Both optimized with high performance AES encryption/decryption. (1400 MB/s - 1700 MB/s throughput in modern Xeon processors).
 4. JNI-based implementation to achieve comparable performance to the native C++ version based on OpenSsl.
-5. Portable across various operating systems (currently only Linux/MacOSX);
+5. Portable across various operating systems (currently only Linux/MacOSX/Windows);
 Apache Commons Crypto loads the library according to your machine environment (it checks system properties, `os.name` and `os.arch`).
 6. Simple usage. Add the commons-crypto-(version).jar file to your classpath.
 
@@ -49,6 +49,11 @@ The following provides more details on the included cryptographic software:
 * Commons Crypto link to and use [OpenSSL](https://www.openssl.org/) ciphers
 
 Initial release
+===============
+The initial release is known to build on Linux, MacOS/X and Windows (using MinGW).
+It may build on other systems.
+Please note that the JNA interface to OpenSSL is a preliminary release.
+It is relatively slow, but may be of use on systems which aren't yet supported by the JNI code.
 
 Changes in this version include:
 

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/514dc16e/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index aab782b..edc0322 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -61,7 +61,16 @@
    -->
 
   <body>
-    <release version="1.0.0" date="2016-07-??" description="Initial release">
+    <release version="1.0.0" date="2016-07-??" description="
+Initial release
+ ===============
+
+The initial release is known to build on Linux, MacOS/X and Windows (using MinGW).
+
+It may build on other systems.
+
+Please note that the JNA interface to OpenSSL is a preliminary release.
+ It is relatively slow, but may be of use on systems which aren't yet supported by the JNI code.">
       <action issue="CRYPTO-68" type="add" dev="britter" >Enable common code quality reports.</action>
       <action issue="CRYPTO-65" type="fix" dev="britter" due-to="sebb">Warnings compiling on MacOSX - JNIEXPORT redefined.</action>
       <action issue="CRYPTO-11" type="add" dev="Ke Jia" due-to="Ke Jia, Jerry Chen">User guide documentation .</action>


[39/50] commons-crypto git commit: Make compiled filename agree with source file

Posted by sd...@apache.org.
Make compiled filename agree with source file

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/dba8b4aa
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/dba8b4aa
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/dba8b4aa

Branch: refs/heads/CRYPTO-1.0.0
Commit: dba8b4aaf41c583eb2af5e3c061570571679ae54
Parents: 6ed9de8
Author: Sebb <se...@apache.org>
Authored: Sun Jul 10 15:39:11 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sun Jul 10 15:39:11 2016 +0100

----------------------------------------------------------------------
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/dba8b4aa/Makefile
----------------------------------------------------------------------
diff --git a/Makefile b/Makefile
index 2d35d29..e579664 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@
 include Makefile.common
 
 COMMONS_CRYPTO_OUT:=$(TARGET)/$(commons-crypto)-$(os_arch)
-COMMONS_CRYPTO_OBJ:=$(addprefix $(COMMONS_CRYPTO_OUT)/,OpensslCryptoRandom.o OpenSslNative.o)
+COMMONS_CRYPTO_OBJ:=$(addprefix $(COMMONS_CRYPTO_OUT)/,OpenSslCryptoRandomNative.o OpenSslNative.o)
 
 # Windows uses different path separators
 ifeq ($(OS_NAME),Windows)
@@ -47,7 +47,7 @@ $(COMMONS_CRYPTO_OUT)/OpenSslNative.o : $(SRC_NATIVE)/org/apache/commons/crypto/
 	@mkdir -p $(@D)
 	$(CC) $(CFLAGS) -c $< -o $@
 
-$(COMMONS_CRYPTO_OUT)/OpensslCryptoRandom.o : $(SRC_NATIVE)/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c $(TARGET)/jni-classes/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.h
+$(COMMONS_CRYPTO_OUT)/OpenSslCryptoRandomNative.o : $(SRC_NATIVE)/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c $(TARGET)/jni-classes/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.h
 	@mkdir -p $(@D)
 	$(CC) $(CFLAGS) -c $< -o $@
 


[50/50] commons-crypto git commit: CRYPTO-119: Fix checkstyle issues

Posted by sd...@apache.org.
CRYPTO-119: Fix checkstyle issues


Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/ed1b6097
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/ed1b6097
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/ed1b6097

Branch: refs/heads/CRYPTO-1.0.0
Commit: ed1b6097c6cfe79dc4e23ac4e9c75fa4b3ccbb04
Parents: 5a3bf99
Author: Sun Dapeng <sd...@apache.org>
Authored: Fri Jul 22 14:40:55 2016 +0800
Committer: Sun Dapeng <sd...@apache.org>
Committed: Fri Jul 22 14:40:55 2016 +0800

----------------------------------------------------------------------
 .../java/org/apache/commons/crypto/Crypto.java  |  10 +
 .../commons/crypto/OpenSslInfoNative.java       |  22 ++-
 .../crypto/cipher/CryptoCipherFactory.java      |   4 +
 .../apache/commons/crypto/jna/OpenSslJna.java   |  12 ++
 .../commons/crypto/jna/OpenSslJnaCipher.java    |  40 +++-
 .../crypto/jna/OpenSslJnaCryptoRandom.java      |  10 +-
 .../commons/crypto/jna/OpenSslNativeJna.java    | 195 ++++++++++++++++++-
 .../crypto/random/CryptoRandomFactory.java      |   4 +
 8 files changed, 281 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ed1b6097/src/main/java/org/apache/commons/crypto/Crypto.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/Crypto.java b/src/main/java/org/apache/commons/crypto/Crypto.java
index d72fa4e..48069f4 100644
--- a/src/main/java/org/apache/commons/crypto/Crypto.java
+++ b/src/main/java/org/apache/commons/crypto/Crypto.java
@@ -56,6 +56,11 @@ public final class Crypto {
     private static class ComponentPropertiesHolder {
         static final Properties PROPERTIES = getComponentProperties();
 
+        /**
+         * Get component properties from component.properties.
+         *
+         * @return Properties contains project version.
+         */
         private static Properties getComponentProperties() {
             URL url = Crypto.class.getResource("/org/apache/commons/crypto/component.properties");
             if (url != null) {
@@ -116,6 +121,11 @@ public final class Crypto {
         return ComponentPropertiesHolder.PROPERTIES.getProperty("NAME");
     }
 
+    /**
+     * The Main of Crypto
+     * @param args don't use the args
+     * @throws Exception if getCryptoRandom or getCryptoCipher get error.
+     */
     public static void main(String args[]) throws Exception {
         System.out.println(getComponentName() + " " + getComponentVersion());
         if (isNativeCodeLoaded()) {

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ed1b6097/src/main/java/org/apache/commons/crypto/OpenSslInfoNative.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/OpenSslInfoNative.java b/src/main/java/org/apache/commons/crypto/OpenSslInfoNative.java
index 3aa394f..8ca2fde 100644
--- a/src/main/java/org/apache/commons/crypto/OpenSslInfoNative.java
+++ b/src/main/java/org/apache/commons/crypto/OpenSslInfoNative.java
@@ -18,7 +18,7 @@
 package org.apache.commons.crypto;
 
 /**
- * JNI interface of {@link CryptoRandom} implementation for OpenSSL.
+ * JNI interface of {@see CryptoRandom} implementation for OpenSSL.
  * The native method in this class is defined in 
  * OpenSslCryptoRandomNative.h (generated at build time by javah)
  * and implemented in the file
@@ -26,16 +26,36 @@ package org.apache.commons.crypto;
  */
 class OpenSslInfoNative {
 
+    /**
+     * Makes the constructor private.
+     */
     private OpenSslInfoNative() {
     }
 
+    /**
+     * @return version of native
+     */
     public static native String NativeVersion();
 
+    /**
+     * @return name of native
+     */
     public static native String NativeName();
 
+    /**
+     * @return timestamp of native
+     */
     public static native String NativeTimeStamp();
 
+    /**
+     * @return the value of SSLEAY_VERSION_NUMBER.
+     */
     public static native long SSLeay();
 
+    /**
+     * Returns SSLeay_version according the version type.
+     * @param type The version type
+     * @return The text variant of the version number and the release date.
+     */
     public static native String SSLeayVersion(int type);
 }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ed1b6097/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java b/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
index 2fa6346..7de06ce 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
@@ -85,6 +85,10 @@ public class CryptoCipherFactory {
 
         private final String className;
 
+        /**
+         * The private constructor.
+         * @param klass the Class of CryptoCipher
+         */
         private CipherProvider(Class<? extends CryptoCipher> klass) {
             this.klass = klass;
             this.className = klass.getName();

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ed1b6097/src/main/java/org/apache/commons/crypto/jna/OpenSslJna.java
----------------------------------------------------------------------
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 b5c90a1..14b9d34 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSslJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSslJna.java
@@ -25,18 +25,30 @@ import org.apache.commons.crypto.random.CryptoRandom;
  */
 public final class OpenSslJna {
 
+    /**
+     * @return The cipher class of JNA implementation
+     */
     public static Class<? extends CryptoCipher> getCipherClass() {
         return OpenSslJnaCipher.class;
     }
 
+    /**
+     * @return The random class of JNA implementation
+     */
     public static Class<? extends CryptoRandom> getRandomClass() {
         return OpenSslJnaCryptoRandom.class;
     }
 
+    /**
+     * @return true if JNA native loads successfully
+     */
     public static boolean isEnabled() {
         return OpenSslNativeJna.INIT_OK;
     }
 
+    /**
+     * @return the error of JNA
+     */
     public static Throwable initialisationError() {
         return OpenSslNativeJna.INIT_ERROR;
     }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ed1b6097/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java b/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
index e9a0588..c83f150 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
@@ -245,8 +245,11 @@ class OpenSslJnaCipher implements CryptoCipher {
 //            OpenSslNativeJna.EVP_CIPHER_CTX_free(context);
         }
     }
-    
-    private void throwOnError(int retVal) {  
+
+    /**
+     * @param retVal the result value of error.
+     */
+    private void throwOnError(int retVal) {
         if (retVal != 1) {
             NativeLong err = OpenSslNativeJna.ERR_peek_error();
             String errdesc = OpenSslNativeJna.ERR_error_string(err, null);
@@ -265,6 +268,12 @@ class OpenSslJnaCipher implements CryptoCipher {
         final String mode;
         final String padding;
 
+        /**
+         * Constructor of Transform.
+         * @param algorithm the algorithm name
+         * @param mode the mode name
+         * @param padding the padding name
+         */
         public Transform(String algorithm, String mode, String padding) {
             this.algorithm = algorithm;
             this.mode = mode;
@@ -272,6 +281,12 @@ class OpenSslJnaCipher implements CryptoCipher {
         }
     }
 
+    /**
+     * Tokenize the transformation.
+     * @param transformation current transformation
+     * @return the Transform
+     * @throws NoSuchAlgorithmException if the algorithm is not supported
+     */
     private static Transform tokenizeTransformation(String transformation)
             throws NoSuchAlgorithmException {
         if (transformation == null) {
@@ -296,10 +311,19 @@ class OpenSslJnaCipher implements CryptoCipher {
         return new Transform(parts[0], parts[1], parts[2]);
     }
     
-    /** Currently only support AES/CTR/NoPadding. */
+    /**
+     * AlgorithmMode of JNA.  Currently only support AES/CTR/NoPadding.
+     */
     private static enum AlgorithmMode {
         AES_CTR, AES_CBC;
 
+        /**
+         * Gets the AlgorithmMode instance.
+         * @param algorithm the algorithm name
+         * @param mode the mode name
+         * @return the AlgorithmMode instance
+         * @throws NoSuchAlgorithmException if the algorithm is not support
+         */
         static AlgorithmMode get(String algorithm, String mode) throws NoSuchAlgorithmException {
             try {
                 return AlgorithmMode.valueOf(algorithm + "_" + mode);
@@ -309,9 +333,19 @@ class OpenSslJnaCipher implements CryptoCipher {
         }
     }
 
+    /**
+     * Padding of JNA.
+     */
     private static enum Padding {
         NoPadding, PKCS5Padding;
 
+        /**
+         * Gets the Padding instance.
+         *
+         * @param padding the padding name
+         * @return the AlgorithmMode instance
+         * @throws NoSuchPaddingException if the algorithm is not support
+         */
         static int get(String padding) throws NoSuchPaddingException {
             try {
                 return Padding.valueOf(padding).ordinal();

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ed1b6097/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCryptoRandom.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCryptoRandom.java b/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCryptoRandom.java
index c9c0419..b3f4c4f 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCryptoRandom.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCryptoRandom.java
@@ -164,7 +164,10 @@ class OpenSslJnaCryptoRandom extends Random implements CryptoRandom {
         //OpenSslNativeJna.CRYPTO_set_locking_callback(null);
         //LOCK.unlock();
     }
-    
+
+    /**
+     * Closes the rdrand engine.
+     */
     private void closeRdrandEngine() {
         
         if(rdrandEngine != null) {
@@ -181,7 +184,10 @@ class OpenSslJnaCryptoRandom extends Random implements CryptoRandom {
     public boolean isRdrandEnabled() {
         return rdrandEnabled;
     }
-    
+
+    /**
+     * @param retVal the result value of error.
+     */
     private void throwOnError(int retVal) {  
         if (retVal != 1) {
             NativeLong err = OpenSslNativeJna.ERR_peek_error();

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ed1b6097/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
----------------------------------------------------------------------
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 f75566e..099c049 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
@@ -32,7 +32,7 @@ class OpenSslNativeJna {
     static final int OOSL_JNA_DECRYPT_MODE = 0;
 
     static final boolean INIT_OK;
- 
+
     static final Throwable INIT_ERROR;
 
     static {
@@ -53,54 +53,229 @@ class OpenSslNativeJna {
     }
 
     //misc
+    /**
+     * @return OPENSSL_VERSION_NUMBER which is a numeric release version
+     * * identifier
+     */
     public static native NativeLong SSLeay();
+
+    /**
+     * Retrieves version/build information about OpenSSL library.
+     *
+     * @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 giving information about the library build.
+     */
     public static native String SSLeay_version(int type);
+
+    /**
+     * Registers the error strings for all libcrypto functions.
+     */
     public static native void ERR_load_crypto_strings();
+
+    /**
+     * @return the earliest error code from the thread's error queue without
+     * modifying it.
+     */
     public static native NativeLong ERR_peek_error();
+
+
+
+    /**
+     * Generates a human-readable string representing the error code e.
+     * @see <a>https://www.openssl.org/docs/manmaster/crypto/ERR_error_string.html</a>
+     *
+     * @param err the error code
+     * @param null_ buf is NULL, the error string is placed in a static buffer
+     * @return the human-readable error messages.
+     */
     public static native String ERR_error_string(NativeLong err, char[] null_);
     //String ERR_lib_error_string(NativeLong err);
     //String ERR_func_error_string(NativeLong err);
-    //String ERR_reason_error_string(NativeLong err);
-    
+
     //en-/decryption
+    /**
+     * Creates a cipher context.
+     *
+     * @return a pointer to a newly created EVP_CIPHER_CTX for success and
+     * NULL for failure.
+     */
     public static native PointerByReference EVP_CIPHER_CTX_new();
+
+
+    /**
+     * EVP_CIPHER_CTX_init() remains as an alias for EVP_CIPHER_CTX_reset
+     * @param p cipher context
+     */
     public static native void EVP_CIPHER_CTX_init(PointerByReference p);
+
+    /**
+     * Enables or disables padding
+     * @param c cipher context
+     * @param pad If the pad parameter is zero then no padding is performed
+     * @return always returns 1
+     */
     public static native int EVP_CIPHER_CTX_set_padding(PointerByReference c, int pad);
+
+    /**
+     * @return an openssl AES evp cipher instance with a 128-bit key CBC mode
+     */
     public static native PointerByReference EVP_aes_128_cbc();
+
+    /**
+     * @return an openssl AES evp cipher instance with a 128-bit key CTR mode
+     */
     public static native PointerByReference EVP_aes_128_ctr();
+
+    /**
+     * @return an openssl AES evp cipher instance with a 192-bit key CBC mode
+     */
     public static native PointerByReference EVP_aes_192_cbc();
+
+    /**
+     * @return an openssl AES evp cipher instance with a 192-bit key CTR mode
+     */
     public static native PointerByReference EVP_aes_192_ctr();
+
+    /**
+     * @return an openssl AES evp cipher instance with a 256-bit key CBC mode
+     */
     public static native PointerByReference EVP_aes_256_cbc();
+
+    /**
+     * @return an openssl AES evp cipher instance with a 256-bit key CTR mode
+     */
     public static native PointerByReference EVP_aes_256_ctr();
+
+    /**
+     * Init a cipher.
+     * @param ctx cipher context
+     * @param cipher evp cipher instance
+     * @param impl engine
+     * @param key key
+     * @param iv iv
+     * @param enc 1 for encryption, 0 for decryption
+     * @return 1 for success and 0 for failure.
+     */
     public static native int EVP_CipherInit_ex(PointerByReference ctx, PointerByReference cipher, PointerByReference impl, byte key[], byte iv[], int enc);
+
+
+    /**
+     * Continues a multiple-part encryption/decryption operation.
+     *
+     * @param ctx cipher context
+     * @param bout output byte buffer
+     * @param outl output length
+     * @param in input byte buffer
+     * @param inl input length
+     * @return 1 for success and 0 for failure.
+     */
     public static native int EVP_CipherUpdate(PointerByReference ctx, ByteBuffer bout, int[] outl, ByteBuffer in, int inl);
-    public static native int EVP_CipherFinal_ex(PointerByReference ctx, ByteBuffer bout, int[] outl);   
+
+    /**
+     * Finishes a multiple-part operation.
+     *
+     * @param ctx cipher context
+     * @param bout output byte buffer
+     * @param outl output length
+     * @return 1 for success and 0 for failure.
+     */
+    public static native int EVP_CipherFinal_ex(PointerByReference ctx, ByteBuffer bout, int[] outl);
+
+    /**
+     * Clears all information from a cipher context and free up any allocated
+     * memory associate with it, including ctx itself.
+     * @param c openssl evp cipher
+     */
     public static native void EVP_CIPHER_CTX_free(PointerByReference c);
+
+    /**
+     * Clears all information from a cipher context and free up any allocated
+     * * memory associate with it.
+     * @param c openssl evp cipher
+     */
     public static native void EVP_CIPHER_CTX_cleanup(PointerByReference c);
-    
+
     //Random generator
+    /**
+     * OpenSSL uses for random number generation
+     * @return pointers to the respective methods
+     */
     public static native PointerByReference RAND_get_rand_method();
+
+    /**
+     * OpenSSL uses for random number generation.
+     * @return pointers to the respective methods
+     */
     public static native PointerByReference RAND_SSLeay();
+
+    /**
+     * Generates random data
+     * @param buf the bytes for generated random.
+     * @param num buffer length
+     * @return 1 on success, 0 otherwise.
+     */
     public static native int RAND_bytes(ByteBuffer buf, int num);
+
+    /**
+     * Releases all functional references.
+     *
+     * @param e engine reference.
+     * @return 0 on success, 1 otherwise.
+     */
     public static native int ENGINE_finish(PointerByReference e);
+
+    /**
+     * Frees the structural reference
+     * @param e engine reference.
+     * @return 0 on success, 1 otherwise.
+     */
     public static native int ENGINE_free(PointerByReference e);
+
+    /**
+     * Cleanups before program exit, it will avoid memory leaks.
+     * @return 0 on success, 1 otherwise.
+     */
     public static native int ENGINE_cleanup();
+
+    /**
+     * Obtains a functional reference from an existing structural reference.
+     * @param e engine reference
+     * @return zero if the ENGINE was not already operational and couldn't be successfully initialised
+     */
     public static native int ENGINE_init(PointerByReference e);
+
+    /**
+     * Sets the engine as the default for random number generation.
+     * @param e  engine reference
+     * @param flags ENGINE_METHOD_RAND
+     * @return zero if failed.
+     */
     public static native int ENGINE_set_default(PointerByReference e, int flags);
+
+    /**
+     * Gets engine by id
+     * @param id engine id
+     * @return engine instance
+     */
     public static native PointerByReference ENGINE_by_id(String id);
+
+    /**
+     * Initializes the engine.
+     */
     public static native void ENGINE_load_rdrand();
-    
+
     //TODO callback multithreading
     /*public interface Id_function_cb extends Callback {
         long invoke ();
     }
-   
+
     public interface Locking_function_cb extends Callback {
         void invoke(int mode, int n, String file, int line);
     }
-    
+
     public static final Id_function_cb default_id_function = new Id_function_cb() {
-        
+
         @Override
         public long invoke() {
             //id always positive
@@ -108,7 +283,7 @@ class OpenSslNativeJna {
             return id;
         }
     };
-    
+
     int CRYPTO_num_locks();
     void CRYPTO_set_id_callback(Id_function_cb id_function);
     void CRYPTO_set_locking_callback(Locking_function_cb locking_function);*/

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ed1b6097/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java b/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
index 5416cc7..2ef50ba 100644
--- a/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
+++ b/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
@@ -116,6 +116,10 @@ public class CryptoRandomFactory {
 
         private final String className;
 
+        /**
+         * The private constructor.
+         * @param klass the Class of CryptoRandom
+         */
         private RandomProvider(Class<? extends CryptoRandom> klass) {
             this.klass = klass;
             this.className = klass.getName();


[41/50] commons-crypto git commit: MinGW now works

Posted by sd...@apache.org.
MinGW now works


Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/c22d7234
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/c22d7234
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/c22d7234

Branch: refs/heads/CRYPTO-1.0.0
Commit: c22d7234cd86cf1ea7082b3e3bbd616c0d3206ba
Parents: eaed08d
Author: Sebb <se...@apache.org>
Authored: Mon Jul 11 01:13:03 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Mon Jul 11 01:13:03 2016 +0100

----------------------------------------------------------------------
 BUILDING.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/c22d7234/BUILDING.txt
----------------------------------------------------------------------
diff --git a/BUILDING.txt b/BUILDING.txt
index e6961a6..88b1098 100644
--- a/BUILDING.txt
+++ b/BUILDING.txt
@@ -3,7 +3,7 @@ Build instructions for Apache Commons Crypto
 ----------------------------------------------------------------------------------
 Requirements:
 
-* Unix System (Linux or Mac)
+* Unix System (Linux or Mac), or Windows with MinGW
 * JDK 1.7 or above (environment variable JAVA_HOME must be set)
 * Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy
   Files (if running unit tests)


[14/50] commons-crypto git commit: No point recreating the File object

Posted by sd...@apache.org.
No point recreating the File object

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/e5a6548f
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/e5a6548f
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/e5a6548f

Branch: refs/heads/CRYPTO-1.0.0
Commit: e5a6548f9c610717ffca3163638c0e59c9ea4591
Parents: c27ed6e
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 00:19:16 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 00:19:16 2016 +0100

----------------------------------------------------------------------
 src/main/java/org/apache/commons/crypto/NativeCodeLoader.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/e5a6548f/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java b/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
index ec96a4e..4d4dbcb 100644
--- a/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
+++ b/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
@@ -206,7 +206,7 @@ final class NativeCodeLoader {
                 }
             }
 
-            return new File(targetFolder, extractedLibFileName);
+            return extractedLibFile;
         } catch (IOException e) {
             return null;
         } finally {


[28/50] commons-crypto git commit: Undefine snprintf on MinGW

Posted by sd...@apache.org.
Undefine snprintf on MinGW

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/5a4c8059
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/5a4c8059
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/5a4c8059

Branch: refs/heads/CRYPTO-1.0.0
Commit: 5a4c8059fbc49f90d150f00f42049eadf4ac996d
Parents: 56894ba
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 19:00:30 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 19:00:30 2016 +0100

----------------------------------------------------------------------
 .../native/org/apache/commons/crypto/org_apache_commons_crypto.h   | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/5a4c8059/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
----------------------------------------------------------------------
diff --git a/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h b/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
index f39faa7..4fbcc83 100644
--- a/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
+++ b/src/main/native/org/apache/commons/crypto/org_apache_commons_crypto.h
@@ -133,7 +133,9 @@ void *do_dlsym(JNIEnv *env, void *handle, const char *symbol) {
 #include <stdio.h>
 #include <jni.h>
 
+#if !defined(__MINGW32__) /* does not appear to be needed on MinGW */
 #define snprintf(a, b ,c, d) _snprintf_s((a), (b), _TRUNCATE, (c), (d))
+#endif
 
 /* A helper macro to dlsym the requisite dynamic symbol and bail-out on error. */
 #define LOAD_DYNAMIC_SYMBOL(func_type, func_ptr, env, handle, symbol) \


[24/50] commons-crypto git commit: Syntax error: missing closing parenthesis

Posted by sd...@apache.org.
Syntax error: missing closing parenthesis

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/a1089e1f
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/a1089e1f
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/a1089e1f

Branch: refs/heads/CRYPTO-1.0.0
Commit: a1089e1fad8a279da812725d5bb9b7f8f0dac596
Parents: 2d38230
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 15:45:34 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 15:45:34 2016 +0100

----------------------------------------------------------------------
 .../org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/a1089e1f/src/main/native/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c
----------------------------------------------------------------------
diff --git a/src/main/native/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c b/src/main/native/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c
index 07dd4f9..a6f0b72 100644
--- a/src/main/native/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c
+++ b/src/main/native/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c
@@ -62,7 +62,7 @@ typedef void * (__cdecl *__dlsym_CRYPTO_malloc) (int, const char *, int);
 typedef void (__cdecl *__dlsym_CRYPTO_free) (void *);
 typedef int (__cdecl *__dlsym_CRYPTO_num_locks) (void);
 typedef void (__cdecl *__dlsym_CRYPTO_set_locking_callback)  \
-              (void (*)(int, int, char *, int);
+              (void (*)(int, int, char *, int));
 typedef void (__cdecl *__dlsym_ENGINE_load_rdrand) (void);
 typedef ENGINE * (__cdecl *__dlsym_ENGINE_by_id) (const char *);
 typedef int (__cdecl *__dlsym_ENGINE_init) (ENGINE *);


[30/50] commons-crypto git commit: Windows uses LoadLibrary/GetLastError

Posted by sd...@apache.org.
Windows uses LoadLibrary/GetLastError

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/f880ccff
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/f880ccff
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/f880ccff

Branch: refs/heads/CRYPTO-1.0.0
Commit: f880ccff6753c49b77746f9d4a37217ecf2779e1
Parents: e8fd891
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 19:43:51 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 19:43:51 2016 +0100

----------------------------------------------------------------------
 .../native/org/apache/commons/crypto/cipher/OpenSslNative.c    | 6 ++++++
 .../apache/commons/crypto/random/OpenSslCryptoRandomNative.c   | 6 ++++++
 2 files changed, 12 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/f880ccff/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c
----------------------------------------------------------------------
diff --git a/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c b/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c
index bae10cd..5e39e13 100644
--- a/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c
+++ b/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c
@@ -129,8 +129,14 @@ JNIEXPORT void JNICALL Java_org_apache_commons_crypto_cipher_OpenSslNative_initI
 #endif
 
   if (!openssl) {
+#ifdef UNIX
     snprintf(msg, sizeof(msg), "Cannot load %s (%s)!", COMMONS_CRYPTO_OPENSSL_LIBRARY,  \
         dlerror());
+#endif
+#ifdef WINDOWS
+    snprintf(msg, sizeof(msg), "Cannot load %s (%d)!", COMMONS_CRYPTO_OPENSSL_LIBRARY,  \
+    		GetLastError());
+#endif
     THROW(env, "java/lang/UnsatisfiedLinkError", msg);
     return;
   }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/f880ccff/src/main/native/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c
----------------------------------------------------------------------
diff --git a/src/main/native/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c b/src/main/native/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c
index 20b9d7a..8f0e9b0 100644
--- a/src/main/native/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c
+++ b/src/main/native/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c
@@ -104,8 +104,14 @@ JNIEXPORT void JNICALL Java_org_apache_commons_crypto_random_OpenSslCryptoRandom
 #endif
 
   if (!openssl) {
+#ifdef UNIX
     snprintf(msg, sizeof(msg), "Cannot load %s (%s)!", COMMONS_CRYPTO_OPENSSL_LIBRARY,  \
         dlerror());
+#endif
+#ifdef WINDOWS
+    snprintf(msg, sizeof(msg), "Cannot load %s (%d)!", COMMONS_CRYPTO_OPENSSL_LIBRARY,  \
+    		GetLastError());
+#endif
     THROW(env, "java/lang/UnsatisfiedLinkError", msg);
     return;
   }


[25/50] commons-crypto git commit: Also catch UnsatisfiedLinkError in case OpenSSL library cannot be found

Posted by sd...@apache.org.
Also catch UnsatisfiedLinkError in case OpenSSL library cannot be found

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/f4d5737e
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/f4d5737e
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/f4d5737e

Branch: refs/heads/CRYPTO-1.0.0
Commit: f4d5737e3906350eaf7cdcd6dd188ababa79220d
Parents: a1089e1
Author: Sebb <se...@apache.org>
Authored: Sat Jul 9 17:39:59 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jul 9 17:39:59 2016 +0100

----------------------------------------------------------------------
 src/main/java/org/apache/commons/crypto/cipher/OpenSsl.java    | 2 ++
 .../org/apache/commons/crypto/random/OpenSslCryptoRandom.java  | 6 ++++--
 2 files changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/f4d5737e/src/main/java/org/apache/commons/crypto/cipher/OpenSsl.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/OpenSsl.java b/src/main/java/org/apache/commons/crypto/cipher/OpenSsl.java
index 64487d4..0898158 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/OpenSsl.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/OpenSsl.java
@@ -98,6 +98,8 @@ final class OpenSsl {
             }
         } catch (Exception t) {
             loadingFailure = t.getMessage();
+        } catch (UnsatisfiedLinkError t) {
+            loadingFailure = t.getMessage();            
         } finally {
             loadingFailureReason = loadingFailure;
         }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/f4d5737e/src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java b/src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java
index d3877cb..54c0697 100644
--- a/src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java
+++ b/src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java
@@ -46,17 +46,19 @@ class OpenSslCryptoRandom extends Random implements CryptoRandom {
 
     private static final boolean nativeEnabled;
 
-    private static final Exception initException;
+    private static final Throwable initException;
 
     static {
         boolean opensslLoaded = false;
-        Exception except = null;
+        Throwable except = null;
         if (Crypto.isNativeCodeLoaded()) {
             try {
                 OpenSslCryptoRandomNative.initSR();
                 opensslLoaded = true;
             } catch (Exception t) {
                 except = t;
+            } catch (UnsatisfiedLinkError t) {
+                except = t;
             }
         }
         nativeEnabled = opensslLoaded;


[10/50] commons-crypto git commit: Formatting: Missing spaces.

Posted by sd...@apache.org.
Formatting: Missing spaces.

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/0715c6c5
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/0715c6c5
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/0715c6c5

Branch: refs/heads/CRYPTO-1.0.0
Commit: 0715c6c5ff6f5d7d3b4e55dec434d3b1711492a5
Parents: 6f6d6b0
Author: ggregory <gg...@apache.org>
Authored: Fri Jul 8 09:19:46 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Fri Jul 8 09:19:46 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/commons/crypto/examples/RandomExample.java | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/0715c6c5/src/test/java/org/apache/commons/crypto/examples/RandomExample.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/examples/RandomExample.java b/src/test/java/org/apache/commons/crypto/examples/RandomExample.java
index 0387472..5206049 100644
--- a/src/test/java/org/apache/commons/crypto/examples/RandomExample.java
+++ b/src/test/java/org/apache/commons/crypto/examples/RandomExample.java
@@ -31,7 +31,7 @@ import org.apache.commons.crypto.random.CryptoRandomFactory;
 public class RandomExample {
 
     public static void main(String []args) throws GeneralSecurityException, IOException {
-        //Constructs a byte array to store random data.
+        // Constructs a byte array to store random data.
         byte[] key = new byte[16];
         byte[] iv = new byte[32];
 
@@ -39,7 +39,7 @@ public class RandomExample {
         properties.put(CryptoRandomFactory.CLASSES_KEY,
             CryptoRandomFactory.RandomProvider.OPENSSL.getClassName());
 
-        //Gets the 'CryptoRandom' instance.
+        // Gets the 'CryptoRandom' instance.
         CryptoRandom random = CryptoRandomFactory.getCryptoRandom(properties);
 
         // Show the actual class (may be different from the one requested)
@@ -49,7 +49,7 @@ public class RandomExample {
         random.nextBytes(key);
         random.nextBytes(iv);
 
-        //Closes the CryptoRandom.
+        // Closes the CryptoRandom.
         random.close();
 
         // Show the generated output


[44/50] commons-crypto git commit: Initial example; changes.xml needs more work

Posted by sd...@apache.org.
Initial example; changes.xml needs more work

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/a8271071
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/a8271071
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/a8271071

Branch: refs/heads/CRYPTO-1.0.0
Commit: a82710711ea01a66fe3b65010f501a628fd1d8c4
Parents: 0c07adb
Author: Sebb <se...@apache.org>
Authored: Wed Jul 13 10:23:00 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Wed Jul 13 10:23:00 2016 +0100

----------------------------------------------------------------------
 RELEASE-NOTES.txt | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/a8271071/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
new file mode 100644
index 0000000..67be48b
--- /dev/null
+++ b/RELEASE-NOTES.txt
@@ -0,0 +1,92 @@
+              Apache Commons Crypto 1.0.0
+                  RELEASE NOTES
+
+The Apache Commons Crypto team is pleased to announce the release of Apache Commons Crypto 1.0.0
+
+Apache Commons Crypto is a cryptographic library optimized with AES-NI (Advanced Encryption
+Standard New Instructions). It provides Java API for both cipher level and Java stream level.
+Developers can use it to implement high performance AES encryption/decryption with the minimum
+code and effort. Please note that Crypto doesn't implement the cryptographic algorithm such as
+AES directly. It wraps to Openssl or JCE which implement the algorithms.
+
+Features
+--------
+
+1. Cipher API for low level cryptographic operations.
+2. Java stream API (CryptoInputStream/CryptoOutputStream) for high level stream encyrption/decryption.
+3. Both optimized with high performance AES encryption/decryption. (1400 MB/s - 1700 MB/s throughput in modern Xeon processors).
+4. JNI-based implementation to achieve comparable performance to the native C++ version based on OpenSsl.
+5. Portable across various operating systems (currently only Linux/MacOSX);
+Apache Commons Crypto loads the library according to your machine environment (it checks system properties, `os.name` and `os.arch`).
+6. Simple usage. Add the commons-crypto-(version).jar file to your classpath.
+
+
+Export restrictions
+-------------------
+
+This distribution includes cryptographic software.
+The country in which you currently reside may have restrictions
+on the import, possession, use, and/or re-export to another country,
+of encryption software. BEFORE using any encryption software,
+please check your country's laws, regulations and policies
+concerning the import, possession, or use, and re-export of
+encryption software, to see if this is permitted.
+See <http://www.wassenaar.org/> for more information.
+
+The U.S. Government Department of Commerce, Bureau of Industry and Security (BIS),
+has classified this software as Export Commodity Control Number (ECCN) 5D002.C.1,
+which includes information security software using or performing
+cryptographic functions with asymmetric algorithms.
+The form and manner of this Apache Software Foundation distribution makes
+it eligible for export under the License Exception
+ENC Technology Software Unrestricted (TSU) exception
+(see the BIS Export Administration Regulations, Section 740.13)
+for both object code and source code.
+
+The following provides more details on the included cryptographic software:
+
+* Commons Crypto use [Java Cryptography Extension](http://docs.oracle.com/javase/8/docs/technotes/guides/security/crypto/CryptoSpec.html) provided by Java
+* Commons Crypto link to and use [OpenSSL](https://www.openssl.org/) ciphers
+
+Initial release
+
+Changes in this version include:
+
+New features:
+o CRYPTO-68:   Enable common code quality reports.
+o CRYPTO-11:   User guide documentation . Thanks to Ke Jia, Jerry Chen.
+o CRYPTO-12:   Rename CryptoInputStream to CipherInputStream and CryptoOutputStream to CipherOutputStream . Thanks to Xianda Ke.
+o CRYPTO-13:   The API differences between apache.commons.crypto and JCE . Thanks to Xianda Ke.
+o CRYPTO-40:   Remove the full qualified package name for shadowed classes . Thanks to Xianda Ke, Jerry Chen.
+o CRYPTO-42:   Remove the header files required for cross platform compilation . Thanks to Dian Fu, Jerry Chen.
+o CRYPTO-45:   Document how to build Commons Crypto . Thanks to Dian Fu, Benedikt Ritter.
+o CRYPTO-48:   Setup site build as defined in commons-parent pom . Thanks to Benedikt Ritter, Dapeng Sun.
+
+Fixed Bugs:
+o CRYPTO-65:   Warnings compiling on MacOSX - JNIEXPORT redefined. Thanks to sebb.
+o CRYPTO-29:   Make sure Cipher.ENCRYPT_MODE is consistent with JDK . Thanks to Dian Fu, Sebb.
+o CRYPTO-30:   Mutable fields should be private . Thanks to Ferdinand Xu, Sebb.
+o CRYPTO-34:   JavaSecureRandom should throw Exception if it cannot create the instance . Thanks to Dapeng Sun, Sebb.
+o CRYPTO-47:   Fix build of MAC_OS . Thanks to Dapeng Sun.
+o CRYPTO-49:   CRYPTO-1 Fix build of X86 . Thanks to Dapeng Sun.
+o CRYPTO-57:   Fix build on Mac OS Thanks to Benedikt Ritter.
+o CRYPTO-61:   Fix possible NPE in OpensslCryptoRandom Thanks to Hendrik Saly.
+o CRYPTO-54:   US Export classification and ECCN registration for encryption Thanks to Stian Soiland-Reyes, Jerry Chen, Benedikt Ritter, Gary Gregory.
+
+Changes:
+o CRYPTO-26:   Utility classes should not have public constructors . Thanks to Dapeng Sun.
+o CRYPTO-28:   Update the README.md of Apache Commons Crypto . Thanks to Ferdinand Xu, Ke Jia.
+o CRYPTO-3:    Change default cipher as OpensslCipher . Thanks to ferdinand xu.
+o CRYPTO-31:   Make fields final wherever possible . Thanks to Ferdinand Xu, Sebb.
+o CRYPTO-33:   SecureRandom shadows JVM class . Thanks to Xianda Ke, Sebb.
+o CRYPTO-38:   Always use blocks . Thanks to Dapeng Sun, Gary Gregory.
+o CRYPTO-7:    Rename source code in Chimera to Apache name space . Thanks to ferdinand xu.
+o CRYPTO-62:   Add multithreaded related tests Thanks to Hendrik Saly.
+
+
+Historical list of changes: http://commons.apache.org/proper/commons-crypto/changes-report.html
+
+For complete information on Apache Commons Crypto, including instructions on how to submit bug reports,
+patches, or suggestions for improvement, see the Apache Apache Commons Crypto website:
+
+http://commons.apache.org/proper/commons-crypto/


[06/50] commons-crypto git commit: Statement unnecessarily nested within else clause.

Posted by sd...@apache.org.
Statement unnecessarily nested within else clause.

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/5119f841
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/5119f841
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/5119f841

Branch: refs/heads/CRYPTO-1.0.0
Commit: 5119f8411967624382804dd96ebfb2e87d7fba96
Parents: a312850
Author: ggregory <gg...@apache.org>
Authored: Fri Jul 8 09:16:38 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Fri Jul 8 09:16:38 2016 -0700

----------------------------------------------------------------------
 .../commons/crypto/random/OpenSslCryptoRandom.java      | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/5119f841/src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java b/src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java
index e7f026f..d3877cb 100644
--- a/src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java
+++ b/src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java
@@ -84,14 +84,12 @@ class OpenSslCryptoRandom extends Random implements CryptoRandom {
         if (!nativeEnabled) {
             if (initException != null) {
                 throw new GeneralSecurityException("Native library could not be initialised", initException);
-            } else {
-                throw new GeneralSecurityException("Native library is not loaded");
-            }
-        } else {
-            // Check that nextRandBytes works (is this really needed?)
-            if (!OpenSslCryptoRandomNative.nextRandBytes(new byte[1])) {
-                throw new GeneralSecurityException("Check of nextRandBytes failed");
             }
+            throw new GeneralSecurityException("Native library is not loaded");
+        }
+        // Check that nextRandBytes works (is this really needed?)
+        if (!OpenSslCryptoRandomNative.nextRandBytes(new byte[1])) {
+            throw new GeneralSecurityException("Check of nextRandBytes failed");
         }
     }