You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/12/13 03:01:42 UTC

[commons-crypto] branch master updated (89e9666 -> d8cd67a)

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

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


    from 89e9666  Javadoc
     new af18580  Sort members
     new 0d1bad6  Format tweaks
     new d8cd67a  Add missing test

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


Summary of changes:
 .../crypto/cipher/OpenSslGaloisCounterMode.java    |   6 +-
 .../commons/crypto/cipher/OpenSslNative.java       | 113 ++++++++++-----------
 .../commons/crypto/jna/OpenSsl11XNativeJna.java    |   2 +-
 .../OpenSslCommonModeTest.java}                    |  11 +-
 4 files changed, 66 insertions(+), 66 deletions(-)
 copy src/test/java/org/apache/commons/crypto/{jna/OpenSslJnaTest.java => cipher/OpenSslCommonModeTest.java} (74%)


[commons-crypto] 01/03: Sort members

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

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

commit af185807452179ec9e851822004f416dd3fbf704
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Dec 12 21:51:33 2022 -0500

    Sort members
---
 .../commons/crypto/cipher/OpenSslNative.java       | 112 ++++++++++-----------
 1 file changed, 56 insertions(+), 56 deletions(-)

diff --git a/src/main/java/org/apache/commons/crypto/cipher/OpenSslNative.java b/src/main/java/org/apache/commons/crypto/cipher/OpenSslNative.java
index 0b1760f..426222d 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/OpenSslNative.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/OpenSslNative.java
@@ -26,24 +26,53 @@ import java.nio.ByteBuffer;
 final class OpenSslNative {
 
     /**
-     * The private constructor of {@link OpenSslNative}.
+     * Cleans the context at native.
+     *
+     * @param context The cipher context address
      */
-    private OpenSslNative() {
-    }
+    public static native void clean(long context);
 
     /**
-     * Declares a native method to initialize JNI field and method IDs.
+     * allows various cipher specific parameters to be determined and set.
+     *
+     * it will call OpenSSL's API
+     * int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
+     * In OpenSSL, data type of ptr can be char* or long*.  Here, we map java's
+     * byte[] to native void*ptr. Note that the byte order is ByteOrder.nativeOrder.
+     *
+     * @param context The cipher context address
+     * @param type CtrlValues
+     * @param arg argument like a tag length
+     * @param data byte buffer or null
+     * @return return 0 if there is any error, else return 1.
      */
-    public static native void initIDs();
+    public static native int ctrl(long context, int type, int arg, byte[] data);
 
     /**
-     * Declares a native method to initialize the cipher context.
+     * Finishes a multiple-part operation. The data is encrypted or decrypted,
+     * depending on how this cipher was initialized.
      *
-     * @param algorithm The algorithm name of cipher
-     * @param padding The padding name of cipher
-     * @return the context address of cipher
+     * @param context The cipher context address
+     * @param output The byte buffer for the result
+     * @param offset The offset in output where the result is stored
+     * @param maxOutputLength The maximum length for output
+     * @return The number of bytes stored in output
      */
-    public static native long initContext(int algorithm, int padding);
+    public static native int doFinal(long context, ByteBuffer output,
+            int offset, int maxOutputLength);
+
+    /**
+     * Finishes a multiple-part operation. The data is encrypted or decrypted,
+     * depending on how this cipher was initialized.
+     *
+     * @param context The cipher context address
+     * @param output The byte array for the result
+     * @param offset The offset in output where the result is stored
+     * @param maxOutputLength The maximum length for output
+     * @return The number of bytes stored in output
+     */
+    public static native int doFinalByteArray(long context, byte[] output,
+            int offset, int maxOutputLength);
 
     /**
      * Declares a native method to initialize the cipher context.
@@ -59,6 +88,20 @@ final class OpenSslNative {
     public static native long init(long context, int mode, int alg,
                                    int padding, byte[] key, byte[] iv);
 
+    /**
+     * Declares a native method to initialize the cipher context.
+     *
+     * @param algorithm The algorithm name of cipher
+     * @param padding The padding name of cipher
+     * @return the context address of cipher
+     */
+    public static native long initContext(int algorithm, int padding);
+
+    /**
+     * Declares a native method to initialize JNI field and method IDs.
+     */
+    public static native void initIDs();
+
     /**
      * Continues a multiple-part encryption/decryption operation. The data is
      * encrypted or decrypted, depending on how this cipher was initialized.
@@ -110,53 +153,10 @@ final class OpenSslNative {
                                                        int inputOffset, int inputLength,
                                                        ByteBuffer output, int outputOffset, int maxOutputLength);
 
-    /**
-     * Finishes a multiple-part operation. The data is encrypted or decrypted,
-     * depending on how this cipher was initialized.
-     *
-     * @param context The cipher context address
-     * @param output The byte buffer for the result
-     * @param offset The offset in output where the result is stored
-     * @param maxOutputLength The maximum length for output
-     * @return The number of bytes stored in output
-     */
-    public static native int doFinal(long context, ByteBuffer output,
-            int offset, int maxOutputLength);
-
-    /**
-     * Finishes a multiple-part operation. The data is encrypted or decrypted,
-     * depending on how this cipher was initialized.
-     *
-     * @param context The cipher context address
-     * @param output The byte array for the result
-     * @param offset The offset in output where the result is stored
-     * @param maxOutputLength The maximum length for output
-     * @return The number of bytes stored in output
-     */
-    public static native int doFinalByteArray(long context, byte[] output,
-            int offset, int maxOutputLength);
-
-    /**
-     * allows various cipher specific parameters to be determined and set.
-     *
-     * it will call OpenSSL's API
-     * int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
-     * In OpenSSL, data type of ptr can be char* or long*.  Here, we map java's
-     * byte[] to native void*ptr. Note that the byte order is ByteOrder.nativeOrder.
-     *
-     * @param context The cipher context address
-     * @param type CtrlValues
-     * @param arg argument like a tag length
-     * @param data byte buffer or null
-     * @return return 0 if there is any error, else return 1.
-     */
-    public static native int ctrl(long context, int type, int arg, byte[] data);
-
 
     /**
-     * Cleans the context at native.
-     *
-     * @param context The cipher context address
+     * The private constructor of {@link OpenSslNative}.
      */
-    public static native void clean(long context);
+    private OpenSslNative() {
+    }
 }


