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 --- src/engine-gpg.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/engine-gpg.c b/src/engine-gpg.c index 03e648f3..ba45e55a 100644 --- a/src/engine-gpg.c +++ b/src/engine-gpg.c @@ -2367,9 +2367,17 @@ gpg_encrypt (void *engine, gpgme_key_t recp[], const char *recpstring, if (!err) err = add_arg (gpg, "--output"); if (!err) - err = add_arg (gpg, "-"); - if (!err) - err = add_data (gpg, ciph, 1, 1); + { + const char *output = gpgme_data_get_file_name (ciph); + if (output) + err = add_arg (gpg, output); + else + { + err = add_arg (gpg, "-"); + if (!err) + err = add_data (gpg, ciph, 1, 1); + } + } if (gpg->flags.use_gpgtar) { const char *file_name = gpgme_data_get_file_name (plain); @@ -2479,9 +2487,17 @@ gpg_encrypt_sign (void *engine, gpgme_key_t recp[], if (!err) err = add_arg (gpg, "--output"); if (!err) - err = add_arg (gpg, "-"); - if (!err) - err = add_data (gpg, ciph, 1, 1); + { + const char *output = gpgme_data_get_file_name (ciph); + if (output) + err = add_arg (gpg, output); + else + { + err = add_arg (gpg, "-"); + if (!err) + err = add_data (gpg, ciph, 1, 1); + } + } if (gpg->flags.use_gpgtar) { const char *file_name = gpgme_data_get_file_name (plain); @@ -3559,6 +3575,7 @@ gpg_sign (void *engine, gpgme_data_t in, gpgme_data_t out, { engine_gpg_t gpg = engine; gpgme_error_t err; + const char *output = NULL; (void)include_certs; @@ -3599,6 +3616,17 @@ gpg_sign (void *engine, gpgme_data_t in, gpgme_data_t out, if (!err) err = append_args_from_sig_notations (gpg, ctx, NOTATION_FLAG_SIG); + if (!err) + { + output = gpgme_data_get_file_name (out); + if (output) + { + err = add_arg (gpg, "--output"); + if (!err) + err = add_arg (gpg, output); + } + } + /* Tell the gpg object about the data. */ if (gpg->flags.use_gpgtar) { @@ -3634,7 +3662,7 @@ gpg_sign (void *engine, gpgme_data_t in, gpgme_data_t out, err = add_data (gpg, in, -1, 0); } - if (!err) + if (!err && !output) err = add_data (gpg, out, 1, 1); if (!err) -- cgit v1.2.3