Bump actions/setup-java from 3 to 3.5.1 master
authorGary Gregory <garydgregory@gmail.com>
Sat, 1 Oct 2022 18:36:12 +0000 (14:36 -0400)
committerGary Gregory <garydgregory@gmail.com>
Sat, 1 Oct 2022 18:36:12 +0000 (14:36 -0400)
30 files changed:
.github/workflows/adhoctest.yml
.github/workflows/codeql-analysis.yml
.github/workflows/coverage.yml
.github/workflows/maven.yml
.github/workflows/scorecards-analysis.yml [new file with mode: 0644]
CONTRIBUTING.md
README.md
pom.xml
src/changes/changes.xml
src/main/java/org/apache/commons/crypto/NativeCodeLoader.java
src/main/java/org/apache/commons/crypto/OsInfo.java
src/main/java/org/apache/commons/crypto/cipher/OpenSslCommonMode.java
src/main/java/org/apache/commons/crypto/cipher/OpenSslGaloisCounterMode.java
src/main/java/org/apache/commons/crypto/jna/OpenSsl10XNativeJna.java
src/main/java/org/apache/commons/crypto/jna/OpenSsl11XNativeJna.java
src/main/java/org/apache/commons/crypto/jna/OpenSsl20XNativeJna.java
src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
src/main/java/org/apache/commons/crypto/random/JavaCryptoRandom.java
src/main/java/org/apache/commons/crypto/random/OpenSslCryptoRandom.java
src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
src/main/java/org/apache/commons/crypto/stream/CtrCryptoInputStream.java
src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java
src/main/java/org/apache/commons/crypto/stream/input/StreamInput.java
src/main/java/org/apache/commons/crypto/utils/ReflectionUtils.java
src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
src/test/java/org/apache/commons/crypto/cipher/GcmCipherTest.java
src/test/java/org/apache/commons/crypto/jna/OpenSslNativeJnaTest.java
src/test/java/org/apache/commons/crypto/random/JavaCryptoRandomTest.java
src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java

index b804f824966ecbc3bff86fa45278bdf18a32e1e2..282fe5a8081e29227a700d3ad14d7c0dc8f23c14 100644 (file)
@@ -46,11 +46,11 @@ jobs:
       fail-fast: false
 
     steps:
-    # - uses: actions/checkout@v3
+    # - uses: actions/checkout@v3.0.2
     #   with:
     #     ref: ${{ matrix.ref }}
     # - name: Set up JDK ${{ matrix.java }}
-    #   uses: actions/setup-java@v3
+    #   uses: actions/setup-java@v3.5.1
     #   with:
     #     distribution: 'temurin'
     #     java-version: ${{ matrix.java }}
index d687f207c8084f775cd439cbd556d6f9df9553da..e27f728650d8bfc9a76899d71d4d47cca10656de 100644 (file)
@@ -49,14 +49,20 @@ jobs:
 
     steps:
     - name: Checkout repository
-      uses: actions/checkout@v3
+      uses: actions/checkout@v3.0.2
+    - uses: actions/cache@v3.0.9
+      with:
+        path: ~/.m2/repository
+        key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
+        restore-keys: |
+          ${{ runner.os }}-maven-
 
     # Override Java default
     # Java 11 complains about illegal access; drop this override when sorted
     # Also complains: "Corrupted channel by directly writing to native stream in forked JVM 1"
     - name: Set up JDK ${{ matrix.java }}
       if: ${{ matrix.language == 'java' }}
-      uses: actions/setup-java@v3
+      uses: actions/setup-java@v3.5.1
       with:
         distribution: 'temurin'
         java-version: ${{ matrix.java }}
index e39f5f62bf54231b055f2b7a7ded25d9fb80048f..960d2a53411d334fd382048060d3b20a92a83828 100644 (file)
@@ -37,15 +37,15 @@ jobs:
         java: [ 8 ]
 
     steps:
-    - uses: actions/checkout@v3
-    - uses: actions/cache@v3.0.6
+    - uses: actions/checkout@v3.0.2
+    - uses: actions/cache@v3.0.9
       with:
         path: ~/.m2/repository
         key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
         restore-keys: |
           ${{ runner.os }}-maven-
     - name: Set up JDK ${{ matrix.java }}
-      uses: actions/setup-java@v3
+      uses: actions/setup-java@v3.5.1
       with:
         distribution: 'temurin'
         java-version: ${{ matrix.java }}
index 40b5f4442df552b1d6d5577afe933c8d56af476f..cf7d9c64ed1523565f7cee7656d63ba32268a26e 100644 (file)
@@ -48,15 +48,15 @@ jobs:
       fail-fast: false
         
     steps:
-    - uses: actions/checkout@v3
-    - uses: actions/cache@v3.0.6
+    - uses: actions/checkout@v3.0.2
+    - uses: actions/cache@v3.0.9
       with:
         path: ~/.m2/repository
         key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
         restore-keys: |
           ${{ runner.os }}-maven-
     - name: Set up JDK ${{ matrix.java }}
-      uses: actions/setup-java@v3
+      uses: actions/setup-java@v3.5.1
       with:
         distribution: 'temurin'
         java-version: ${{ matrix.java }}
diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml
new file mode 100644 (file)
index 0000000..abd6992
--- /dev/null
@@ -0,0 +1,67 @@
+# 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.
+
+name: "Scorecards supply-chain security"
+
+on:
+  branch_protection_rule:
+  schedule:
+    - cron: "30 1 * * 6"    # Weekly on Saturdays
+  push:
+    branches: [ "master" ]
+
+permissions: read-all
+
+jobs:
+
+  analysis:
+
+    name: "Scorecards analysis"
+    runs-on: ubuntu-latest
+    permissions:
+      security-events: write    # Needed to upload the results to the code-scanning dashboard.
+      actions: read
+      contents: read
+
+    steps:
+
+      - name: "Checkout code"
+        uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b   # 3.0.2
+        with:
+          persist-credentials: false
+
+      - name: "Run analysis"
+        uses: ossf/scorecard-action@ce330fde6b1a5c9c75b417e7efc510b822a35564    # 1.1.2
+        with:
+          results_file: results.sarif
+          results_format: sarif
+          # A read-only PAT token, which is sufficient for the action to function.
+          # The relevant discussion: https://github.com/ossf/scorecard-action/issues/188
+          repo_token: ${{ secrets.GITHUB_TOKEN }}
+          # Publish the results for public repositories to enable scorecard badges.
+          # For more details: https://github.com/ossf/scorecard-action#publishing-results
+          publish_results: true
+
+      - name: "Upload artifact"
+        uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8    # 3.1.0
+        with:
+          name: SARIF file
+          path: results.sarif
+          retention-days: 5
+
+      - name: "Upload to code-scanning"
+        uses: github/codeql-action/upload-sarif@b398f525a5587552e573b247ac661067fafa920b    # 2.1.22
+        with:
+          sarif_file: results.sarif
index 3a5e3e052d5f40af9beaf79aa1a6cb31170b5ad4..75c4be0007679c06084dbff71617fa03ee1ddaf6 100644 (file)
@@ -61,7 +61,7 @@ Making Changes
 --------------
 
 + Create a _topic branch_ for your isolated work.
