summaryrefslogtreecommitdiffstats
path: root/qpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2009-09-27 22:33:17 +0200
committerJay Berkenbilt <ejb@ql.org>2009-09-27 22:33:17 +0200
commit6bdac26369c0d770759c2b6ce24afef608a91ec9 (patch)
tree1f613435e319ffafec69bc1dfad5b14441cd0d42 /qpdf
parent8d7bb3ff50943fa51ac1d968930bd23071376904 (diff)
downloadqpdf-6bdac26369c0d770759c2b6ce24afef608a91ec9.tar.zst
finished testing C API
git-svn-id: svn+q:///qpdf/trunk@734 71b93d88-0707-0410-a8cf-f5a4172ac649
Diffstat (limited to 'qpdf')
-rw-r--r--qpdf/qpdf-ctest.c43
-rw-r--r--qpdf/qpdf.cc2
-rw-r--r--qpdf/qtest/qpdf.test25
-rw-r--r--qpdf/qtest/qpdf/c-decrypt-with-owner.pdfbin0 -> 9668 bytes
-rw-r--r--qpdf/qtest/qpdf/c-decrypt-with-user.pdfbin0 -> 9668 bytes
-rw-r--r--qpdf/qtest/qpdf/c-r2.pdfbin0 -> 9893 bytes
-rw-r--r--qpdf/qtest/qpdf/c-r3.pdfbin0 -> 9897 bytes
7 files changed, 69 insertions, 1 deletions
diff --git a/qpdf/qpdf-ctest.c b/qpdf/qpdf-ctest.c
index 456f06c6..42d8f9f4 100644
--- a/qpdf/qpdf-ctest.c
+++ b/qpdf/qpdf-ctest.c
@@ -159,6 +159,46 @@ static void test10(char const* infile,
report_errors();
}
+static void test11(char const* infile,
+ char const* password,
+ char const* outfile)
+{
+ qpdf_read(qpdf, infile, password);
+ qpdf_init_write(qpdf, outfile);
+ qpdf_set_static_ID(qpdf, QPDF_TRUE);
+ qpdf_set_r2_encryption_parameters(
+ qpdf, "user1", "owner1", QPDF_FALSE, QPDF_TRUE, QPDF_TRUE, QPDF_TRUE);
+ qpdf_write(qpdf);
+ report_errors();
+}
+
+static void test12(char const* infile,
+ char const* password,
+ char const* outfile)
+{
+ qpdf_read(qpdf, infile, password);
+ qpdf_init_write(qpdf, outfile);
+ qpdf_set_static_ID(qpdf, QPDF_TRUE);
+ qpdf_set_r3_encryption_parameters(
+ qpdf, "user2", "owner2", QPDF_TRUE, QPDF_TRUE,
+ QPDF_R3_PRINT_LOW, QPDF_R3_MODIFY_ALL);
+ qpdf_write(qpdf);
+ report_errors();
+}
+
+static void test13(char const* infile,
+ char const* password,
+ char const* outfile)
+{
+ qpdf_read(qpdf, infile, password);
+ printf("user password: %s\n", qpdf_get_user_password(qpdf));
+ qpdf_init_write(qpdf, outfile);
+ qpdf_set_static_ID(qpdf, QPDF_TRUE);
+ qpdf_set_preserve_encryption(qpdf, QPDF_FALSE);
+ qpdf_write(qpdf);
+ report_errors();
+}
+
int main(int argc, char* argv[])
{
char* whoami = 0;
@@ -202,6 +242,9 @@ int main(int argc, char* argv[])
(n == 8) ? test08 :
(n == 9) ? test09 :
(n == 10) ? test10 :
+ (n == 11) ? test11 :
+ (n == 12) ? test12 :
+ (n == 13) ? test13 :
0);
if (fn == 0)
diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc
index 9cd0df7b..cc65328f 100644
--- a/qpdf/qpdf.cc
+++ b/qpdf/qpdf.cc
@@ -472,7 +472,7 @@ int main(int argc, char* argv[])
// 1 2 3 4 5 6 7 8
// 12345678901234567890123456789012345678901234567890123456789012345678901234567890
std::cout
- << whoami << " version 2.0.6" << std::endl
+ << whoami << " version 2.1.a1" << std::endl
<< "Copyright (c) 2005-2009 Jay Berkenbilt"
<< std::endl
<< "This software may be distributed under the terms of version 2 of the"
diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test
index 70021676..8cf355b0 100644
--- a/qpdf/qtest/qpdf.test
+++ b/qpdf/qtest/qpdf.test
@@ -851,6 +851,31 @@ $td->runtest("invalid password",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
+my @cenc = (
+ [11, 'hybrid-xref.pdf', "''", 'r2', ""],
+ [12, 'hybrid-xref.pdf', "''", 'r3', ""],
+ [13, 'c-r2.pdf', 'user1', 'decrypt with user',
+ "user password: user1\n"],
+ [13, 'c-r3.pdf', 'owner2', 'decrypt with owner',
+ "user password: user2\n"],
+ );
+$n_tests += 2 * @cenc;
+
+foreach my $d (@cenc)
+{
+ my ($n, $infile, $pass, $description, $output) = @$d;
+ my $outfile = $description;
+ $outfile =~ s/ /-/g;
+ my $outfile = "c-$outfile.pdf";
+ $td->runtest("C API encryption: $description",
+ {$td->COMMAND => "qpdf-ctest $n $infile $pass a.pdf"},
+ {$td->STRING => $output, $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
+ $td->runtest("check $description",
+ {$td->FILE => "a.pdf"},
+ {$td->FILE => $outfile});
+}
+
# Test combinations of linearization and encryption. Note that we do
# content checks on encrypted and linearized files in various
# combinations below. Here we are just making sure that they are
diff --git a/qpdf/qtest/qpdf/c-decrypt-with-owner.pdf b/qpdf/qtest/qpdf/c-decrypt-with-owner.pdf
new file mode 100644
index 00000000..9a0f23b4
--- /dev/null
+++ b/qpdf/qtest/qpdf/c-decrypt-with-owner.pdf
Binary files differ
diff --git a/qpdf/qtest/qpdf/c-decrypt-with-user.pdf b/qpdf/qtest/qpdf/c-decrypt-with-user.pdf
new file mode 100644
index 00000000..9a0f23b4
--- /dev/null
+++ b/qpdf/qtest/qpdf/c-decrypt-with-user.pdf
Binary files differ
diff --git a/qpdf/qtest/qpdf/c-r2.pdf b/qpdf/qtest/qpdf/c-r2.pdf
new file mode 100644
index 00000000..0301696c
--- /dev/null
+++ b/qpdf/qtest/qpdf/c-r2.pdf
Binary files differ
diff --git a/qpdf/qtest/qpdf/c-r3.pdf b/qpdf/qtest/qpdf/c-r3.pdf
new file mode 100644
index 00000000..55493b2e
--- /dev/null
+++ b/qpdf/qtest/qpdf/c-r3.pdf
Binary files differ