Repository: commons-crypto
Updated Branches:
  refs/heads/master acb1a15a8 -> 250e9184e


Separate remaining JNA tests

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

Branch: refs/heads/master
Commit: 250e9184e15b634a8d6855433012beae519f124b
Parents: acb1a15
Author: Sebb <s...@apache.org>
Authored: Sat Jul 2 16:10:55 2016 +0100
Committer: Sebb <s...@apache.org>
Committed: Sat Jul 2 16:10:55 2016 +0100

----------------------------------------------------------------------
 .../crypto/cipher/AbstractCipherTest.java       |  2 -
 .../crypto/jna/AbstractCipherJnaStreamTest.java | 69 ++++++++++++++++++++
 .../jna/CbcNoPaddingCipherJnaStreamTest.java    | 28 ++++++++
 .../jna/CbcPkcs5PaddingCipherJnaStreamTest.java | 29 ++++++++
 .../crypto/jna/CtrCryptoJnaStreamTest.java      | 30 +++++++++
 .../jna/CtrNoPaddingCipherJnaStreamTest.java    | 29 ++++++++
 .../crypto/stream/AbstractCipherStreamTest.java | 25 ++-----
 7 files changed, 191 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/250e9184/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java 
b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
index 0101e5e..8d5fbbb 100644
--- a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
+++ b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
@@ -44,8 +44,6 @@ public abstract class AbstractCipherTest {
 
     public static final String JCE_CIPHER_CLASSNAME = 
JceCipher.class.getName();
 
-    public static final String OPENSSLJNA_CIPHER_CLASSNAME = 
OpenSslJna.getCipherClass().getName();
-
     // data
     public static final int BYTEBUFFER_SIZE = 1000;
 

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/250e9184/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
new file mode 100644
index 0000000..a035b39
--- /dev/null
+++ 
b/src/test/java/org/apache/commons/crypto/jna/AbstractCipherJnaStreamTest.java
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.crypto.jna;
+
+import java.io.ByteArrayOutputStream;
+
+import org.apache.commons.crypto.cipher.AbstractCipherTest;
+import org.apache.commons.crypto.stream.AbstractCipherStreamTest;
+import org.junit.Test;
+
+public abstract class AbstractCipherJnaStreamTest extends 
AbstractCipherStreamTest {
+
+    private static final String CIPHER_OPENSSL_JNA = 
OpenSslJna.getCipherClass().getName();
+
+    /** Test skip. */
+    @Test(timeout = 120000)
+    public void testSkip() throws Exception {
+        doSkipTest(CIPHER_OPENSSL_JNA, false);
+
+        doSkipTest(CIPHER_OPENSSL_JNA, true);
+    }
+
+    /** Test byte buffer read with different buffer size. */
+    @Test(timeout = 120000)
+    public void testByteBufferRead() throws Exception {
+        doByteBufferRead(CIPHER_OPENSSL_JNA, false);
+
+        doByteBufferRead(CIPHER_OPENSSL_JNA, true);
+    }
+
+    /** Test byte buffer write. */
+    @Test(timeout = 120000)
+    public void testByteBufferWrite() throws Exception {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        doByteBufferWrite(CIPHER_OPENSSL_JNA, baos, false);
+
+        doByteBufferWrite(CIPHER_OPENSSL_JNA, baos, true);
+    }
+
+    @Test
+    public void testReadWrite() throws Exception {
+        doReadWriteTest(0, CIPHER_OPENSSL_JNA, CIPHER_OPENSSL_JNA, iv);
+        doReadWriteTest(count, CIPHER_OPENSSL_JNA, CIPHER_OPENSSL_JNA, iv);
+        doReadWriteTest(count, AbstractCipherTest.JCE_CIPHER_CLASSNAME, 
CIPHER_OPENSSL_JNA, iv);
+        doReadWriteTest(count, CIPHER_OPENSSL_JNA, 
AbstractCipherTest.JCE_CIPHER_CLASSNAME, iv);
+        // Overflow test, IV: xx xx xx xx xx xx xx xx ff ff ff ff ff ff ff ff
+        for (int i = 0; i < 8; i++) {
+            iv[8 + i] = (byte) 0xff;
+        }
+        doReadWriteTest(count, CIPHER_OPENSSL_JNA, CIPHER_OPENSSL_JNA, iv);
+        doReadWriteTest(count, AbstractCipherTest.JCE_CIPHER_CLASSNAME, 
CIPHER_OPENSSL_JNA, iv);
+        doReadWriteTest(count, CIPHER_OPENSSL_JNA, 
AbstractCipherTest.JCE_CIPHER_CLASSNAME, iv);
+    }
+}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/250e9184/src/test/java/org/apache/commons/crypto/jna/CbcNoPaddingCipherJnaStreamTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/commons/crypto/jna/CbcNoPaddingCipherJnaStreamTest.java
 
b/src/test/java/org/apache/commons/crypto/jna/CbcNoPaddingCipherJnaStreamTest.java
new file mode 100644
index 0000000..98c17e1
--- /dev/null
+++ 
b/src/test/java/org/apache/commons/crypto/jna/CbcNoPaddingCipherJnaStreamTest.java
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.crypto.jna;
+
+import java.io.IOException;
+
+public class CbcNoPaddingCipherJnaStreamTest extends 
AbstractCipherJnaStreamTest {
+
+    @Override
+    public void setUp() throws IOException {
+        transformation = "AES/CBC/NoPadding";
+    }
+}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/250e9184/src/test/java/org/apache/commons/crypto/jna/CbcPkcs5PaddingCipherJnaStreamTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/commons/crypto/jna/CbcPkcs5PaddingCipherJnaStreamTest.java
 
b/src/test/java/org/apache/commons/crypto/jna/CbcPkcs5PaddingCipherJnaStreamTest.java
new file mode 100644
index 0000000..8ebc081
--- /dev/null
+++ 
b/src/test/java/org/apache/commons/crypto/jna/CbcPkcs5PaddingCipherJnaStreamTest.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.crypto.jna;
+
+import java.io.IOException;
+
+public class CbcPkcs5PaddingCipherJnaStreamTest extends 
AbstractCipherJnaStreamTest {
+
+    @Override
+    public void setUp() throws IOException {
+        transformation = "AES/CBC/PKCS5Padding";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/250e9184/src/test/java/org/apache/commons/crypto/jna/CtrCryptoJnaStreamTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/commons/crypto/jna/CtrCryptoJnaStreamTest.java 
b/src/test/java/org/apache/commons/crypto/jna/CtrCryptoJnaStreamTest.java
new file mode 100644
index 0000000..6cb39df
--- /dev/null
+++ b/src/test/java/org/apache/commons/crypto/jna/CtrCryptoJnaStreamTest.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.crypto.jna;
+
+import java.io.IOException;
+
+public class CtrCryptoJnaStreamTest extends AbstractCipherJnaStreamTest {
+
+    @Override
+    public void setUp() throws IOException {
+        transformation = "AES/CTR/NoPadding";
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/250e9184/src/test/java/org/apache/commons/crypto/jna/CtrNoPaddingCipherJnaStreamTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/commons/crypto/jna/CtrNoPaddingCipherJnaStreamTest.java
 
b/src/test/java/org/apache/commons/crypto/jna/CtrNoPaddingCipherJnaStreamTest.java
new file mode 100644
index 0000000..d615a65
--- /dev/null
+++ 
b/src/test/java/org/apache/commons/crypto/jna/CtrNoPaddingCipherJnaStreamTest.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.crypto.jna;
+
+import java.io.IOException;
+
+public class CtrNoPaddingCipherJnaStreamTest extends 
AbstractCipherJnaStreamTest {
+
+    @Override
+    public void setUp() throws IOException {
+        transformation = "AES/CTR/NoPadding";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/250e9184/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java 
b/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
index 10b28dc..79258d1 100644
--- 
a/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
+++ 
b/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
@@ -47,8 +47,8 @@ public abstract class AbstractCipherStreamTest {
     private byte[] encData;
     private Properties props = new Properties();
     protected byte[] key = new byte[16];
-    private byte[] iv = new byte[16];
-    private int count = 10000;
+    protected byte[] iv = new byte[16];
+    protected int count = 10000;
     protected static int defaultBufferSize = 8192;
     protected static int smallBufferSize = 1024;
 
@@ -71,11 +71,9 @@ public abstract class AbstractCipherStreamTest {
     public void testSkip() throws Exception {
         doSkipTest(AbstractCipherTest.JCE_CIPHER_CLASSNAME, false);
         doSkipTest(AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME, false);
-        doSkipTest(AbstractCipherTest.OPENSSLJNA_CIPHER_CLASSNAME, false);
 
         doSkipTest(AbstractCipherTest.JCE_CIPHER_CLASSNAME, true);
         doSkipTest(AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME, true);
-        doSkipTest(AbstractCipherTest.OPENSSLJNA_CIPHER_CLASSNAME, true);
     }
 
     /** Test byte buffer read with different buffer size. */
@@ -83,11 +81,9 @@ public abstract class AbstractCipherStreamTest {
     public void testByteBufferRead() throws Exception {
         doByteBufferRead(AbstractCipherTest.JCE_CIPHER_CLASSNAME, false);
         doByteBufferRead(AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME, false);
-        doByteBufferRead(AbstractCipherTest.OPENSSLJNA_CIPHER_CLASSNAME, 
false);
 
         doByteBufferRead(AbstractCipherTest.JCE_CIPHER_CLASSNAME, true);
         doByteBufferRead(AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME, true);
-        doByteBufferRead(AbstractCipherTest.OPENSSLJNA_CIPHER_CLASSNAME, true);
     }
 
     /** Test byte buffer write. */
@@ -96,14 +92,12 @@ public abstract class AbstractCipherStreamTest {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         doByteBufferWrite(AbstractCipherTest.JCE_CIPHER_CLASSNAME, baos, 
false);
         doByteBufferWrite(AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME, baos, 
false);
-        doByteBufferWrite(AbstractCipherTest.OPENSSLJNA_CIPHER_CLASSNAME, 
baos, false);
 
         doByteBufferWrite(AbstractCipherTest.JCE_CIPHER_CLASSNAME, baos, true);
         doByteBufferWrite(AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME, baos, 
true);
-        doByteBufferWrite(AbstractCipherTest.OPENSSLJNA_CIPHER_CLASSNAME, 
baos, true);
     }
 
-    private void doSkipTest(String cipherClass, boolean withChannel)
+    protected void doSkipTest(String cipherClass, boolean withChannel)
             throws IOException {
         try (InputStream in = getCryptoInputStream(
                 new ByteArrayInputStream(encData), getCipher(cipherClass),
@@ -134,7 +128,7 @@ public abstract class AbstractCipherStreamTest {
         }
     }
 
-    private void doByteBufferRead(String cipherClass, boolean withChannel)
+    protected void doByteBufferRead(String cipherClass, boolean withChannel)
             throws Exception {
         // Default buffer size, initial buffer position is 0
         InputStream in = getCryptoInputStream(
@@ -194,7 +188,7 @@ public abstract class AbstractCipherStreamTest {
         in.close();
     }
 
-    private void doByteBufferWrite(String cipherClass,
+    protected void doByteBufferWrite(String cipherClass,
             ByteArrayOutputStream baos, boolean withChannel) throws Exception {
         baos.reset();
         CryptoOutputStream out = getCryptoOutputStream(baos,
@@ -313,28 +307,21 @@ public abstract class AbstractCipherStreamTest {
     public void testReadWrite() throws Exception {
         doReadWriteTest(0, AbstractCipherTest.JCE_CIPHER_CLASSNAME, 
AbstractCipherTest.JCE_CIPHER_CLASSNAME, iv);
         doReadWriteTest(0, AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME, 
AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME, iv);
-        doReadWriteTest(0, AbstractCipherTest.OPENSSLJNA_CIPHER_CLASSNAME, 
AbstractCipherTest.OPENSSLJNA_CIPHER_CLASSNAME, iv);
         doReadWriteTest(count, AbstractCipherTest.JCE_CIPHER_CLASSNAME, 
AbstractCipherTest.JCE_CIPHER_CLASSNAME, iv);
         doReadWriteTest(count, AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME, 
AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME, iv);
-        doReadWriteTest(count, AbstractCipherTest.OPENSSLJNA_CIPHER_CLASSNAME, 
AbstractCipherTest.OPENSSLJNA_CIPHER_CLASSNAME, iv);
         doReadWriteTest(count, AbstractCipherTest.JCE_CIPHER_CLASSNAME, 
AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME, iv);
-        doReadWriteTest(count, AbstractCipherTest.JCE_CIPHER_CLASSNAME, 
AbstractCipherTest.OPENSSLJNA_CIPHER_CLASSNAME, iv);
         doReadWriteTest(count, AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME, 
AbstractCipherTest.JCE_CIPHER_CLASSNAME, iv);
-        doReadWriteTest(count, AbstractCipherTest.OPENSSLJNA_CIPHER_CLASSNAME, 
AbstractCipherTest.JCE_CIPHER_CLASSNAME, iv);
         // Overflow test, IV: xx xx xx xx xx xx xx xx ff ff ff ff ff ff ff ff
         for (int i = 0; i < 8; i++) {
             iv[8 + i] = (byte) 0xff;
         }
         doReadWriteTest(count, AbstractCipherTest.JCE_CIPHER_CLASSNAME, 
AbstractCipherTest.JCE_CIPHER_CLASSNAME, iv);
         doReadWriteTest(count, AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME, 
AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME, iv);
-        doReadWriteTest(count, AbstractCipherTest.OPENSSLJNA_CIPHER_CLASSNAME, 
AbstractCipherTest.OPENSSLJNA_CIPHER_CLASSNAME, iv);
         doReadWriteTest(count, AbstractCipherTest.JCE_CIPHER_CLASSNAME, 
AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME, iv);
-        doReadWriteTest(count, AbstractCipherTest.JCE_CIPHER_CLASSNAME, 
AbstractCipherTest.OPENSSLJNA_CIPHER_CLASSNAME, iv);
         doReadWriteTest(count, AbstractCipherTest.OPENSSL_CIPHER_CLASSNAME, 
AbstractCipherTest.JCE_CIPHER_CLASSNAME, iv);
-        doReadWriteTest(count, AbstractCipherTest.OPENSSLJNA_CIPHER_CLASSNAME, 
AbstractCipherTest.JCE_CIPHER_CLASSNAME, iv);
     }
 
-    private void doReadWriteTest(int count, String encCipherClass,
+    protected void doReadWriteTest(int count, String encCipherClass,
             String decCipherClass, byte[] iv) throws IOException {
         doReadWriteTestForInputStream(count, encCipherClass, decCipherClass, 
iv);
         doReadWriteTestForReadableByteChannel(count, encCipherClass,

Reply via email to