-  * Usually you should base your branch on the `master` or `trunk` branch.
+  * Usually you should base your branch on the `master` branch.
   * A good topic branch name can be the JIRA bug id plus a keyword, e.g. `CRYPTO-123-InputStream`.
   * If you have submitted multiple JIRA issues, try to maintain separate branches and pull requests.
 + Make commits of logical units.
index 2acbe4852b14e4e53e317c6c1b9584c256e30c2e..b5d28954133a50fab511a08f7ce554c049895bcc 100644 (file)
--- a/README.md
+++ b/README.md
@@ -44,9 +44,10 @@ Apache Commons Crypto
 ===================
 
 [![Build Status](https://travis-ci.org/apache/commons-crypto.svg)](https://travis-ci.org/apache/commons-crypto)
-[![Coverage Status](https://coveralls.io/repos/apache/commons-crypto/badge.svg)](https://coveralls.io/r/apache/commons-crypto)
-[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-crypto/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-crypto/)
+[![Coverage Status](https://codecov.io/gh/apache/commons-crypto/branch/master/graph/badge.svg)](https://app.codecov.io/gh/apache/commons-crypto/branch/master)
+[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-crypto/badge.svg?gav=true)](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-crypto/?gav=true)
 [![Javadocs](https://javadoc.io/badge/org.apache.commons/commons-crypto/1.1.0.svg)](https://javadoc.io/doc/org.apache.commons/commons-crypto/1.1.0)
+[![CodeQL](https://github.com/apache/commons-crypto/workflows/CodeQL/badge.svg)](https://github.com/apache/commons-crypto/actions/workflows/codeql-analysis.yml?query=workflow%3ACodeQL)
 
 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.
diff --git a/pom.xml b/pom.xml
index 73086092b6d05f7cbf6a93c1d447bb7d3e87e594..297820280188139feb8abd1573e5c9b8c57b23c3 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -18,7 +18,7 @@
   <parent>
     <groupId>org.apache.commons</groupId>
     <artifactId>commons-parent</artifactId>
-    <version>53</version>
+    <version>54</version>
   </parent>
 
   <artifactId>commons-crypto</artifactId>
@@ -139,25 +139,24 @@ The following provides more details on the included cryptographic software:
     <!-- This is used by reporting plugins -->
     <project.reporting.outputEncoding>${commons.encoding}</project.reporting.outputEncoding>
 
-    <checkstyle.version>3.1.2</checkstyle.version>
+    <checkstyle.version>3.2.0</checkstyle.version>
     <checkstyle.header.file>${basedir}/LICENSE-header.txt</checkstyle.header.file>
     <checkstyle.resourceExcludes>LICENSE.txt, NOTICE.txt, **/maven-archiver/pom.properties</checkstyle.resourceExcludes>
 
-    <commons.pmd.version>3.16.0</commons.pmd.version>
-    <commons.javadoc.version>3.4.0</commons.javadoc.version>
+    <commons.pmd.version>3.19.0</commons.pmd.version>
+    <commons.pmd-impl.version>6.48.0</commons.pmd-impl.version>
+    <commons.javadoc.version>3.4.1</commons.javadoc.version>
     <japicmp.skip>false</japicmp.skip>
-    <commons.japicmp.version>0.15.7</commons.japicmp.version>
-    <commons.spotbugs.version>4.7.1.1</commons.spotbugs.version>
+    <commons.japicmp.version>0.16.0</commons.japicmp.version>
+    <commons.spotbugs.version>4.7.2.0</commons.spotbugs.version>
     <!-- commons.animal-sniffer.version 1.21 fails on Java 17. -->
     <commons.animal-sniffer.version>1.20</commons.animal-sniffer.version>
     
-    <clirr.skip>true</clirr.skip>
-    
     <commons.release.isDistModule>true</commons.release.isDistModule>
     <commons.releaseManagerName>Gary Gregory</commons.releaseManagerName>    
     <commons.releaseManagerKey>86fdc7e2a11262cb</commons.releaseManagerKey>
   
-    <jna.version>5.11.0</jna.version>
+    <jna.version>5.12.1</jna.version>
     <commons.jacoco.version>0.8.8</commons.jacoco.version>
 
     <!-- The property "target.name" is used to specify the ant target, The All target will use
@@ -165,7 +164,7 @@ The following provides more details on the included cryptographic software:
     User is able to specify the platform by maven profiles.-->
     <target.name>all</target.name>
     <maven-antrun-plugin.version>3.1.0</maven-antrun-plugin.version>
-    <junit.version>5.9.0</junit.version>
+    <junit.version>5.9.1</junit.version>
     <commons.surefire.version>3.0.0-M7</commons.surefire.version>
 
     <!-- Override default buildNumber timestamp format, needed for coveralls plugin -->
@@ -463,7 +462,7 @@ The following provides more details on the included cryptographic software:
   </profiles>
 
   <build>
-    <defaultGoal>clean apache-rat:check install japicmp:cmp spotbugs:check pmd:check javadoc:javadoc</defaultGoal>
+    <defaultGoal>clean apache-rat:check install japicmp:cmp spotbugs:check pmd:check checkstyle:check javadoc:javadoc</defaultGoal>
     <resources>
       <resource>
         <directory>src/main/resources/</directory>
index 18310f3b973c928876458b7080d34d8ce1881286..e7e5a8ae2815d63055d7d45836e2475d5f035dcd 100644 (file)
       <action                    type="fix" dev="ggregory" due-to="Gary Gregory">Port from pre-Java 8 javah tool to Java 8 and up javac with the -h option.</action>
       <action                    type="fix" dev="ggregory" due-to="Gary Gregory">Fix build on Java 11.</action>
       <action                    type="fix" dev="ggregory" due-to="Gary Gregory">Fix build on Java 17.</action>
+      <action issue="CRYPTO-155" type="fix" due-to="Arturo Bernal">Minor improvement #115, #125.</action>
       <!-- ADD -->
       <action                    type="fix" dev="ggregory" due-to="Gary Gregory, Dependabot">Add github/codeql-action 2 #159.</action>
       <!-- UPDATE -->
-      <action                    type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump actions/cache from 2.1.7 to 3.0.6 #150.</action>
-      <action                    type="update" dev="ggregory" due-to="Dependabot">Bump actions/checkout from 2 to 3 #149.</action>
-      <action                    type="update" dev="ggregory" due-to="Gary Gregory">Bump actions/setup-java from 2 to 3.</action>
-      <action issue="CRYPTO-155" type="update" due-to="Arturo Bernal">Minor improvement #115, #125.</action>
-      <action issue="CRYPTO-151" type="update" due-to="Arturo Bernal, Dependabot">Migrate to Junit 5.9.0 #114, #171.</action>
-      <action                    type="update" dev="ggregory" due-to="Dependabot">Bump jna from 5.5.0 to 5.11.0 #123, #139, #153.</action>
-      <action                    type="update" dev="ggregory" due-to="Gary Gregory">Bump commons.japicmp.version from 0.14.3 to 0.15.7.</action>
-      <action                    type="update" dev="ggregory" due-to="Dependabot">Bump maven-checkstyle-plugin from 3.1.1 to 3.1.2 #130.</action>
+      <action                    type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump actions/cache from 2.1.7 to 3.0.9 #150, #184.</action>
+      <action                    type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump actions/checkout from 2 to 3.0.2 #149.</action>
+      <action                    type="update" dev="ggregory" due-to="Gary Gregory">Bump actions/setup-java from 2 to 3.5.1.</action>
+      <action issue="CRYPTO-151" type="update" due-to="Arturo Bernal, Dependabot">Migrate to Junit 5.9.1 #114, #171, #183.</action>
+      <action                    type="update" dev="ggregory" due-to="Dependabot">Bump jna from 5.5.0 to 5.12.1 #123, #139, #153, #167.</action>
+      <action                    type="update" dev="ggregory" due-to="Gary Gregory">Bump commons.japicmp.version from 0.14.3 to 0.16.0.</action>
+      <action                    type="update" dev="ggregory" due-to="Dependabot">Bump maven-checkstyle-plugin from 3.1.1 to 3.2.0 #130, #176.</action>
       <action                    type="update" dev="ggregory" due-to="Dependabot">Bump jmh.version from 1.12 to 1.35 #119, #157.</action>
       <action                    type="update" dev="ggregory" due-to="Dependabot">Bump exec-maven-plugin from 1.6.0 to 3.1.0 #121, #170.</action>
       <action                    type="update" dev="ggregory" due-to="Dependabot">Bump maven-antrun-plugin from 1.8 to 3.1.0 #120, #158.</action>
       <action                    type="update" dev="ggregory" due-to="Gary Gregory">Bump commons.japicmp.version from 0.15.2 to 0.15.7 #138.</action>
       <action                    type="update" dev="ggregory" due-to="Gary Gregory">Bump jacoco-maven-plugin from 0.6.6 to 0.8.8 #138, #154.</action>
-      <action                    type="update" dev="ggregory" due-to="Gary Gregory">Bump commons.javadoc.version from 3.2.0 to 3.4.0 #138.</action>
-      <action                    type="update" dev="ggregory" due-to="Gary Gregory">Bump maven-pmd-plugin from 3.14.0 to 3.16.0 #140.</action>
+      <action                    type="update" dev="ggregory" due-to="Gary Gregory">Bump maven-javadoc-plugin from 3.2.0 to 3.4.1 #138.</action>
+      <action                    type="update" dev="ggregory" due-to="Gary Gregory">Bump maven-pmd-plugin from 3.14.0 to 3.19.0 #140, #177, #178.</action>
+      <action                    type="update" dev="ggregory" due-to="Gary Gregory">Bump pmd from 6.44.0 to 6.48.0.</action>
       <action                    type="update" dev="ggregory" due-to="Dependabot">Bump taglist-maven-plugin from 2.4 to 3.0.0 #147.</action>
-      <action                    type="update" dev="ggregory" due-to="Dependabot">Bump spotbugs-maven-plugin from 4.5.3.0 to 4.7.1.1 #152, #160, #168, #174.</action>
-      <action                    type="update" dev="ggregory" due-to="Gary Gregory">Bump commons-parent from 52 to 53.</action>
+      <action                    type="update" dev="ggregory" due-to="Dependabot">Bump spotbugs-maven-plugin from 4.5.3.0 to 4.7.2.0 #152, #160, #168, #174, #179.</action>
+      <action                    type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump commons-parent from 52 to 54 #182</action>
       <action                    type="update" dev="ggregory" due-to="Gary Gregory">Bump commons.surefire.version from 3.0.0-M5 to 3.0.0-M7.</action>
       <action                    type="update" dev="ggregory" due-to="Dependabot">Bump maven-resources-plugin from 3.2.0 to 3.3.0 #172.</action>
     </release>
index 0ed1fd27980bf721c019aee8b7ddefe39d9f9eca..280834569a44a2be0815936fec49ad00815253ff 100644 (file)
@@ -58,12 +58,14 @@ final class NativeCodeLoader {
     /**
      * Returns the given InputStream if it is already a {@link BufferedInputStream},
      * otherwise creates a BufferedInputStream from the given InputStream.
+     * <p>
+     * Copied from Apache Commons IO 2.5.
+     * </p>
      *
      * @param inputStream the InputStream to wrap or return (not null)
      * @return the given InputStream or a new {@link BufferedInputStream} for the
      *         given InputStream
      * @throws NullPointerException if the input parameter is null
-     * @since Apache Commons IO 2.5
      */
     @SuppressWarnings("resource")
     private static BufferedInputStream buffer(final InputStream inputStream) {
@@ -76,12 +78,14 @@ final class NativeCodeLoader {
 
     /**
      * Checks whether in1 and in2 is equal.
+     * <p>
+     * Copied from Apache Commons IO 2.5.
+     * </p>
      *
      * @param input1 the input1.
      * @param input2 the input2.
      * @return true if in1 and in2 is equal, else false.
      * @throws IOException if an I/O error occurs.
-     * @since Apache Commons IO 2.5
      */
     @SuppressWarnings("resource")
     private static boolean contentsEquals(final InputStream input1, final InputStream input2) throws IOException {
index cd129380057847e8e08c5054db6683ab94f3c8aa..d5b23cf067dfbb2c26ff406b80094c0f1ec74f26 100644 (file)
@@ -118,7 +118,8 @@ final class OsInfo {
             if ("--os".equals(args[0])) {
                 System.out.print(getOSName());
                 return;
-            } else if ("--arch".equals(args[0])) {
+            }
+            if ("--arch".equals(args[0])) {
                 System.out.print(getArchName());
                 return;
             }
@@ -185,15 +186,17 @@ final class OsInfo {
     private static String translateOSNameToFolderName(final String osName) {
         if (osName.contains("Windows")) {
             return "Windows";
-        } else if (osName.contains("Mac")) {
+        }
+        if (osName.contains("Mac")) {
             return "Mac";
-        } else if (osName.contains("Linux")) {
+        }
+        if (osName.contains("Linux")) {
             return "Linux";
-        } else if (osName.contains("AIX")) {
+        }
+        if (osName.contains("AIX")) {
             return "AIX";
-        } else {
-            return osName.replaceAll("\\W", "");
         }
+        return osName.replaceAll("\\W", "");
     }
 
     /**
index 6ca17bb90a91561b3bd23a2fbe163c7fc494dfb8..4102b6ec6795b70dda5f7e1f07c8b60f2a6e81a7 100644 (file)
@@ -42,12 +42,11 @@ class OpenSslCommonMode extends OpenSslFeedbackCipher {
             throws InvalidAlgorithmParameterException {
         this.cipherMode = mode;
         final byte[] iv;
-        if (params instanceof IvParameterSpec) {
-            iv = ((IvParameterSpec) params).getIV();
-        } else {
+        if (!(params instanceof IvParameterSpec)) {
             // other AlgorithmParameterSpec is not supported now.
             throw new InvalidAlgorithmParameterException("Illegal parameters");
         }
+        iv = ((IvParameterSpec) params).getIV();
         context = OpenSslNative.init(context, mode, algorithmMode, padding, key, iv);
     }
 
index 79950edafc4cf12e71ce8144a13373a79819f705..9abe02e81ab3824fa1db2c22db63dafdaf804312 100644 (file)
@@ -63,14 +63,13 @@ class OpenSslGaloisCounterMode extends OpenSslFeedbackCipher {
 
         this.cipherMode = mode;
         final byte[] iv;
-        if (params instanceof GCMParameterSpec) {
-            final GCMParameterSpec gcmParam = (GCMParameterSpec) params;
-            iv = gcmParam.getIV();
-            this.tagBitLen = gcmParam.getTLen();
-        } else {
+        if (!(params instanceof GCMParameterSpec)) {
             // other AlgorithmParameterSpec is not supported now.
             throw new InvalidAlgorithmParameterException("Illegal parameters");
         }
+        final GCMParameterSpec gcmParam = (GCMParameterSpec) params;
+        iv = gcmParam.getIV();
+        this.tagBitLen = gcmParam.getTLen();
 
         if (this.cipherMode == OpenSsl.DECRYPT_MODE) {
             inBuffer = new ByteArrayOutputStream();
@@ -212,7 +211,6 @@ class OpenSslGaloisCounterMode extends OpenSslFeedbackCipher {
 
                 // retrieve tag
                 tag.put(inputFinal, inputFinal.length - getTagLen(), getTagLen());
-                tag.flip();
 
             } else {
                 // if no buffered input, just use the input directly
@@ -228,8 +226,8 @@ class OpenSslGaloisCounterMode extends OpenSslFeedbackCipher {
 
                 // retrieve tag
                 tag.put(input);
-                tag.flip();
             }
+            tag.flip();
 
             // set tag to EVP_Cipher for integrity verification in doFinal
             evpCipherCtxCtrl(context, OpenSslEvpCtrlValues.AEAD_SET_TAG.getValue(),
@@ -270,13 +268,12 @@ class OpenSslGaloisCounterMode extends OpenSslFeedbackCipher {
     @Override
     public void updateAAD(final byte[] aad) {
         // must be called after initialized.
-        if (aadBuffer != null) {
-            aadBuffer.write(aad, 0, aad.length);
-        } else {
+        if (aadBuffer == null) {
             // update has already been called
             throw new IllegalStateException
                     ("Update has been called; no more AAD data");
         }
+        aadBuffer.write(aad, 0, aad.length);
     }
 
     private void processAAD() {
index af68e104ba4c2e5f0e55f56ccd8bce1cd913a07c..2a2d6ba53e77cb38d3e81215a094422aece83d15 100644 (file)
@@ -313,117 +313,145 @@ class OpenSsl10XNativeJna implements OpenSslInterfaceNativeJna {
 
     // ================== instance interface methods ==================
 
+    @Override
     public boolean _INIT_OK() {
         return INIT_OK;
     }
 
+    @Override
     public Throwable _INIT_ERROR() {
         return INIT_ERROR;
     }
 
-    public PointerByReference _ENGINE_by_id(String string) {
+    @Override
+    public PointerByReference _ENGINE_by_id(final String string) {
         return ENGINE_by_id(string);
     }
 
-    public int _ENGINE_finish(PointerByReference rdrandEngine) {
+    @Override
+    public int _ENGINE_finish(final PointerByReference rdrandEngine) {
         return ENGINE_finish(rdrandEngine);
     }
 
-    public int _ENGINE_free(PointerByReference rdrandEngine) {
+    @Override
+    public int _ENGINE_free(final PointerByReference rdrandEngine) {
         return ENGINE_free(rdrandEngine);
     }
 
-    public int _ENGINE_init(PointerByReference rdrandEngine) {
+    @Override
+    public int _ENGINE_init(final PointerByReference rdrandEngine) {
         return ENGINE_init(rdrandEngine);
     }
 
-    public int _ENGINE_set_default(PointerByReference rdrandEngine, int flags) {
+    @Override
+    public int _ENGINE_set_default(final PointerByReference rdrandEngine, final int flags) {
         return ENGINE_set_default(rdrandEngine, flags);
     }
 
-    public String _ERR_error_string(NativeLong err, char[] buff) {
+    @Override
+    public String _ERR_error_string(final NativeLong err, final char[] buff) {
         return ERR_error_string(err, buff);
     }
 
+    @Override
     public NativeLong _ERR_peek_error() {
         return ERR_peek_error();
     }
 
+    @Override
     public PointerByReference _EVP_aes_128_cbc() {
         return EVP_aes_128_cbc();
     }
 
+    @Override
     public PointerByReference _EVP_aes_128_ctr() {
         return EVP_aes_128_ctr();
     }
 
+    @Override
     public PointerByReference _EVP_aes_192_cbc() {
         return EVP_aes_192_cbc();
     }
 
+    @Override
     public PointerByReference _EVP_aes_192_ctr() {
         return EVP_aes_192_ctr();
     }
 
+    @Override
     public PointerByReference _EVP_aes_256_cbc() {
         return EVP_aes_256_cbc();
     }
 
+    @Override
     public PointerByReference _EVP_aes_256_ctr() {
         return EVP_aes_256_ctr();
     }
 
-    public void _EVP_CIPHER_CTX_free(PointerByReference context) {
+    @Override
+    public void _EVP_CIPHER_CTX_free(final PointerByReference context) {
         EVP_CIPHER_CTX_free(context);
     }
 
+    @Override
     public PointerByReference _EVP_CIPHER_CTX_new() {
         return EVP_CIPHER_CTX_new();
     }
 
-    public int _EVP_CIPHER_CTX_set_padding(PointerByReference context, int padding) {
+    @Override
+    public int _EVP_CIPHER_CTX_set_padding(final PointerByReference context, final int padding) {
         return EVP_CIPHER_CTX_set_padding(context, padding);
     }
 
-    public int _EVP_CipherFinal_ex(PointerByReference context, ByteBuffer outBuffer, int[] outlen) {
+    @Override
+    public int _EVP_CipherFinal_ex(final PointerByReference context, final ByteBuffer outBuffer, final int[] outlen) {
         return EVP_CipherFinal_ex(context, outBuffer, outlen);
     }
 
-    public int _EVP_CipherInit_ex(PointerByReference context, PointerByReference algo, PointerByReference impl, byte[] encoded,
-            byte[] iv, int cipherMode) {
+    @Override
+    public int _EVP_CipherInit_ex(final PointerByReference context, final PointerByReference algo, final PointerByReference impl, final byte[] encoded,
+            final byte[] iv, final int cipherMode) {
         return EVP_CipherInit_ex(context, algo, impl, encoded, iv, cipherMode);
     }
 
-    public int _EVP_CipherUpdate(PointerByReference context, ByteBuffer outBuffer, int[] outlen, ByteBuffer inBuffer,
-            int remaining) {
+    @Override
+    public int _EVP_CipherUpdate(final PointerByReference context, final ByteBuffer outBuffer, final int[] outlen, final ByteBuffer inBuffer,
+            final int remaining) {
         return EVP_CipherUpdate(context, outBuffer, outlen, inBuffer, remaining);
     }
 
-    public int _RAND_bytes(ByteBuffer buf, int length) {
+    @Override
+    public int _RAND_bytes(final ByteBuffer buf, final int length) {
         return RAND_bytes(buf, length) ;
     }
 
+    @Override
     public PointerByReference _RAND_get_rand_method() {
         return RAND_get_rand_method();
     }
 
+    @Override
     public PointerByReference _RAND_SSLeay() {
         return RAND_SSLeay();
     }
 
-    public String _OpenSSL_version(int i) {
+    @Override
+    public String _OpenSSL_version(final int i) {
         return SSLeay_version(i);
     }
 
+    @Override
     public void _ENGINE_load_rdrand() {
         ENGINE_load_rdrand();
     }
 
+    @Override
     public int _ENGINE_cleanup() {
         return ENGINE_cleanup();
     }
 
-    public void _EVP_CIPHER_CTX_cleanup(PointerByReference context) {
+    @Override
+    public void _EVP_CIPHER_CTX_cleanup(final PointerByReference context) {
         EVP_CIPHER_CTX_cleanup(context);
     }
 }
index ed24c91c6db2559b14492557fac35fcfe62d6cdf..adf023ed225c012b54157d7e37f2405dbf691ff9 100644 (file)
@@ -269,117 +269,145 @@ class OpenSsl11XNativeJna  implements OpenSslInterfaceNativeJna {
 
     // ================== instance interface methods ==================
 
+    @Override
     public boolean _INIT_OK() {
         return INIT_OK;
     }
 
+    @Override
     public Throwable _INIT_ERROR() {
         return INIT_ERROR;
     }
 
-    public PointerByReference _ENGINE_by_id(String string) {
+    @Override
+    public PointerByReference _ENGINE_by_id(final String string) {
         return ENGINE_by_id(string);
     }
 
-    public int _ENGINE_finish(PointerByReference rdrandEngine) {
+    @Override
+    public int _ENGINE_finish(final PointerByReference rdrandEngine) {
         return ENGINE_finish(rdrandEngine);
     }
 
-    public int _ENGINE_free(PointerByReference rdrandEngine) {
+    @Override
+    public int _ENGINE_free(final PointerByReference rdrandEngine) {
         return ENGINE_free(rdrandEngine);
     }
 
-    public int _ENGINE_init(PointerByReference rdrandEngine) {
+    @Override
+    public int _ENGINE_init(final PointerByReference rdrandEngine) {
         return ENGINE_init(rdrandEngine);
     }
 
-    public int _ENGINE_set_default(PointerByReference rdrandEngine, int flags) {
+    @Override
+    public int _ENGINE_set_default(final PointerByReference rdrandEngine, final int flags) {
         return ENGINE_set_default(rdrandEngine, flags);
     }
 
-    public String _ERR_error_string(NativeLong err, char[] buff) {
+    @Override
+    public String _ERR_error_string(final NativeLong err, final char[] buff) {
         return ERR_error_string(err, buff);
     }
 
+    @Override
     public NativeLong _ERR_peek_error() {
         return ERR_peek_error();
     }
 
+    @Override
     public PointerByReference _EVP_aes_128_cbc() {
         return EVP_aes_128_cbc();
     }
 
+    @Override
     public PointerByReference _EVP_aes_128_ctr() {
         return EVP_aes_128_ctr();
     }
 
+    @Override
     public PointerByReference _EVP_aes_192_cbc() {
         return EVP_aes_192_cbc();
     }
 
+    @Override
     public PointerByReference _EVP_aes_192_ctr() {
         return EVP_aes_192_ctr();
     }
 
+    @Override
     public PointerByReference _EVP_aes_256_cbc() {
         return EVP_aes_256_cbc();
     }
 
+    @Override
     public PointerByReference _EVP_aes_256_ctr() {
         return EVP_aes_256_ctr();
     }
 
-    public void _EVP_CIPHER_CTX_free(PointerByReference context) {
+    @Override
+    public void _EVP_CIPHER_CTX_free(final PointerByReference context) {
         EVP_CIPHER_CTX_free(context);
     }
 
+    @Override
     public PointerByReference _EVP_CIPHER_CTX_new() {
         return EVP_CIPHER_CTX_new();
     }
 
-    public int _EVP_CIPHER_CTX_set_padding(PointerByReference context, int padding) {
+    @Override
+    public int _EVP_CIPHER_CTX_set_padding(final PointerByReference context, final int padding) {
         return EVP_CIPHER_CTX_set_padding(context, padding);
     }
 
-    public int _EVP_CipherFinal_ex(PointerByReference context, ByteBuffer outBuffer, int[] outlen) {
+    @Override
+    public int _EVP_CipherFinal_ex(final PointerByReference context, final ByteBuffer outBuffer, final int[] outlen) {
         return EVP_CipherFinal_ex(context, outBuffer, outlen);
     }
 
-    public int _EVP_CipherInit_ex(PointerByReference context, PointerByReference algo, PointerByReference impl, byte[] encoded,
-            byte[] iv, int cipherMode) {
+    @Override
+    public int _EVP_CipherInit_ex(final PointerByReference context, final PointerByReference algo, final PointerByReference impl, final byte[] encoded,
+            final byte[] iv, final int cipherMode) {
         return EVP_CipherInit_ex(context, algo, impl, encoded, iv, cipherMode);
     }
 
-    public int _EVP_CipherUpdate(PointerByReference context, ByteBuffer outBuffer, int[] outlen, ByteBuffer inBuffer,
-            int remaining) {
+    @Override
+    public int _EVP_CipherUpdate(final PointerByReference context, final ByteBuffer outBuffer, final int[] outlen, final ByteBuffer inBuffer,
+            final int remaining) {
         return EVP_CipherUpdate(context, outBuffer, outlen, inBuffer, remaining);
     }
 
-    public int _RAND_bytes(ByteBuffer buf, int length) {
+    @Override
+    public int _RAND_bytes(final ByteBuffer buf, final int length) {
         return RAND_bytes(buf, length) ;
     }
 
+    @Override
     public PointerByReference _RAND_get_rand_method() {
         return RAND_get_rand_method();
     }
 
+    @Override
     public PointerByReference _RAND_SSLeay() {
         return null; // Not available
     }
 
-    public String _OpenSSL_version(int i) {
+    @Override
+    public String _OpenSSL_version(final int i) {
         return OpenSSL_version(i);
     }
 
+    @Override
     public void _ENGINE_load_rdrand() {
         // Not available
     }
 
+    @Override
     public int _ENGINE_cleanup() {
         return 0; // Not available
     }
 
-    public void _EVP_CIPHER_CTX_cleanup(PointerByReference context) {
+    @Override
+    public void _EVP_CIPHER_CTX_cleanup(final PointerByReference context) {
         // Not available
     }
 
index 633e58d2655c08f4815c9d9b8cb169bf8ef862d3..ae1cb49cb76f2c144d1205350b41b53f9251c348 100644 (file)
@@ -304,117 +304,145 @@ class OpenSsl20XNativeJna implements OpenSslInterfaceNativeJna {
 
     // ================== instance interface methods ==================
 
+    @Override
     public boolean _INIT_OK() {
         return INIT_OK;
     }
 
+    @Override
     public Throwable _INIT_ERROR() {
         return INIT_ERROR;
     }
 
-    public PointerByReference _ENGINE_by_id(String string) {
+    @Override
+    public PointerByReference _ENGINE_by_id(final String string) {
         return ENGINE_by_id(string);
     }
 
-    public int _ENGINE_finish(PointerByReference rdrandEngine) {
+    @Override
+    public int _ENGINE_finish(final PointerByReference rdrandEngine) {
         return ENGINE_finish(rdrandEngine);
     }
 
-    public int _ENGINE_free(PointerByReference rdrandEngine) {
+    @Override
+    public int _ENGINE_free(final PointerByReference rdrandEngine) {
         return ENGINE_free(rdrandEngine);
     }
 
-    public int _ENGINE_init(PointerByReference rdrandEngine) {
+    @Override
+    public int _ENGINE_init(final PointerByReference rdrandEngine) {
         return ENGINE_init(rdrandEngine);
     }
 
-    public int _ENGINE_set_default(PointerByReference rdrandEngine, int flags) {
+    @Override
+    public int _ENGINE_set_default(final PointerByReference rdrandEngine, final int flags) {
         return ENGINE_set_default(rdrandEngine, flags);
     }
 
-    public String _ERR_error_string(NativeLong err, char[] buff) {
+    @Override
+    public String _ERR_error_string(final NativeLong err, final char[] buff) {
         return ERR_error_string(err, buff);
     }
 
+    @Override
     public NativeLong _ERR_peek_error() {
         return ERR_peek_error();
     }
 
+    @Override
     public PointerByReference _EVP_aes_128_cbc() {
         return EVP_aes_128_cbc();
     }
 
+    @Override
     public PointerByReference _EVP_aes_128_ctr() {
         return EVP_aes_128_ctr();
     }
 
+    @Override
     public PointerByReference _EVP_aes_192_cbc() {
         return EVP_aes_192_cbc();
     }
 
+    @Override
     public PointerByReference _EVP_aes_192_ctr() {
         return EVP_aes_192_ctr();
     }
 
+    @Override
     public PointerByReference _EVP_aes_256_cbc() {
         return EVP_aes_256_cbc();
     }
 
+    @Override
     public PointerByReference _EVP_aes_256_ctr() {
         return EVP_aes_256_ctr();
     }
 
-    public void _EVP_CIPHER_CTX_free(PointerByReference context) {
+    @Override
+    public void _EVP_CIPHER_CTX_free(final PointerByReference context) {
         EVP_CIPHER_CTX_free(context);
     }
 
+    @Override
     public PointerByReference _EVP_CIPHER_CTX_new() {
         return EVP_CIPHER_CTX_new();
     }
 
-    public int _EVP_CIPHER_CTX_set_padding(PointerByReference context, int padding) {
+    @Override
+    public int _EVP_CIPHER_CTX_set_padding(final PointerByReference context, final int padding) {
         return EVP_CIPHER_CTX_set_padding(context, padding);
     }
 
-    public int _EVP_CipherFinal_ex(PointerByReference context, ByteBuffer outBuffer, int[] outlen) {
+    @Override
+    public int _EVP_CipherFinal_ex(final PointerByReference context, final ByteBuffer outBuffer, final int[] outlen) {
         return EVP_CipherFinal_ex(context, outBuffer, outlen);
     }
 
-    public int _EVP_CipherInit_ex(PointerByReference context, PointerByReference algo, PointerByReference impl, byte[] encoded,
-            byte[] iv, int cipherMode) {
+    @Override
+    public int _EVP_CipherInit_ex(final PointerByReference context, final PointerByReference algo, final PointerByReference impl, final byte[] encoded,
+            final byte[] iv, final int cipherMode) {
         return EVP_CipherInit_ex(context, algo, impl, encoded, iv, cipherMode);
     }
 
-    public int _EVP_CipherUpdate(PointerByReference context, ByteBuffer outBuffer, int[] outlen, ByteBuffer inBuffer,
-            int remaining) {
+    @Override
+    public int _EVP_CipherUpdate(final PointerByReference context, final ByteBuffer outBuffer, final int[] outlen, final ByteBuffer inBuffer,
+            final int remaining) {
         return EVP_CipherUpdate(context, outBuffer, outlen, inBuffer, remaining);
     }
 
-    public int _RAND_bytes(ByteBuffer buf, int length) {
+    @Override
+    public int _RAND_bytes(final ByteBuffer buf, final int length) {
         return RAND_bytes(buf, length) ;
     }
 
+    @Override
     public PointerByReference _RAND_get_rand_method() {
         return RAND_get_rand_method();
     }
 
+    @Override
     public PointerByReference _RAND_SSLeay() {
         return RAND_SSLeay();
     }
 
-    public String _OpenSSL_version(int i) {
+    @Override
+    public String _OpenSSL_version(final int i) {
         return SSLeay_version(i);
     }
 
+    @Override
     public void _ENGINE_load_rdrand() {
         // Not available
     }
 
+    @Override
     public int _ENGINE_cleanup() {
         return ENGINE_cleanup();
     }
 
-    public void _EVP_CIPHER_CTX_cleanup(PointerByReference context) {
+    @Override
+    public void _EVP_CIPHER_CTX_cleanup(final PointerByReference context) {
         EVP_CIPHER_CTX_cleanup(context);
     }
 }
index d1e8ab2cbeaa084f46c2d0474dc90601bc982ae2..acf46ca362aa78c9b385980cc68873413e3b34fc 100644 (file)
@@ -97,13 +97,12 @@ class OpenSslJnaCipher implements CryptoCipher {
             cipherMode = OpenSslNativeJna.OOSL_JNA_ENCRYPT_MODE;
         }
         final byte[] iv;
-        if (params instanceof IvParameterSpec) {
-            iv = ((IvParameterSpec) params).getIV();
-        } else {
+        if (!(params instanceof IvParameterSpec)) {
             // other AlgorithmParameterSpec such as GCMParameterSpec is not
             // supported now.
             throw new InvalidAlgorithmParameterException("Illegal parameters");
         }
+        iv = ((IvParameterSpec) params).getIV();
 
         if ((algMode == AlgorithmMode.AES_CBC || algMode == AlgorithmMode.AES_CTR) && iv.length != IV_LENGTH) {
             throw new InvalidAlgorithmParameterException("Wrong IV length: must be 16 bytes long");
index 794f57dc6458c24f6be8a8615149a753ea3fcc95..57929d81d9d12f18dfa910a08e294c93823c0f3b 100644 (file)
@@ -44,7 +44,7 @@ class OpenSslNativeJna {
     public static final long VERSION_2_0_X = 0x20000000;
 
     private static final OpenSslInterfaceNativeJna JnaImplementation;
-  
+
     static {
         final String libraryName = System.getProperty(Crypto.CONF_PREFIX + OpenSslNativeJna.class.getSimpleName(), "crypto");
         OpenSslJna.debug("NativeLibrary.getInstance('%s')%n", libraryName);
index 5e65cea63c2720a388d03f641062300cdf3b2029..13e253876063fbc138878221d0d99e64ed7ace86 100644 (file)
@@ -92,8 +92,8 @@ class JavaCryptoRandom extends Random implements CryptoRandom {
     @Override
     protected int next(final int numBits) {
         Utils.checkArgument(numBits >= 0 && numBits <= 32);
-               // Can't simply invoke instance.next(bits) here, because that is package protected.
-               // But, this should do.
-               return  instance.nextInt() >>> (Integer.SIZE - numBits);
+        // Can't simply invoke instance.next(bits) here, because that is package protected.
+        // But, this should do.
+        return instance.nextInt() >>> (Integer.SIZE - numBits);
     }
 }
index 33e214088b7406585aab86a86fa82296f1ada36a..67a9b3b28f35b6b99f308f004ffaf35e39a37fe9 100644 (file)
@@ -65,7 +65,7 @@ class OpenSslCryptoRandom extends Random implements CryptoRandom {
         // Check that nextRandBytes works (is this really needed?)
         try {
             checkNative();
-        } catch (GeneralSecurityException e) {
+        } catch (final GeneralSecurityException e) {
             throw new IllegalStateException(e);
         }
         if (!OpenSslCryptoRandomNative.nextRandBytes(new byte[1])) {
@@ -139,7 +139,7 @@ class OpenSslCryptoRandom extends Random implements CryptoRandom {
 
     /**
      * Generates a user-specified number of random bytes. It's thread-safe.
-     * Overrides {@link Random}. 
+     * Overrides {@link Random}.
      *
      * @param bytes the array to be filled in with random bytes.
      */
index 27afbf96d404bbbdaa0f9110c6651ce5cee903f8..f22a22bcf9c99074031cefdd051977e8c17db4ac 100644 (file)
@@ -252,7 +252,8 @@ public class CryptoInputStream extends InputStream implements
         Objects.requireNonNull(array, "array");
         if (off < 0 || len < 0 || len > array.length - off) {
             throw new IndexOutOfBoundsException();
-        } else if (len == 0) {
+        }
+        if (len == 0) {
             return 0;
         }
 
@@ -508,13 +509,13 @@ public class CryptoInputStream extends InputStream implements
 
             // End of the stream
             return EOS;
-        } else if (n == 0) {
+        }
+        if (n == 0) {
             // No data is read, but the stream is not end yet
             return 0;
-        } else {
-            decrypt();
-            return outBuffer.remaining();
         }
+        decrypt();
+        return outBuffer.remaining();
     }
 
     /**
@@ -590,7 +591,7 @@ public class CryptoInputStream extends InputStream implements
             .clean(); */
             final String SUN_CLASS = "sun.nio.ch.DirectBuffer";
             final Class<?>[] interfaces = buffer.getClass().getInterfaces();
-            final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
+            final Object[] EMPTY_OBJECT_ARRAY = {};
 
             for (final Class<?> clazz : interfaces) {
                 if (clazz.getName().equals(SUN_CLASS)) {
index 47058f3be582dea4656a7e33e1064ac837f3509a..58712c4ab61a182d2d5b36a80e29b0c05cbea2b0 100644 (file)
@@ -265,27 +265,27 @@ public class CtrCryptoInputStream extends CryptoInputStream {
 
         if (n == 0) {
             return 0;
-        } else if (n <= outBuffer.remaining()) {
+        }
+        if (n <= outBuffer.remaining()) {
             final int pos = outBuffer.position() + (int) n;
             outBuffer.position(pos);
             return n;
-        } else {
-            /*
-             * Subtract outBuffer.remaining() to see how many bytes we need to
-             * skip in the underlying stream. Add outBuffer.remaining() to the
-             * actual number of skipped bytes in the underlying stream to get
-             * the number of skipped bytes from the user's point of view.
-             */
-            n -= outBuffer.remaining();
-            long skipped = input.skip(n);
-            if (skipped < 0) {
-                skipped = 0;
-            }
-            final long pos = streamOffset + skipped;
-            skipped += outBuffer.remaining();
-            resetStreamOffset(pos);
-            return skipped;
         }
+        /*
+         * Subtract outBuffer.remaining() to see how many bytes we need to
+         * skip in the underlying stream. Add outBuffer.remaining() to the
+         * actual number of skipped bytes in the underlying stream to get
+         * the number of skipped bytes from the user's point of view.
+         */
+        n -= outBuffer.remaining();
+        long skipped = input.skip(n);
+        if (skipped < 0) {
+            skipped = 0;
+        }
+        final long pos = streamOffset + skipped;
+        skipped += outBuffer.remaining();
+        resetStreamOffset(pos);
+        return skipped;
     }
 
     /**
index 7387e90af6462f8493d0b3822960b7ac2f328b3d..8837589adb082a76988745b00591486793eab1ec 100644 (file)
@@ -259,10 +259,9 @@ public class PositionedCryptoInputStream extends CtrCryptoInputStream {
      * @param position the offset from the start of the stream.
      * @param iv the iv.
      * @return the padding.
-     * @throws IOException if an I/O error occurs.
      */
     private byte postDecryption(final CipherState state, final ByteBuffer inByteBuffer,
-            final long position, final byte[] iv) throws IOException {
+            final long position, final byte[] iv) {
         byte padding = 0;
         if (state.isReset()) {
             /*
@@ -284,10 +283,8 @@ public class PositionedCryptoInputStream extends CtrCryptoInputStream {
      * @param state the CipherState instance.
      * @param position the offset from the start of the stream.
      * @param iv the iv.
-     * @throws IOException if an I/O error occurs.
      */
-    private void resetCipher(final CipherState state, final long position, final byte[] iv)
-            throws IOException {
+    private void resetCipher(final CipherState state, final long position, final byte[] iv) {
         final long counter = getCounter(position);
         CtrCryptoInputStream.calculateIV(getInitIV(), counter, iv);
         try {
index 76c163495f67af311006e2811d45e95e5274e267..372701772fd3c1514374c9f416ca7fe57546279b 100644 (file)
@@ -67,7 +67,8 @@ public class StreamInput implements Input {
                     read = EOS;
                 }
                 break;
-            } else if (n > 0) {
+            }
+            if (n > 0) {
                 dst.put(buf, 0, n);
                 read += n;
                 remaining -= n;
index dbde489e6e004d11a7bb43ac573e273037d0ec5f..165047292303d299c306eaaf597e6ddaa42544d3 100644 (file)
@@ -137,11 +137,11 @@ public final class ReflectionUtils {
             // two putters can race here, but they'll put the same class
             map.put(name, new WeakReference<>(clazz));
             return clazz;
-        } else if (clazz == NEGATIVE_CACHE_SENTINEL) {
+        }
+        if (clazz == NEGATIVE_CACHE_SENTINEL) {
             return null; // not found
-        } else {
-            // cache hit
-            return clazz;
         }
+        // cache hit
+        return clazz;
     }
 }
index 15b8398869a5a084558f7396c24596f2acabd98f..01f807f449fe5818b71f9659e334b92c06073e68 100644 (file)
@@ -275,7 +275,7 @@ public abstract class AbstractCipherTest {
 
                        // check update method with inputs whose sizes are the multiple of
                        // block size or not
-                       final int[] bufferLenList = new int[] { 2 * 1024 - 128, 2 * 1024 - 125 };
+                       final int[] bufferLenList = { 2 * 1024 - 128, 2 * 1024 - 125 };
                        for (final int bufferLen : bufferLenList) {
                                resetCipher(transformation, key, iv);
 
index ceb60fffd196dbe410c7631602cf814687bfb5f9..f36ab440ca5e4792f9e01f221140ef803c809d95 100644 (file)
@@ -252,7 +252,7 @@ public class GcmCipherTest {
 
         final Random r = new Random();
         final byte[] keyBytes = new byte[32];
-        final byte[] input = new byte[0];  // no input for GMAC
+        final byte[] input = {};  // no input for GMAC
         final byte[] ivBytes = new byte[16];
 
         final byte[] tag_orig = new byte[16]; // JDK's tag
@@ -302,7 +302,7 @@ public class GcmCipherTest {
     public void testGMacTamperedData() throws Exception {
         final Random r = new Random();
         final byte[] keyBytes = new byte[32];
-        final byte[] input = new byte[0];
+        final byte[] input = {};
         final byte[] ivBytes = new byte[16];
 
         final byte[] tag = new byte[16];
index fc89b0de881a9a27d35999bd34f70741ea267678..f6ae77e7ee34877053d288b106091a5dd62ea646 100644 (file)
@@ -26,7 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 public class OpenSslNativeJnaTest {
 
     @Test
-    public void test(TestReporter reporter) {
+    public void test(final TestReporter reporter) {
         if (OpenSslJna.isEnabled()) {
             reporter.publishEntry(String.format("JNA loaded OK for lib version 0x%x: ", OpenSslNativeJna.VERSION));
         } else {
index 12f29ae90c4d62436151e40eba1c7a2227e11169..881fbe34ba539536800537ca2053397e81d43e63 100644 (file)
@@ -18,7 +18,6 @@
 package org.apache.commons.crypto.random;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -26,7 +25,6 @@ import java.security.GeneralSecurityException;
 import java.util.Properties;
 import java.util.Random;
 
-import org.apache.commons.crypto.utils.Utils;
 import org.junit.jupiter.api.Test;
 
 public class JavaCryptoRandomTest extends AbstractRandomTest {
@@ -47,7 +45,7 @@ public class JavaCryptoRandomTest extends AbstractRandomTest {
     public void testNextIntIsntActuallyRandomNextInt() throws Exception {
        final CryptoRandom cr = getCryptoRandom();
        final Random r = (Random) cr;
-       final long seed = 1654421930011l; // System.getCurrentMillis() on 2022-June-05, 11:39
+       final long seed = 1654421930011L; // System.getCurrentMillis() on 2022-June-05, 11:39
        final Random otherRandom = new Random(seed);
        final Random otherRandom2 = new Random();
        otherRandom2.setSeed(seed);
index 0926b9ef8fee4424a83b536dcae0edaf3322b00c..8bc0decea1fef24eeb10d8549182a9a23e724edb 100644 (file)
@@ -148,12 +148,11 @@ public class PositionedCryptoInputStreamTest {
                     compareByteArray(testData, position, bytes2, pn2);
                 }
 
-                if (n > 0) {
-                    compareByteArray(testData, position, buf.array(), n);
-                    position += n;
-                } else {
+                if (n <= 0) {
                     break;
                 }
+                compareByteArray(testData, position, buf.array(), n);
+                position += n;
             }
         }
     }
@@ -233,12 +232,11 @@ public class PositionedCryptoInputStreamTest {
                 in.seek(position);
                 final ByteBuffer buf = ByteBuffer.allocate(length);
                 final int n = in.read(buf);
-                if (n > 0) {
-                    compareByteArray(testData, position, buf.array(), n);
-                    position += n;
-                } else {
+                if (n <= 0) {
                     break;
                 }
+                compareByteArray(testData, position, buf.array(), n);
+                position += n;
             }
         }
     }
@@ -258,12 +256,11 @@ public class PositionedCryptoInputStreamTest {
             while (position < total) {
                 final byte[] bytes = new byte[length];
                 final int n = in.read(position, bytes, 0, length);
-                if (n >= 0) {
-                    compareByteArray(testData, position, bytes, n);
-                    position += n;
-                } else {
+                if (n < 0) {
                     break;
                 }
+                compareByteArray(testData, position, bytes, n);
+                position += n;
             }
         }
     }
@@ -394,7 +391,8 @@ public class PositionedCryptoInputStreamTest {
         public void seek(final long position) throws IOException {
             if (pos < 0) {
                 throw new IOException("Negative seek offset");
-            } else if (position >= 0 && position < count) {
+            }
+            if (position >= 0 && position < count) {
                 pos = position;
             } else {
                 // to the end of file