commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From x..@apache.org
Subject commons-crypto git commit: CRYPTO-30: Mutable fields should be private
Date Fri, 29 Apr 2016 02:46:31 GMT
Repository: commons-crypto
Updated Branches:
  refs/heads/master d1fb85f7c -> 98bec4c43


CRYPTO-30: Mutable fields should be private


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

Branch: refs/heads/master
Commit: 98bec4c43e42ea68437d13c1137b148428562e2c
Parents: d1fb85f
Author: Ferdinand Xu <cheng.a.xu@intel.com>
Authored: Wed Apr 27 04:24:38 2016 +0800
Committer: Ferdinand Xu <cheng.a.xu@intel.com>
Committed: Fri Apr 29 03:23:57 2016 +0800

----------------------------------------------------------------------
 .../crypto/stream/CTRCipherInputStream.java     |  9 ++-
 .../crypto/stream/CTRCipherOutputStream.java    | 20 ++++-
 .../crypto/stream/CipherInputStream.java        | 36 ++++++---
 .../crypto/stream/CipherOutputStream.java       | 78 +++++++++++++++-----
 .../crypto/stream/output/StreamOutput.java      | 13 ++--
 5 files changed, 120 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/98bec4c4/src/main/java/org/apache/commons/crypto/stream/CTRCipherInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/stream/CTRCipherInputStream.java b/src/main/java/org/apache/commons/crypto/stream/CTRCipherInputStream.java
index 0d1c546..b0cea74 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CTRCipherInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CTRCipherInputStream.java
@@ -54,7 +54,7 @@ public class CTRCipherInputStream extends CipherInputStream {
   /**
    * Underlying stream offset
    */
-  protected long streamOffset = 0;
+  long streamOffset = 0;
 
   /**
    * The initial IV.
@@ -343,7 +343,7 @@ public class CTRCipherInputStream extends CipherInputStream {
 
   /**
    * Seeks the stream to a specific position relative to start of the under layer stream.
-   * 
+   *
    * @param position the given position in the data.
    * @throws IOException if an I/O error occurs.
    */
@@ -374,6 +374,10 @@ public class CTRCipherInputStream extends CipherInputStream {
     return streamOffset;
   }
 
+  protected void setStreamOffset(long streamOffset) {
+    this.streamOffset = streamOffset;
+  }
+
   /**
    * Gets the position of the stream.
    *
@@ -618,5 +622,4 @@ public class CTRCipherInputStream extends CipherInputStream {
       throw new IOException(e);
     }
   }
-
 }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/98bec4c4/src/main/java/org/apache/commons/crypto/stream/CTRCipherOutputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/stream/CTRCipherOutputStream.java b/src/main/java/org/apache/commons/crypto/stream/CTRCipherOutputStream.java
index b3dc7c9..7889123 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CTRCipherOutputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CTRCipherOutputStream.java
@@ -53,7 +53,7 @@ public class CTRCipherOutputStream extends CipherOutputStream {
   /**
    * Underlying stream offset.
    */
-  protected long streamOffset = 0;
+  long streamOffset = 0;
 
   /**
    * The initial IV.
@@ -364,4 +364,22 @@ public class CTRCipherOutputStream extends CipherOutputStream {
       throw new IOException(e);
     }
   }
+
+  /**
+   * Get the underlying stream offset
+   *
+   * @return the underlying stream offset
+   */
+  protected long getStreamOffset() {
+    return streamOffset;
+  }
+
+  /**
+   * Set the underlying stream offset
+   *
+   * @param streamOffset the underlying stream offset
+   */
+  protected void setStreamOffset(long streamOffset) {
+    this.streamOffset = streamOffset;
+  }
 }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/98bec4c4/src/main/java/org/apache/commons/crypto/stream/CipherInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/stream/CipherInputStream.java b/src/main/java/org/apache/commons/crypto/stream/CipherInputStream.java
index f556153..83df143 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CipherInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CipherInputStream.java
@@ -50,25 +50,25 @@ public class CipherInputStream extends InputStream implements
   private final byte[] oneByteBuf = new byte[1];
 
   /**The Cipher instance.*/
