From c38b6200396f703917e4c66aca068f90cfbad325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Mon, 19 Jun 2023 16:31:17 +0200 Subject: core: Support writing the sign/encrypt output directly to a file * src/engine-gpg.c (gpg_encrypt): Pass output file name to gpg if output has file name set. (gpg_encrypt_sign): Ditto. (gpg_sign): Ditto. * tests/run-encrypt.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-sign.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. -- This change makes it possible to tell gpg (and gpgtar) to write the output (i.e. the signed/encrypted data or the signature or the created archive) directly to a file with given file name instead of piping the output back to gpgme. GnuPG-bug-id: 6530 --- tests/run-encrypt.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'tests/run-encrypt.c') diff --git a/tests/run-encrypt.c b/tests/run-encrypt.c index 7266ba56..94a66283 100644 --- a/tests/run-encrypt.c +++ b/tests/run-encrypt.c @@ -152,6 +152,7 @@ show_usage (int ex) " --symmetric encrypt symmetric (OpenPGP only)\n" " --archive encrypt given file or directory into an archive\n" " --directory DIR switch to directory DIR before encrypting into an archive\n" + " --output FILE write output to FILE instead of stdout\n" " --diagnostics print diagnostics\n" " --cancel N cancel after N progress lines\n" , stderr); @@ -177,6 +178,7 @@ main (int argc, char **argv) int keycount = 0; char *keystring = NULL; const char *directory = NULL; + const char *output = NULL; int i; gpgme_encrypt_flags_t flags = GPGME_ENCRYPT_ALWAYS_TRUST; gpgme_off_t offset; @@ -294,6 +296,14 @@ main (int argc, char **argv) directory = *argv; argc--; argv++; } + else if (!strcmp (*argv, "--output")) + { + argc--; argv++; + if (!argc) + show_usage (1); + output = *argv; + argc--; argv++; + } else if (!strcmp (*argv, "--diagnostics")) { diagnostics = 1; @@ -410,6 +420,11 @@ main (int argc, char **argv) err = gpgme_data_new (&out); fail_if_err (err); + if (output) + { + err = gpgme_data_set_file_name (out, output); + fail_if_err (err); + } if (sign) err = gpgme_op_encrypt_sign_ext (ctx, keycount ? keys : NULL, keystring, @@ -451,9 +466,12 @@ main (int argc, char **argv) exit (1); } - fputs ("Begin Output:\n", stdout); - print_data (out); - fputs ("End Output.\n", stdout); + if (!output) + { + fputs ("Begin Output:\n", stdout); + print_data (out); + fputs ("End Output.\n", stdout); + } gpgme_data_release (out); gpgme_data_release (in); -- cgit v1.2.3