diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2016-08-19 20:23:16 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2016-08-19 20:23:16 +0000 |
commit | 892d978d4e7f99b503ee950224de8df7ed3d66ae (patch) | |
tree | 14502ae9139c71388b1dce3078e9330c966b0a19 /src/java/org/apache/poi/poifs/crypt/ChunkedCipherInputStream.java | |
parent | 753a03eef713b321a7b0692f2e1922f28c5c925e (diff) | |
download | poi-892d978d4e7f99b503ee950224de8df7ed3d66ae.tar.gz poi-892d978d4e7f99b503ee950224de8df7ed3d66ae.zip |
add encryption support
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/hssf_cryptoapi@1756964 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/poifs/crypt/ChunkedCipherInputStream.java')
-rw-r--r-- | src/java/org/apache/poi/poifs/crypt/ChunkedCipherInputStream.java | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/java/org/apache/poi/poifs/crypt/ChunkedCipherInputStream.java b/src/java/org/apache/poi/poifs/crypt/ChunkedCipherInputStream.java index 7b5632dea7..e59ceb369c 100644 --- a/src/java/org/apache/poi/poifs/crypt/ChunkedCipherInputStream.java +++ b/src/java/org/apache/poi/poifs/crypt/ChunkedCipherInputStream.java @@ -222,24 +222,33 @@ public abstract class ChunkedCipherInputStream extends LittleEndianInputStream { /**
* Used when BIFF header fields (sid, size) are being read. The internal
* {@link Cipher} instance must step even when unencrypted bytes are read
+ *
*/
- public int readPlain(byte b[], int off, int len) throws IOException {
+ @Override
+ public void readPlain(byte b[], int off, int len) {
if (len <= 0) {
- return len;
+ return;
}
- int readBytes, total = 0;
- do {
- readBytes = read(b, off, len, true);
- total += Math.max(0, readBytes);
- } while (readBytes > -1 && total < len);
-
- return total;
+ try {
+ int readBytes, total = 0;
+ do {
+ readBytes = read(b, off, len, true);
+ total += Math.max(0, readBytes);
+ } while (readBytes > -1 && total < len);
+
+ if (total < len) {
+ throw new EOFException("buffer underrun");
+ }
+ } catch (IOException e) {
+ // need to wrap checked exception, because of LittleEndianInput interface :(
+ throw new RuntimeException(e);
+ }
}
/**
* Some ciphers (actually just XOR) are based on the record size,
- * which needs to be set before encryption
+ * which needs to be set before decryption
*
* @param recordSize the size of the next record
*/
|