You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by sd...@apache.org on 2016/06/21 09:10:15 UTC

commons-crypto git commit: CRYPTO-86 remove the Properties field in CryptoCipher

Repository: commons-crypto
Updated Branches:
  refs/heads/master 2c57b118a -> 4bbb57a05


CRYPTO-86 remove the Properties field in CryptoCipher


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

Branch: refs/heads/master
Commit: 4bbb57a05d49dad0fd493c8fabfad3cf7991215a
Parents: 2c57b11
Author: Xianda Ke <xi...@intel.com>
Authored: Tue Jun 21 15:15:44 2016 +0800
Committer: Xianda Ke <xi...@intel.com>
Committed: Tue Jun 21 16:58:40 2016 +0800

----------------------------------------------------------------------
 .../apache/commons/crypto/cipher/CryptoCipher.java    |  7 -------
 .../org/apache/commons/crypto/cipher/JceCipher.java   | 12 ------------
 .../apache/commons/crypto/cipher/OpensslCipher.java   | 12 ------------
 .../crypto/stream/PositionedCryptoInputStream.java    | 14 ++++++++++----
 .../stream/PositionedCryptoInputStreamTest.java       |  2 +-
 5 files changed, 11 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/4bbb57a0/src/main/java/org/apache/commons/crypto/cipher/CryptoCipher.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/CryptoCipher.java b/src/main/java/org/apache/commons/crypto/cipher/CryptoCipher.java
index bd494fb..746a4d1 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/CryptoCipher.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/CryptoCipher.java
@@ -45,13 +45,6 @@ public interface CryptoCipher extends Closeable {
     CipherTransformation getTransformation();
 
     /**
-     * Gets the properties for this cipher.
-     *
-     * @return the properties for this cipher.
-     */
-    Properties getProperties();
-
-    /**
      * Initializes the cipher with mode, key and iv.
      *
      * @param mode {@link javax.crypto.Cipher#ENCRYPT_MODE} or {@link javax

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/4bbb57a0/src/main/java/org/apache/commons/crypto/cipher/JceCipher.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/JceCipher.java b/src/main/java/org/apache/commons/crypto/cipher/JceCipher.java
index 324c75f..2098b43 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/JceCipher.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/JceCipher.java
@@ -37,7 +37,6 @@ import org.apache.commons.crypto.utils.Utils;
  * Implements the {@link CryptoCipher} using JCE provider.
  */
 public class JceCipher implements CryptoCipher {
-    private final Properties props;
     private final CipherTransformation transformation;
     private final Cipher cipher;
 
@@ -50,7 +49,6 @@ public class JceCipher implements CryptoCipher {
      */
     public JceCipher(Properties props, CipherTransformation transformation)
             throws GeneralSecurityException {
-        this.props = props;
         this.transformation = transformation;
 
         String provider = getJCEProvider(props);
@@ -72,16 +70,6 @@ public class JceCipher implements CryptoCipher {
     }
 
     /**
-     * Gets the properties for the jce cipher.
-     *
-     * @return the properties for this cipher.
-     */
-    @Override
-    public Properties getProperties() {
-        return props;
-    }
-
-    /**
      * Initializes the cipher with mode, key and iv.
      *
      * @param mode {@link Cipher#ENCRYPT_MODE} or {@link Cipher#DECRYPT_MODE}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/4bbb57a0/src/main/java/org/apache/commons/crypto/cipher/OpensslCipher.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/OpensslCipher.java b/src/main/java/org/apache/commons/crypto/cipher/OpensslCipher.java
index 37938c4..a39e769 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/OpensslCipher.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/OpensslCipher.java
@@ -36,7 +36,6 @@ import org.apache.commons.crypto.utils.Utils;
  * Implements the CryptoCipher using JNI into OpenSSL.
  */
 public class OpensslCipher implements CryptoCipher {
-    private final Properties props;
     private final CipherTransformation transformation;
     private final Openssl cipher;
 
@@ -49,7 +48,6 @@ public class OpensslCipher implements CryptoCipher {
      */
     public OpensslCipher(Properties props, CipherTransformation transformation)
             throws GeneralSecurityException {
-        this.props = props;
         this.transformation = transformation;
 
         String loadingFailureReason = Openssl.getLoadingFailureReason();
@@ -71,16 +69,6 @@ public class OpensslCipher implements CryptoCipher {
     }
 
     /**
-     * Gets the properties for the openssl cipher.
-     *
-     * @return the properties for this cipher.
-     */
-    @Override
-    public Properties getProperties() {
-        return props;
-    }
-
-    /**
      * Initializes the cipher with mode, key and iv.
      *
      * @param mode {@link Cipher#ENCRYPT_MODE} or {@link Cipher#DECRYPT_MODE}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/4bbb57a0/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java b/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java
index cbd77fb..55f47c3 100644
--- a/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java
@@ -56,6 +56,11 @@ public class PositionedCryptoInputStream extends CTRCryptoInputStream {
     private final Queue<CipherState> cipherPool = new ConcurrentLinkedQueue<CipherState>();
 
     /**
+     * properties for constructing a CryptoCipher
+     */
+    private final Properties props;
+
+    /**
      * Constructs a {@link PositionedCryptoInputStream}.
      *
      * @param props The <code>Properties</code> class represents a set of
@@ -68,8 +73,8 @@ public class PositionedCryptoInputStream extends CTRCryptoInputStream {
      */
     public PositionedCryptoInputStream(Properties props, Input in, byte[] key,
             byte[] iv, long streamOffset) throws IOException {
-        this(in, Utils.getCipherInstance(AES_CTR_NOPADDING, props), Utils
-                .getBufferSize(props), key, iv, streamOffset);
+        this(props, in, Utils.getCipherInstance(AES_CTR_NOPADDING, props),
+                Utils.getBufferSize(props), key, iv, streamOffset);
     }
 
     /**
@@ -83,10 +88,11 @@ public class PositionedCryptoInputStream extends CTRCryptoInputStream {
      * @param streamOffset the start offset in the data.
      * @throws IOException if an I/O error occurs.
      */
-    protected PositionedCryptoInputStream(Input input, CryptoCipher cipher,
+    protected PositionedCryptoInputStream(Properties props, Input input, CryptoCipher cipher,
             int bufferSize, byte[] key, byte[] iv, long streamOffset)
             throws IOException {
         super(input, cipher, bufferSize, key, iv, streamOffset);
+        this.props = props;
     }
 
     /**
@@ -314,7 +320,7 @@ public class PositionedCryptoInputStream extends CTRCryptoInputStream {
             CryptoCipher cipher;
             try {
                 cipher = CryptoCipherFactory.getInstance(getCipher()
-                        .getTransformation(), getCipher().getProperties());
+                        .getTransformation(), props);
             } catch (GeneralSecurityException e) {
                 throw new IOException(e);
             }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/4bbb57a0/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java b/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java
index 09b8fd9..1781796 100644
--- a/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java
+++ b/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java
@@ -92,7 +92,7 @@ public class PositionedCryptoInputStreamTest {
 
     private PositionedCryptoInputStream getCryptoInputStream(
             CryptoCipher cipher, int bufferSize) throws IOException {
-        return new PositionedCryptoInputStream(new PositionedInputForTest(
+        return new PositionedCryptoInputStream(props, new PositionedInputForTest(
                 Arrays.copyOf(encData, encData.length)), cipher, bufferSize,
                 key, iv, 0);
     }