Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Hook <dgh@cryptoworkshop.com>2014-05-20 01:47:12 +0400
committerDavid Hook <dgh@cryptoworkshop.com>2014-05-20 01:47:12 +0400
commitb2af52be1c1251f7c0b613e4ad300faa3e262e74 (patch)
treecc46c9d6150ed96d9316557afc807f1ccce8ea62 /core/src/main/java/org/bouncycastle
parent49555ece84b685bddbbbb5e48d3f7715452aab2f (diff)
further work on SkippingCiphers
Diffstat (limited to 'core/src/main/java/org/bouncycastle')
-rw-r--r--core/src/main/java/org/bouncycastle/crypto/io/CipherInputStream.java35
1 files changed, 32 insertions, 3 deletions
diff --git a/core/src/main/java/org/bouncycastle/crypto/io/CipherInputStream.java b/core/src/main/java/org/bouncycastle/crypto/io/CipherInputStream.java
index ebebe3d0..bf40f125 100644
--- a/core/src/main/java/org/bouncycastle/crypto/io/CipherInputStream.java
+++ b/core/src/main/java/org/bouncycastle/crypto/io/CipherInputStream.java
@@ -6,6 +6,7 @@ import java.io.InputStream;
import org.bouncycastle.crypto.BufferedBlockCipher;
import org.bouncycastle.crypto.InvalidCipherTextException;
+import org.bouncycastle.crypto.SkippingCipher;
import org.bouncycastle.crypto.StreamCipher;
import org.bouncycastle.crypto.modes.AEADBlockCipher;
@@ -240,9 +241,36 @@ public class CipherInputStream
return 0;
}
- int skip = (int)Math.min(n, available());
- bufOff += skip;
- return skip;
+ if (streamCipher instanceof SkippingCipher)
+ {
+ int avail = available();
+ if (n <= avail)
+ {
+ bufOff += n;
+
+ return n;
+ }
+
+ bufOff = maxBuf;
+
+ long skip = in.skip(n - avail);
+
+ long cSkip = ((SkippingCipher)streamCipher).skip(skip);
+
+ if (skip != cSkip)
+ {
+ throw new IOException("Unable to skip cipher " + skip + " bytes.");
+ }
+
+ return skip;
+ }
+ else
+ {
+ int skip = (int)Math.min(n, available());
+ bufOff += skip;
+
+ return skip;
+ }
}
public int available()
@@ -317,6 +345,7 @@ public class CipherInputStream
public void mark(int readlimit)
{
+ // TODO: add support for skipping ciphers
}
public void reset()