aboutsummaryrefslogtreecommitdiffstats
path: root/poi-ooxml/src/main
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2021-10-16 10:30:43 +0000
committerPJ Fanning <fanningpj@apache.org>2021-10-16 10:30:43 +0000
commit0042a4717239718390a3e23e9bb1e38592f07186 (patch)
tree5371073df7ba3a6f67bbb7e05ea7125577cebd1e /poi-ooxml/src/main
parentdfbab3ff6af87898de6101ea827db7e75cecca61 (diff)
downloadpoi-0042a4717239718390a3e23e9bb1e38592f07186.tar.gz
poi-0042a4717239718390a3e23e9bb1e38592f07186.zip
record size of encrypted temp data
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894303 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml/src/main')
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/EncryptedTempFilePackagePart.java5
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/EncryptedTempData.java14
2 files changed, 13 insertions, 6 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/EncryptedTempFilePackagePart.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/EncryptedTempFilePackagePart.java
index a9119eaf42..a64326c32a 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/EncryptedTempFilePackagePart.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/EncryptedTempFilePackagePart.java
@@ -98,12 +98,9 @@ public final class EncryptedTempFilePackagePart extends PackagePart {
return tempFile.getOutputStream();
}
- /**
- * @return EncryptedTempData.getSize() always returns -1
- */
@Override
public long getSize() {
- return -1;
+ return tempFile.getByteCount();
}
@Override
diff --git a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/EncryptedTempData.java b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/EncryptedTempData.java
index 9f219f1a80..d0fe43a9c8 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/EncryptedTempData.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/EncryptedTempData.java
@@ -32,6 +32,7 @@ import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
import javax.crypto.spec.SecretKeySpec;
+import org.apache.commons.io.output.CountingOutputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.poifs.crypt.ChainingMode;
@@ -52,7 +53,8 @@ public class EncryptedTempData {
private final SecretKeySpec skeySpec;
private final byte[] ivBytes;
private final File tempFile;
-
+ private CountingOutputStream outputStream;
+
public EncryptedTempData() throws IOException {
SecureRandom sr = new SecureRandom();
ivBytes = new byte[16];
@@ -72,7 +74,8 @@ public class EncryptedTempData {
*/
public OutputStream getOutputStream() throws IOException {
Cipher ciEnc = CryptoFunctions.getCipher(skeySpec, cipherAlgorithm, ChainingMode.cbc, ivBytes, Cipher.ENCRYPT_MODE, PADDING);
- return new CipherOutputStream(new FileOutputStream(tempFile), ciEnc);
+ outputStream = new CountingOutputStream(new CipherOutputStream(new FileOutputStream(tempFile), ciEnc));
+ return outputStream;
}
/**
@@ -87,6 +90,13 @@ public class EncryptedTempData {
}
/**
+ * @return number of bytes stored in the temp data file (the number you should expect after you decrypt the data)
+ */
+ public long getByteCount() {
+ return outputStream == null ? 0 : outputStream.getByteCount();
+ }
+
+ /**
* Removes the temporarily backing file
*/
public void dispose() {