diff options
author | Yegor Kozlov <yegor@apache.org> | 2012-02-26 08:49:36 +0000 |
---|---|---|
committer | Yegor Kozlov <yegor@apache.org> | 2012-02-26 08:49:36 +0000 |
commit | a3ee22079cad3065349c57276dcfa31d731ad0a8 (patch) | |
tree | 3c542084b61f20dfe16d9bec4bbeaa6052c770fd /src/testcases | |
parent | a5375147a107d4df0d26ca997093c51d86ff3cff (diff) | |
download | poi-a3ee22079cad3065349c57276dcfa31d731ad0a8.tar.gz poi-a3ee22079cad3065349c57276dcfa31d731ad0a8.zip |
Bugzilla 52690 - added a getter for length of encrypted data in Ecma and Agile decryptors
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1293784 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases')
-rw-r--r-- | src/testcases/org/apache/poi/poifs/crypt/TestDecryptor.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/poifs/crypt/TestDecryptor.java b/src/testcases/org/apache/poi/poifs/crypt/TestDecryptor.java index 27385719c8..dcef8d31cd 100644 --- a/src/testcases/org/apache/poi/poifs/crypt/TestDecryptor.java +++ b/src/testcases/org/apache/poi/poifs/crypt/TestDecryptor.java @@ -20,7 +20,9 @@ import junit.framework.TestCase; import org.apache.poi.POIDataSamples; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import java.security.GeneralSecurityException; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -80,4 +82,36 @@ public class TestDecryptor extends TestCase { } } } + public void testDataLength() throws Exception { + POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.getPOIFSInstance().openResourceAsStream("protected_agile.docx")); + + EncryptionInfo info = new EncryptionInfo(fs); + + Decryptor d = Decryptor.getInstance(info); + + d.verifyPassword(Decryptor.DEFAULT_PASSWORD); + + InputStream is = d.getDataStream(fs); + + long len = d.getLength(); + assertEquals(12810, len); + + byte[] buf = new byte[(int)len]; + + is.read(buf); + + ZipInputStream zin = new ZipInputStream(new ByteArrayInputStream(buf)); + + while (true) { + ZipEntry entry = zin.getNextEntry(); + if (entry==null) { + break; + } + + while (zin.available()>0) { + zin.skip(zin.available()); + } + } + } + } |