You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2016/06/25 12:19:55 UTC

commons-crypto git commit: CRYPTO-87 Reduce util package API footprint

Repository: commons-crypto
Updated Branches:
  refs/heads/master 6522a7299 -> f0ba94cb1


CRYPTO-87 Reduce util package API footprint

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

Branch: refs/heads/master
Commit: f0ba94cb1c6a395c478287edf0a3c6b42ccb9c49
Parents: 6522a72
Author: Sebb <se...@apache.org>
Authored: Sat Jun 25 13:19:50 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sat Jun 25 13:19:50 2016 +0100

----------------------------------------------------------------------
 .../crypto/stream/CTRCryptoInputStream.java     |  2 +-
 .../crypto/stream/CTRCryptoOutputStream.java    |  2 +-
 .../crypto/stream/CryptoInputStream.java        | 31 +++++++++++++++++++-
 .../crypto/stream/CryptoOutputStream.java       |  2 +-
 .../org/apache/commons/crypto/utils/Utils.java  | 30 +------------------
 5 files changed, 34 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/f0ba94cb/src/main/java/org/apache/commons/crypto/stream/CTRCryptoInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/stream/CTRCryptoInputStream.java b/src/main/java/org/apache/commons/crypto/stream/CTRCryptoInputStream.java
index aabf0b6..84fc05e 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CTRCryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CTRCryptoInputStream.java
@@ -245,7 +245,7 @@ public class CTRCryptoInputStream extends CryptoInputStream {
         this.initIV = iv.clone();
         this.iv = iv.clone();
 
-        Utils.checkStreamCipher(cipher);
+        CryptoInputStream.checkStreamCipher(cipher);
 
         resetStreamOffset(streamOffset);
     }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/f0ba94cb/src/main/java/org/apache/commons/crypto/stream/CTRCryptoOutputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/stream/CTRCryptoOutputStream.java b/src/main/java/org/apache/commons/crypto/stream/CTRCryptoOutputStream.java
index c389024..0025a7a 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CTRCryptoOutputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CTRCryptoOutputStream.java
@@ -243,7 +243,7 @@ public class CTRCryptoOutputStream extends CryptoOutputStream {
         super(output, cipher, bufferSize, new SecretKeySpec(key, "AES"),
                 new IvParameterSpec(iv));
 
-        Utils.checkStreamCipher(cipher);
+        CryptoInputStream.checkStreamCipher(cipher);
         this.streamOffset = streamOffset;
         this.initIV = iv.clone();
         this.iv = iv.clone();

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/f0ba94cb/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java b/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
index 5378e56..c4a6935 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
@@ -84,6 +84,8 @@ public class CryptoInputStream extends InputStream implements
      */
     ByteBuffer outBuffer;
 
+    private static final int MIN_BUFFER_SIZE = 512;
+
     /**
      * Constructs a {@link CryptoInputStream}.
      *
@@ -172,7 +174,7 @@ public class CryptoInputStream extends InputStream implements
             Key key, AlgorithmParameterSpec params) throws IOException {
         this.input = input;
         this.cipher = cipher;
-        this.bufferSize = Utils.checkBufferSize(cipher, bufferSize);
+        this.bufferSize = CryptoInputStream.checkBufferSize(cipher, bufferSize);
 
         this.key = key;
         this.params = params;
@@ -567,4 +569,31 @@ public class CryptoInputStream extends InputStream implements
         Utils.freeDirectBuffer(inBuffer);
         Utils.freeDirectBuffer(outBuffer);
     }
+
+    /**
+     * Checks whether the cipher is supported streaming.
+     *
+     * @param cipher the {@link CryptoCipher} instance.
+     * @throws IOException if an I/O error occurs.
+     */
+    static void checkStreamCipher(CryptoCipher cipher)
+            throws IOException {
+        if (!cipher.getAlgorithm().equals("AES/CTR/NoPadding")) {
+            throw new IOException("AES/CTR/NoPadding is required");
+        }
+    }
+
+    /**
+     * Checks and floors buffer size.
+     *
+     * @param cipher the {@link CryptoCipher} instance.
+     * @param bufferSize the buffer size.
+     * @return the remaining buffer size.
+     */
+    static int checkBufferSize(CryptoCipher cipher, int bufferSize) {
+        Utils.checkArgument(bufferSize >= CryptoInputStream.MIN_BUFFER_SIZE,
+                "Minimum value of buffer size is " + CryptoInputStream.MIN_BUFFER_SIZE + ".");
+        return bufferSize - bufferSize
+                % cipher.getBlockSize();
+    }
 }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/f0ba94cb/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java b/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java
index 477fcf5..f89b7df 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java
@@ -171,7 +171,7 @@ public class CryptoOutputStream extends OutputStream implements
             throws IOException {
 
         this.output = output;
-        this.bufferSize = Utils.checkBufferSize(cipher, bufferSize);
+        this.bufferSize = CryptoInputStream.checkBufferSize(cipher, bufferSize);
         this.cipher = cipher;
 
         this.key = key;

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/f0ba94cb/src/main/java/org/apache/commons/crypto/utils/Utils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/utils/Utils.java b/src/main/java/org/apache/commons/crypto/utils/Utils.java
index fd5cf9f..5c1800c 100644
--- a/src/main/java/org/apache/commons/crypto/utils/Utils.java
+++ b/src/main/java/org/apache/commons/crypto/utils/Utils.java
@@ -36,8 +36,6 @@ import org.apache.commons.crypto.conf.ConfigurationKeys;
  */
 public final class Utils {
 
-    private static final int MIN_BUFFER_SIZE = 512;
-
     /**
      * For AES, the algorithm block is fixed size of 128 bits.
      *
@@ -61,6 +59,7 @@ public final class Utils {
      * {@link ConfigurationKeys#SYSTEM_PROPERTIES_FILE} is found.
      */
     private static void loadSystemProperties() {
+        new Throwable().printStackTrace();
         try {
             InputStream is = Thread.currentThread().getContextClassLoader()
                     .getResourceAsStream(ConfigurationKeys.SYSTEM_PROPERTIES_FILE);
@@ -165,33 +164,6 @@ public final class Utils {
     }
 
     /**
-     * Checks whether the cipher is supported streaming.
-     *
-     * @param cipher the {@link CryptoCipher} instance.
-     * @throws IOException if an I/O error occurs.
-     */
-    public static void checkStreamCipher(CryptoCipher cipher)
-            throws IOException {
-        if (!cipher.getAlgorithm().equals("AES/CTR/NoPadding")) {
-            throw new IOException("AES/CTR/NoPadding is required");
-        }
-    }
-
-    /**
-     * Checks and floors buffer size.
-     *
-     * @param cipher the {@link CryptoCipher} instance.
-     * @param bufferSize the buffer size.
-     * @return the remaining buffer size.
-     */
-    public static int checkBufferSize(CryptoCipher cipher, int bufferSize) {
-        checkArgument(bufferSize >= MIN_BUFFER_SIZE,
-                "Minimum value of buffer size is " + MIN_BUFFER_SIZE + ".");
-        return bufferSize - bufferSize
-                % cipher.getBlockSize();
-    }
-
-    /**
      * <p>
      * This method is only for Counter (CTR) mode. Generally the CryptoCipher
      * calculates the IV and maintain encryption context internally.For example