diff options
author | Werner Koch <[email protected]> | 2016-08-12 13:24:46 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2016-08-12 13:32:31 +0000 |
commit | fe1e8e71aa18b4ac6471292b2894b8859f42f7c8 (patch) | |
tree | cd9e70ab4b46ca79a74a54f976d36b17cc0d4d50 /src | |
parent | core: Add gpgme_data_set_flag to add more meta data to data objects. (diff) | |
download | gpgme-fe1e8e71aa18b4ac6471292b2894b8859f42f7c8.tar.gz gpgme-fe1e8e71aa18b4ac6471292b2894b8859f42f7c8.zip |
core: Make use of the "size-hint" in engine-gpg.
* src/engine-gpg.c: Include data.h.
(add_input_size_hint): New.
(gpg_decrypt, gpg_encrypt, gpg_encrypt_sign, gpg_sign)
(gpg_verify): Call new function,
* tests/run-encrypt.c (status_cb): Print to stderr.
(progress_cb): New.o
(main): Add option --progress. Print full-status lines. Provide a
size for the input data.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/engine-gpg.c | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/src/engine-gpg.c b/src/engine-gpg.c index efab80ac..3edac6ca 100644 --- a/src/engine-gpg.c +++ b/src/engine-gpg.c @@ -42,6 +42,7 @@ #include "priv-io.h" #include "sema.h" #include "debug.h" +#include "data.h" #include "engine-backend.h" @@ -1483,6 +1484,35 @@ start (engine_gpg_t gpg) } +/* Add the --input-size-hint option if requested. */ +static gpgme_error_t +add_input_size_hint (engine_gpg_t gpg, gpgme_data_t data) +{ + gpgme_error_t err; + gpgme_off_t value = _gpgme_data_get_size_hint (data); + char numbuf[50]; /* Large enough for even 2^128 in base-10. */ + char *p; + + if (!value || !have_gpg_version (gpg, "2.1.15")) + return 0; + + err = add_arg (gpg, "--input-size-hint"); + if (!err) + { + p = numbuf + sizeof numbuf; + *--p = 0; + do + { + *--p = '0' + (value % 10); + value /= 10; + } + while (value); + err = add_arg (gpg, p); + } + return err; +} + + static gpgme_error_t gpg_decrypt (void *engine, gpgme_data_t ciph, gpgme_data_t plain) { @@ -1499,6 +1529,8 @@ gpg_decrypt (void *engine, gpgme_data_t ciph, gpgme_data_t plain) if (!err) err = add_data (gpg, plain, 1, 1); if (!err) + err = add_input_size_hint (gpg, ciph); + if (!err) err = add_arg (gpg, "--"); if (!err) err = add_data (gpg, ciph, -1, 0); @@ -1764,6 +1796,8 @@ gpg_encrypt (void *engine, gpgme_key_t recp[], gpgme_encrypt_flags_t flags, err = add_arg (gpg, gpgme_data_get_file_name (plain)); } if (!err) + err = add_input_size_hint (gpg, plain); + if (!err) err = add_arg (gpg, "--"); if (!err) err = add_data (gpg, plain, -1, 0); @@ -1837,6 +1871,8 @@ gpg_encrypt_sign (void *engine, gpgme_key_t recp[], err = add_arg (gpg, gpgme_data_get_file_name (plain)); } if (!err) + err = add_input_size_hint (gpg, plain); + if (!err) err = add_arg (gpg, "--"); if (!err) err = add_data (gpg, plain, -1, 0); @@ -2291,7 +2327,7 @@ gpg_keylist_build_options (engine_gpg_t gpg, int secret_only, err = add_arg (gpg, "--with-colons"); /* Since gpg 2.1.15 fingerprints are always printed, thus there is - * no more need to explictly reqeust them. */ + * no more need to explictly request them. */ if (!have_gpg_version (gpg, "2.1.15")) { if (!err) @@ -2436,6 +2472,8 @@ gpg_sign (void *engine, gpgme_data_t in, gpgme_data_t out, /* Tell the gpg object about the data. */ if (!err) + err = add_input_size_hint (gpg, in); + if (!err) err = add_arg (gpg, "--"); if (!err) err = add_data (gpg, in, -1, 0); @@ -2481,11 +2519,12 @@ gpg_verify (void *engine, gpgme_data_t sig, gpgme_data_t signed_text, if (plaintext) { /* Normal or cleartext signature. */ - err = add_arg (gpg, "--output"); if (!err) err = add_arg (gpg, "-"); if (!err) + err = add_input_size_hint (gpg, sig); + if (!err) err = add_arg (gpg, "--"); if (!err) err = add_data (gpg, sig, -1, 0); @@ -2496,6 +2535,8 @@ gpg_verify (void *engine, gpgme_data_t sig, gpgme_data_t signed_text, { err = add_arg (gpg, "--verify"); if (!err) + err = add_input_size_hint (gpg, signed_text); + if (!err) err = add_arg (gpg, "--"); if (!err) err = add_data (gpg, sig, -1, 0); |