[commons-crypto] 03/03: Add missing test

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

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

commit d8cd67aaac54c6d26404a6ca8cd96cac5b866cc4
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Dec 12 22:01:38 2022 -0500

    Add missing test
---
 .../crypto/cipher/OpenSslGaloisCounterMode.java    |  6 ++---
 .../crypto/cipher/OpenSslCommonModeTest.java       | 31 ++++++++++++++++++++++
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/commons/crypto/cipher/OpenSslGaloisCounterMode.java b/src/main/java/org/apache/commons/crypto/cipher/OpenSslGaloisCounterMode.java
index b637525..b07000b 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/OpenSslGaloisCounterMode.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/OpenSslGaloisCounterMode.java
@@ -270,16 +270,14 @@ final class OpenSslGaloisCounterMode extends AbstractOpenSslFeedbackCipher {
         // must be called after initialized.
         if (aadBuffer == null) {
             // update has already been called
-            throw new IllegalStateException
-                    ("Update has been called; no more AAD data");
+            throw new IllegalStateException("Update has been called; no more AAD data");
         }
         aadBuffer.write(aad, 0, aad.length);
     }
 
     private void processAAD() {
         if (aadBuffer != null && aadBuffer.size() > 0) {
-            OpenSslNative.updateByteArray(context, aadBuffer.toByteArray(),
-                    0, aadBuffer.size(), null, 0, 0);
+            OpenSslNative.updateByteArray(context, aadBuffer.toByteArray(), 0, aadBuffer.size(), null, 0, 0);
             aadBuffer = null;
         }
     }
diff --git a/src/test/java/org/apache/commons/crypto/cipher/OpenSslCommonModeTest.java b/src/test/java/org/apache/commons/crypto/cipher/OpenSslCommonModeTest.java
new file mode 100644
index 0000000..585ce5e
--- /dev/null
+++ b/src/test/java/org/apache/commons/crypto/cipher/OpenSslCommonModeTest.java
@@ -0,0 +1,31 @@
+/*
+ * 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.cipher;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.junit.jupiter.api.Test;
+
+public class OpenSslCommonModeTest {
+
+    @Test
+    public void testUpdateAAD() {
+        assertThrows(UnsupportedOperationException.class, () -> new OpenSslCommonMode(0, 0, 0).updateAAD(null));
+    }
+}


[commons-crypto] 02/03: Format tweaks

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

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

commit 0d1bad6b910cd1226316228793f93decf4b5cf2c
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Dec 12 21:53:43 2022 -0500

    Format tweaks
---
 src/main/java/org/apache/commons/crypto/cipher/OpenSslNative.java    | 1 -
 src/main/java/org/apache/commons/crypto/jna/OpenSsl11XNativeJna.java | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/crypto/cipher/OpenSslNative.java b/src/main/java/org/apache/commons/crypto/cipher/OpenSslNative.java
index 426222d..8b8a85b 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/OpenSslNative.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/OpenSslNative.java
@@ -153,7 +153,6 @@ final class OpenSslNative {
                                                        int inputOffset, int inputLength,
                                                        ByteBuffer output, int outputOffset, int maxOutputLength);
 
-
     /**
      * The private constructor of {@link OpenSslNative}.
      */
diff --git a/src/main/java/org/apache/commons/crypto/jna/OpenSsl11XNativeJna.java b/src/main/java/org/apache/commons/crypto/jna/OpenSsl11XNativeJna.java
index 1d4fa88..b9ca5bd 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSsl11XNativeJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSsl11XNativeJna.java
@@ -60,8 +60,8 @@ final class OpenSsl11XNativeJna  implements OpenSslInterfaceNativeJna {
      * @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 OpenSSL_version(int type);
 
-     public static native String OpenSSL_version(int type);
     /**
      * @return the earliest error code from the thread's error queue without modifying it.
      */