-  protected final Cipher cipher;
+  final Cipher cipher;
 
   /**The buffer size.*/
-  protected final int bufferSize;
+  final int bufferSize;
 
   /**Crypto key for the cipher.*/
-  protected final Key key;
+  final Key key;
 
   /** the algorithm parameters */
-  protected final AlgorithmParameterSpec params;
+  final AlgorithmParameterSpec params;
 
   /** Flag to mark whether the input stream is closed.*/
-  protected boolean closed;
+  private boolean closed;
 
   /** Flag to mark whether do final of the cipher to end the decrypting stream.*/
-  protected boolean finalDone = false;
+  private boolean finalDone = false;
 
   /**The input data.*/
-  protected Input input;
+  Input input;
 
   /**
    * Input data buffer. The data starts at inBuffer.position() and ends at
@@ -96,8 +96,8 @@ public class CipherInputStream extends InputStream implements
   public CipherInputStream(CipherTransformation transformation,
                            Properties props, InputStream in, Key key, AlgorithmParameterSpec
params)
       throws IOException {
-    this(in, Utils.getCipherInstance(transformation, props),
-        Utils.getBufferSize(props), key, params);
+    this(in, Utils.getCipherInstance(transformation, props), Utils.getBufferSize(props),
key,
+      params);
   }
 
   /**
@@ -424,6 +424,24 @@ public class CipherInputStream extends InputStream implements
   }
 
   /**
+   * Gets the specification of cryptographic parameters.
+   *
+   * @return the params.
+   */
+  protected AlgorithmParameterSpec getParams() {
+    return params;
+  }
+
+  /**
+   * Gets the input.
+   *
+   * @return the input.
+   */
+  protected Input getInput() {
+    return input;
+  }
+
+  /**
    * Initializes the cipher.
    *
    * @throws IOException if an I/O error occurs.

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/98bec4c4/src/main/java/org/apache/commons/crypto/stream/CipherOutputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/stream/CipherOutputStream.java b/src/main/java/org/apache/commons/crypto/stream/CipherOutputStream.java
index 5cadbb6..57a0e1b 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CipherOutputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CipherOutputStream.java
@@ -52,34 +52,34 @@ public class CipherOutputStream extends OutputStream implements
   private final byte[] oneByteBuf = new byte[1];
 
   /** The output.*/
-  protected Output output;
+  Output output;
 
   /**the Cipher instance*/
-  protected final Cipher cipher;
+  final Cipher cipher;
 
   /**The buffer size.*/
-  protected final int bufferSize;
+  final int bufferSize;
 
   /**Crypto key for the cipher.*/
-  protected final Key key;
+  final Key key;
 
   /** the algorithm parameters */
-  protected final AlgorithmParameterSpec params;
+  final AlgorithmParameterSpec params;
 
   /** Flag to mark whether the output stream is closed.*/
-  protected boolean closed;
+  private boolean closed;
 
   /**
    * Input data buffer. The data starts at inBuffer.position() and ends at
    * inBuffer.limit().
    */
-  protected ByteBuffer inBuffer;
+  ByteBuffer inBuffer;
 
   /**
    * Encrypted data buffer. The data starts at outBuffer.position() and ends at
    * outBuffer.limit().
    */
-  protected ByteBuffer outBuffer;
+  ByteBuffer outBuffer;
 
   /**
    * Constructs a {@link org.apache.commons.crypto.stream.CipherOutputStream}.
@@ -92,11 +92,14 @@ public class CipherOutputStream extends OutputStream implements
    * @param params the algorithm parameters.
    * @throws IOException if an I/O error occurs.
    */
