aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2023-12-23 00:14:11 +0100
committerJay Berkenbilt <ejb@ql.org>2023-12-23 02:10:18 +0100
commit7d7e2234a537b6cd2205fb5cf942d5a9e8a866e3 (patch)
treefc4553803a5510c0e2793cc57d055dd5459e2ff6 /qpdf
parent1173a0bdfc56a08eedafc06afcd37f0b35ac3ea2 (diff)
downloadqpdf-7d7e2234a537b6cd2205fb5cf942d5a9e8a866e3.tar.zst
Implement new --encrypt args and completion (fixes #784)
Positional arguments are supported in a backward-compatible way, but completion no longer guides users to it.
Diffstat (limited to 'qpdf')
-rw-r--r--qpdf/qtest/arg-parsing.test18
-rw-r--r--qpdf/qtest/completion.test19
-rw-r--r--qpdf/qtest/qpdf/completion-encrypt-zsh.out6
-rw-r--r--qpdf/qtest/qpdf/completion-encrypt.out7
-rw-r--r--qpdf/qtest/qpdf/completion-quoting.out2
-rw-r--r--qpdf/qtest/qpdf/encrypt-u2
6 files changed, 37 insertions, 17 deletions
diff --git a/qpdf/qtest/arg-parsing.test b/qpdf/qtest/arg-parsing.test
index ad6bc0d2..2f6bf621 100644
--- a/qpdf/qtest/arg-parsing.test
+++ b/qpdf/qtest/arg-parsing.test
@@ -15,7 +15,7 @@ cleanup();
my $td = new TestDriver('arg-parsing');
-my $n_tests = 17;
+my $n_tests = 21;
$td->runtest("required argument",
{$td->COMMAND => "qpdf --password minimal.pdf"},
@@ -108,5 +108,21 @@ $td->runtest("empty and replace-input",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
+# Disallow mixing positional and flag-style encryption arguments.
+my @bad_enc = (
+ "u --owner-password=x",
+ "u o --bits=128",
+ "--user-password=u o",
+ "--user-password=u --owner-password=o 256",
+ );
+foreach my $arg (@bad_enc)
+{
+ $td->runtest("mixed encryption args ($arg)",
+ {$td->COMMAND => "qpdf --encrypt $arg"},
+ {$td->REGEXP => ".*positional and dashed encryption arguments may not be mixed",
+ $td->EXIT_STATUS => 2},
+ $td->NORMALIZE_NEWLINES);
+}
+
cleanup();
$td->report($n_tests);
diff --git a/qpdf/qtest/completion.test b/qpdf/qtest/completion.test
index cb11fd3f..4d0fcd5d 100644
--- a/qpdf/qtest/completion.test
+++ b/qpdf/qtest/completion.test
@@ -29,14 +29,7 @@ my @completion_tests = (
['qpdf ', undef, 'top'],
['qpdf -', undef, 'top-arg'],
['qpdf --enc', undef, 'enc'],
- ['qpdf --encrypt ', undef, 'encrypt'],
- ['qpdf --encrypt u ', undef, 'encrypt-u'],
- ['qpdf --encrypt u o ', undef, 'encrypt-u-o'],
- ['qpdf @encrypt-u o ', undef, 'encrypt-u-o'],
- ['qpdf --encrypt u o 40 --', undef, 'encrypt-40'],
- ['qpdf --encrypt u o 128 --', undef, 'encrypt-128'],
- ['qpdf --encrypt u o 256 --', undef, 'encrypt-256'],
- ['qpdf --encrypt u o bad --', undef, 'encrypt-bad'],
+ ['qpdf --encrypt -', undef, 'encrypt'],
['qpdf --split-pag', undef, 'split'],
['qpdf --decode-l', undef, 'decode-l'],
['qpdf --decode-lzzz', 15, 'decode-l'],
@@ -44,11 +37,11 @@ my @completion_tests = (
['qpdf --decode-level=g', undef, 'decode-level-g'],
['qpdf --check -', undef, 'later-arg'],
['qpdf infile outfile oops --ch', undef, 'usage-empty'],
- ['qpdf --encrypt \'user " password\' ', undef, 'quoting'],
- ['qpdf --encrypt \'user password\' ', undef, 'quoting'],
- ['qpdf --encrypt "user password" ', undef, 'quoting'],
- ['qpdf --encrypt "user pass\'word" ', undef, 'quoting'],
- ['qpdf --encrypt user\ password ', undef, 'quoting'],
+ ['qpdf \'input " file\' --q', undef, 'quoting'],
+ ['qpdf \'input file\' --q', undef, 'quoting'],
+ ['qpdf "input file" --q', undef, 'quoting'],
+ ['qpdf "input fi\'le" --q', undef, 'quoting'],
+ ['qpdf input\ file --q', undef, 'quoting'],
);
my $n_tests = 2 * scalar(@completion_tests);
my $completion_filter =
diff --git a/qpdf/qtest/qpdf/completion-encrypt-zsh.out b/qpdf/qtest/qpdf/completion-encrypt-zsh.out
new file mode 100644
index 00000000..45f12a69
--- /dev/null
+++ b/qpdf/qtest/qpdf/completion-encrypt-zsh.out
@@ -0,0 +1,6 @@
+--bits=128
+--bits=256
+--bits=40
+--owner-password=
+--user-password=
+!--print
diff --git a/qpdf/qtest/qpdf/completion-encrypt.out b/qpdf/qtest/qpdf/completion-encrypt.out
index 4577a128..c9ccf27b 100644
--- a/qpdf/qtest/qpdf/completion-encrypt.out
+++ b/qpdf/qtest/qpdf/completion-encrypt.out
@@ -1,2 +1,7 @@
-user-password
+--bits=
+--owner-password=
+--user-password=
+!--bits=128
+!--bits=256
+!--bits=40
!--print
diff --git a/qpdf/qtest/qpdf/completion-quoting.out b/qpdf/qtest/qpdf/completion-quoting.out
index 0d8a0622..1d2dfbe8 100644
--- a/qpdf/qtest/qpdf/completion-quoting.out
+++ b/qpdf/qtest/qpdf/completion-quoting.out
@@ -1 +1 @@
-owner-password
+--qdf
diff --git a/qpdf/qtest/qpdf/encrypt-u b/qpdf/qtest/qpdf/encrypt-u
index 9d413960..b9581e93 100644
--- a/qpdf/qtest/qpdf/encrypt-u
+++ b/qpdf/qtest/qpdf/encrypt-u
@@ -1,2 +1,2 @@
--encrypt
-u
+--bits=2