summaryrefslogtreecommitdiffstats
path: root/qpdf/test_driver.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2012-12-30 03:31:21 +0100
committerJay Berkenbilt <ejb@ql.org>2012-12-31 16:32:32 +0100
commite57c25814e49b82863753894ee7d97c18e4c4525 (patch)
tree232c2b8501849c5ce9bffc2c6c4bfd861ddd5a42 /qpdf/test_driver.cc
parent93ac1695a4b79f3d5b71e2d57ed876c28866d2c9 (diff)
downloadqpdf-e57c25814e49b82863753894ee7d97c18e4c4525.tar.zst
Support for encryption with /V=5 and /R=5 and /R=6
Read and write support is implemented for /V=5 with /R=5 as well as /R=6. /R=5 is the deprecated encryption method used by Acrobat IX. /R=6 is the encryption method used by PDF 2.0 from ISO 32000-2.
Diffstat (limited to 'qpdf/test_driver.cc')
-rw-r--r--qpdf/test_driver.cc66
1 files changed, 65 insertions, 1 deletions
diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc
index 2ad7655d..45190042 100644
--- a/qpdf/test_driver.cc
+++ b/qpdf/test_driver.cc
@@ -112,7 +112,12 @@ void runtest(int n, char const* filename1, char const* arg2)
{
pdf.setAttemptRecovery(false);
}
- if (n % 2 == 0)
+ if ((n == 35) && (arg2 != 0))
+ {
+ // arg2 is password
+ pdf.processFile(filename1, arg2);
+ }
+ else if (n % 2 == 0)
{
if (n % 4 == 0)
{
@@ -1150,6 +1155,65 @@ void runtest(int n, char const* filename1, char const* arg2)
<< "extension level: " << pdf.getExtensionLevel() << std::endl
<< pdf.getRoot().getKey("/Extensions").unparse() << std::endl;
}
+ else if (n == 35)
+ {
+ // Extract attachments
+
+ std::map<std::string, PointerHolder<Buffer> > attachments;
+ QPDFObjectHandle root = pdf.getRoot();
+ QPDFObjectHandle names = root.getKey("/Names");
+ QPDFObjectHandle embeddedFiles = names.getKey("/EmbeddedFiles");
+ names = embeddedFiles.getKey("/Names");
+ for (int i = 0; i < names.getArrayNItems(); ++i)
+ {
+ QPDFObjectHandle item = names.getArrayItem(i);
+ if (item.isDictionary() &&
+ item.getKey("/Type").isName() &&
+ (item.getKey("/Type").getName() == "/Filespec") &&
+ item.getKey("/EF").isDictionary() &&
+ item.getKey("/EF").getKey("/F").isStream())
+ {
+ std::string filename = item.getKey("/F").getStringValue();
+ QPDFObjectHandle stream = item.getKey("/EF").getKey("/F");
+ attachments[filename] = stream.getStreamData();
+ }
+ }
+ for (std::map<std::string, PointerHolder<Buffer> >::iterator iter =
+ attachments.begin(); iter != attachments.end(); ++iter)
+ {
+ std::string const& filename = (*iter).first;
+ std::string data = std::string(
+ (char const*)(*iter).second->getBuffer(),
+ (*iter).second->getSize());
+ bool is_binary = false;
+ for (size_t i = 0; i < data.size(); ++i)
+ {
+ if (data[i] < 0)
+ {
+ is_binary = true;
+ break;
+ }
+ }
+ if (is_binary)
+ {
+ std::string t;
+ for (size_t i = 0; i < std::min(data.size(), (size_t)20); ++i)
+ {
+ if ((data[i] >= 32) && (data[i] <= 126))
+ {
+ t += data[i];
+ }
+ else
+ {
+ t += ".";
+ }
+ }
+ t += " (" + QUtil::int_to_string(data.size()) + " bytes)";
+ data = t;
+ }
+ std::cout << filename << ":\n" << data << "--END--\n";
+ }
+ }
else
{
throw std::runtime_error(std::string("invalid test ") +