diff options
author | Werner Koch <[email protected]> | 2017-03-24 13:36:54 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2017-03-24 14:17:23 +0000 |
commit | 6ac1f2cdedb085b4ac9372c1e591497e2e618de4 (patch) | |
tree | e022c038fd965e40e4d7a9a4db6015a86d0e60a5 /tests/run-decrypt.c | |
parent | qt: Add test for Data::toKeys (diff) | |
download | gpgme-6ac1f2cdedb085b4ac9372c1e591497e2e618de4.tar.gz gpgme-6ac1f2cdedb085b4ac9372c1e591497e2e618de4.zip |
core: New flags GPGME_DECRYPT_UNWRAP and GPGME_ENCRYPT_WRAP.
* src/gpgme.h.in (GPGME_ENCRYPT_WRAP): New const.
(gpgme_decrypt_flags_t): New enum.
(GPGME_DECRYPT_VERIFY): New const
(GPGME_DECRYPT_UNWRAP): New const
(gpgme_op_decrypt_ext_start): New func.
(gpgme_op_decrypt_ext): New func.
* src/decrypt-verify.c (gpgme_op_decrypt_ext_start): New.
(gpgme_op_decrypt_ext): New.
(decrypt_verify_start): Add arg FLAGS. Replace call to
engine_op_decrypt_verify by the plain decrypt with the flag set.
(gpgme_op_decrypt_verify_start): Pass the flag.
(gpgme_op_decrypt_verify): Pass the flag.
* src/decrypt.c (decrypt_start): Rename to ...
(_gpgme_decrypt_start): this. Add arg FLAGS. Pass FLAGS to
engine_op_decrypt.
(gpgme_op_decrypt_start): Adjust for chnage pass 0 for FLAG.
(gpgme_op_decrypt_start): Ditto.
* src/engine.c (_gpgme_engine_op_decrypt_verify): Remove.
(_gpgme_engine_op_decrypt): Add arg FLAGS.
* src/gpgme.def, src/libgpgme.vers: Add new functions.
* src/engine-backend.h (struct engine_ops): Remove member
'decrypt_verify'. Add FLAGS to 'decrypt'. Adjust all initialization.
* src/engine-uiserver.c (uiserver_decrypt): Remove.
(uiserver_decrypt_verify): Remove.
(_uiserver_decrypt): Rename to ...
(uiserver_decrypt): this. Replace arg VERIFY by new arg FLAGS.
* src/engine-gpg.c (gpg_decrypt): Support GPGME_DECRYPT_UNWRAP.
(gpg_encrypt): Support GPGME_ENCRYPT_WRAP.
* tests/run-decrypt.c (main): New option --unwrap.
* tests/run-encrypt.c (main): New option --wrap.
--
Manual testing of that wrap/unwrap feature can be done this way:
./run-encrypt --verbose --key Alice /etc/motd > x
./run-decrypt --verbose --unwrap x > y
./run-encrypt --verbose --key Bob --wrap y > z
1. The message was first encrypted to Alice.
2. Alice decrypts the message receiving a valid OpenPGP message.
3. Alice encrypt that message to Bob
This will also work with encrypted and signed messages; the signature
will be kept intact during re-encryption. Requires GnuPG 2.1.12.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'tests/run-decrypt.c')
-rw-r--r-- | tests/run-decrypt.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/run-decrypt.c b/tests/run-decrypt.c index 8bcca0e5..0fcacf88 100644 --- a/tests/run-decrypt.c +++ b/tests/run-decrypt.c @@ -80,6 +80,7 @@ show_usage (int ex) " --cms use the CMS protocol\n" " --export-session-key show the session key\n" " --override-session-key STRING use STRING as session key\n" + " --unwrap remove only the encryption layer\n" , stderr); exit (ex); } @@ -92,6 +93,7 @@ main (int argc, char **argv) gpgme_error_t err; gpgme_ctx_t ctx; gpgme_protocol_t protocol = GPGME_PROTOCOL_OpenPGP; + gpgme_decrypt_flags_t flags = 0; FILE *fp_in = NULL; gpgme_data_t in = NULL; gpgme_data_t out = NULL; @@ -99,6 +101,7 @@ main (int argc, char **argv) int print_status = 0; int export_session_key = 0; const char *override_session_key = NULL; + int raw_output = 0; if (argc) { argc--; argv++; } @@ -146,6 +149,12 @@ main (int argc, char **argv) override_session_key = *argv; argc--; argv++; } + else if (!strcmp (*argv, "--unwrap")) + { + flags |= GPGME_DECRYPT_UNWRAP; + raw_output = 1; + argc--; argv++; + } else if (!strncmp (*argv, "--", 2)) show_usage (1); @@ -211,7 +220,7 @@ main (int argc, char **argv) exit (1); } - err = gpgme_op_decrypt (ctx, in, out); + err = gpgme_op_decrypt_ext (ctx, flags, in, out); result = gpgme_op_decrypt_result (ctx); if (err) { @@ -220,8 +229,13 @@ main (int argc, char **argv) } if (result) { - print_result (result); + 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); } gpgme_data_release (out); |