diff options
author | Ingo Klöcker <[email protected]> | 2023-06-19 14:31:17 +0000 |
---|---|---|
committer | Ingo Klöcker <[email protected]> | 2023-06-19 16:08:47 +0000 |
commit | c38b6200396f703917e4c66aca068f90cfbad325 (patch) | |
tree | bacb6cf68582d81a3c99addfd5a09e15158d94c9 /tests/run-encrypt.c | |
parent | qt: Add a generic hook to start a job (diff) | |
download | gpgme-c38b6200396f703917e4c66aca068f90cfbad325.tar.gz gpgme-c38b6200396f703917e4c66aca068f90cfbad325.zip |
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
Diffstat (limited to 'tests/run-encrypt.c')
-rw-r--r-- | tests/run-encrypt.c | 24 |
1 files changed, 21 insertions, 3 deletions
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); |