-  public CipherOutputStream(CipherTransformation transformation,
-                            Properties props, OutputStream out, Key key, AlgorithmParameterSpec
params)
-      throws IOException {
-    this(out, Utils.getCipherInstance(transformation, props),
-        Utils.getBufferSize(props), key, params);
+  public CipherOutputStream(
+    CipherTransformation transformation,
+    Properties props,
+    OutputStream out,
+    Key key,
+    AlgorithmParameterSpec params) throws IOException {
+    this(out, Utils.getCipherInstance(transformation, props), Utils.getBufferSize(props),
key,
+      params);
   }
 
   /**
@@ -110,11 +113,14 @@ public class CipherOutputStream extends OutputStream implements
    * @param params the algorithm parameters.
    * @throws IOException if an I/O error occurs.
    */
-  public CipherOutputStream(CipherTransformation transformation,
-                            Properties props, WritableByteChannel out, Key key, AlgorithmParameterSpec
params)
-      throws IOException {
-    this(out, Utils.getCipherInstance(transformation, props),
-        Utils.getBufferSize(props), key, params);
+  public CipherOutputStream(
+    CipherTransformation transformation,
+    Properties props,
+    WritableByteChannel out,
+    Key key,
+    AlgorithmParameterSpec params) throws IOException {
+    this(out, Utils.getCipherInstance(transformation, props), Utils.getBufferSize(props),
key,
+      params);
   }
 
   /**
@@ -393,4 +399,40 @@ public class CipherOutputStream extends OutputStream implements
     Utils.freeDirectBuffer(inBuffer);
     Utils.freeDirectBuffer(outBuffer);
   }
+
+  /**
+   * Gets the outBuffer.
+   *
+   * @return the outBuffer.
+   */
+  protected ByteBuffer getOutBuffer() {
+    return outBuffer;
+  }
+
+  /**
+   * Gets the internal Cipher.
+   *
+   * @return the cipher instance.
+   */
+  protected Cipher getCipher() {
+    return cipher;
+  }
+
+  /**
+   * Gets the buffer size.
+   *
+   * @return the buffer size.
+   */
+  protected int getBufferSize() {
+    return bufferSize;
+  }
+
+  /**
+   * Gets the inBuffer.
+   *
+   * @return the inBuffer.
+   */
+  protected ByteBuffer getInBuffer() {
+    return inBuffer;
+  }
 }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/98bec4c4/src/main/java/org/apache/commons/crypto/stream/output/StreamOutput.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/stream/output/StreamOutput.java b/src/main/java/org/apache/commons/crypto/stream/output/StreamOutput.java
index ad067be..73f0c74 100644
--- a/src/main/java/org/apache/commons/crypto/stream/output/StreamOutput.java
+++ b/src/main/java/org/apache/commons/crypto/stream/output/StreamOutput.java
@@ -22,13 +22,13 @@ import java.io.OutputStream;
 import java.nio.ByteBuffer;
 
 /**
- * The StreamOutput class takes a <code>OutputStream</code> object and wraps
it as 
+ * The StreamOutput class takes a <code>OutputStream</code> object and wraps
it as
  * <code>Output</code> object acceptable by <code>CipherOutputStream</code>
as the output target.
  */
 public class StreamOutput implements Output {
   private byte[] buf;
   private int bufferSize;
-  protected OutputStream out;
+  private OutputStream out;
 
   /**
    * Constructs a {@link org.apache.commons.crypto.stream.output.StreamOutput}.
@@ -55,7 +55,7 @@ public class StreamOutput implements Output {
   public int write(ByteBuffer src) throws IOException {
     final int len = src.remaining();
     final byte[] buf = getBuf();
-    
+
     int remaining = len;
     while(remaining > 0) {
       final int n = Math.min(remaining, bufferSize);
@@ -63,7 +63,7 @@ public class StreamOutput implements Output {
       out.write(buf, 0, n);
       remaining = src.remaining();
     }
-    
+
     return len;
   }
 
@@ -90,7 +90,7 @@ public class StreamOutput implements Output {
   public void close() throws IOException {
     out.close();
   }
-  
+
   private byte[] getBuf() {
     if (buf == null) {
       buf = new byte[bufferSize];
@@ -98,4 +98,7 @@ public class StreamOutput implements Output {
     return buf;
   }
 
+  protected OutputStream getOut() {
+    return out;
+  }
 }


Mime
View raw message