aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorIngo Klöcker <[email protected]>2023-12-19 10:26:15 +0000
committerIngo Klöcker <[email protected]>2023-12-19 12:12:59 +0000
commit5efd3486a9fa9f4b0f383aca2f2f01412e73237c (patch)
tree01d62e7da673d239c19b0e221cfc919da8b1aa0d /tests
parentcore: Support direct signing of file with gpg (diff)
downloadgpgme-5efd3486a9fa9f4b0f383aca2f2f01412e73237c.tar.gz
gpgme-5efd3486a9fa9f4b0f383aca2f2f01412e73237c.zip
core: Support writing the decrypt/verify output directly to a fileikloecker/t6550
* src/engine-gpg.c (gpg_decrypt): Pass output file name to gpg if output has file name set. (gpg_verify): Ditto. * tests/run-decrypt.c (show_usage): New option --output. (main): Parse new option. Set file name on output if --output is given. Do not print output if --output is given. * tests/run-verify.c (show_usage): New option --output. (main): Parse new option. Set file name on output if --output is given. -- This change makes it possible to tell gpg to write the output (i.e. the decrypted/verified data) directly to a file with given file name instead of piping the output back to gpgme. GnuPG-bug-id: 6550
Diffstat (limited to 'tests')
-rw-r--r--tests/run-decrypt.c33
-rw-r--r--tests/run-verify.c27
2 files changed, 55 insertions, 5 deletions
diff --git a/tests/run-decrypt.c b/tests/run-decrypt.c
index de082d6f..0e38e0d3 100644
--- a/tests/run-decrypt.c
+++ b/tests/run-decrypt.c
@@ -91,6 +91,7 @@ show_usage (int ex)
" --unwrap remove only the encryption layer\n"
" --large-buffers use large I/O buffer\n"
" --sensitive mark data objects as sensitive\n"
+ " --output FILE write output to FILE instead of stdout\n"
" --archive extract files from an encrypted archive\n"
" --directory DIR extract the files into the directory DIR\n"
" --diagnostics print diagnostics\n"
@@ -116,6 +117,7 @@ main (int argc, char **argv)
int export_session_key = 0;
const char *override_session_key = NULL;
const char *request_origin = NULL;
+ const char *output = NULL;
const char *directory = NULL;
int no_symkey_cache = 0;
int ignore_mdc_error = 0;
@@ -210,6 +212,14 @@ main (int argc, char **argv)
raw_output = 1;
argc--; argv++;
}
+ else if (!strcmp (*argv, "--output"))
+ {
+ argc--; argv++;
+ if (!argc)
+ show_usage (1);
+ output = *argv;
+ argc--; argv++;
+ }
else if (!strcmp (*argv, "--archive"))
{
flags |= GPGME_DECRYPT_ARCHIVE;
@@ -341,6 +351,16 @@ main (int argc, char **argv)
gpgme_strerror (err));
exit (1);
}
+ if (output && !(flags & GPGME_DECRYPT_ARCHIVE))
+ {
+ err = gpgme_data_set_file_name (out, output);
+ if (err)
+ {
+ fprintf (stderr, PGM ": error setting file name (out): %s\n",
+ gpgme_strerror (err));
+ exit (1);
+ }
+ }
if (directory && (flags & GPGME_DECRYPT_ARCHIVE))
{
err = gpgme_data_set_file_name (out, directory);
@@ -407,11 +427,14 @@ main (int argc, char **argv)
{
if (!raw_output)
print_result (result);
- if (!raw_output)
- fputs ("Begin Output:\n", stdout);
- print_data (out);
- if (!raw_output)
- fputs ("End Output.\n", stdout);
+ if (!output)
+ {
+ if (!raw_output)
+ fputs ("Begin Output:\n", stdout);
+ print_data (out);
+ if (!raw_output)
+ fputs ("End Output.\n", stdout);
+ }
}
gpgme_data_release (out);
diff --git a/tests/run-verify.c b/tests/run-verify.c
index dba45557..9f32fce9 100644
--- a/tests/run-verify.c
+++ b/tests/run-verify.c
@@ -236,6 +236,7 @@ show_usage (int ex)
" --repeat N repeat the operation N times\n"
" --auto-key-retrieve\n"
" --auto-key-import\n"
+ " --output FILE write output to FILE instead of stdout\n"
" --archive extract files from a signed archive FILE\n"
" --directory DIR extract the files into the directory DIR\n"
" --diagnostics print diagnostics\n"
@@ -254,6 +255,7 @@ main (int argc, char **argv)
gpgme_verify_flags_t flags = 0;
int print_status = 0;
const char *sender = NULL;
+ const char *output = NULL;
const char *directory = NULL;
int auto_key_retrieve = 0;
int auto_key_import = 0;
@@ -327,6 +329,14 @@ main (int argc, char **argv)
auto_key_import = 1;
argc--; argv++;
}
+ else if (!strcmp (*argv, "--output"))
+ {
+ argc--; argv++;
+ if (!argc)
+ show_usage (1);
+ output = *argv;
+ argc--; argv++;
+ }
else if (!strcmp (*argv, "--archive"))
{
flags |= GPGME_VERIFY_ARCHIVE;
@@ -484,6 +494,23 @@ main (int argc, char **argv)
}
}
+ if (output && !(flags & GPGME_VERIFY_ARCHIVE))
+ {
+ err = gpgme_data_new (&out);
+ if (err)
+ {
+ fprintf (stderr, PGM ": error allocating data object: %s\n",
+ gpgme_strerror (err));
+ exit (1);
+ }
+ err = gpgme_data_set_file_name (out, output);
+ if (err)
+ {
+ fprintf (stderr, PGM ": error setting file name (out): %s\n",
+ gpgme_strerror (err));
+ exit (1);
+ }
+ }
if (directory && (flags & GPGME_VERIFY_ARCHIVE))
{
err = gpgme_data_new (&out);