aboutsummaryrefslogtreecommitdiffstats
path: root/tests/run-encrypt.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2016-08-12 13:24:46 +0000
committerWerner Koch <[email protected]>2016-08-12 13:32:31 +0000
commitfe1e8e71aa18b4ac6471292b2894b8859f42f7c8 (patch)
treecd9e70ab4b46ca79a74a54f976d36b17cc0d4d50 /tests/run-encrypt.c
parentcore: Add gpgme_data_set_flag to add more meta data to data objects. (diff)
downloadgpgme-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 'tests/run-encrypt.c')
-rw-r--r--tests/run-encrypt.c69
1 files changed, 67 insertions, 2 deletions
diff --git a/tests/run-encrypt.c b/tests/run-encrypt.c
index 210f88ab..b94b0288 100644
--- a/tests/run-encrypt.c
+++ b/tests/run-encrypt.c
@@ -36,16 +36,33 @@
static int verbose;
+
static gpg_error_t
status_cb (void *opaque, const char *keyword, const char *value)
{
(void)opaque;
- printf ("status_cb: %s %s\n", keyword, value);
+ fprintf (stderr, "status_cb: %s %s\n", nonnull(keyword), nonnull(value));
return 0;
}
static void
+progress_cb (void *opaque, const char *what, int type, int current, int total)
+{
+ (void)opaque;
+ (void)type;
+
+ if (total)
+ fprintf (stderr, "progress for '%s' %u%% (%d of %d)\n",
+ nonnull (what),
+ (unsigned)(((double)current / total) * 100), current, total);
+ else
+ fprintf (stderr, "progress for '%s' %d\n", nonnull(what), current);
+ fflush (stderr);
+}
+
+
+static void
print_result (gpgme_encrypt_result_t result)
{
gpgme_invalid_key_t invkey;
@@ -65,6 +82,7 @@ show_usage (int ex)
"Options:\n"
" --verbose run in verbose mode\n"
" --status print status lines from the backend\n"
+ " --progress print progress info\n"
" --openpgp use the OpenPGP protocol (default)\n"
" --cms use the CMS protocol\n"
" --uiserver use the UI server\n"
@@ -87,12 +105,14 @@ main (int argc, char **argv)
gpgme_data_t in, out;
gpgme_encrypt_result_t result;
int print_status = 0;
+ int print_progress = 0;
int use_loopback = 0;
char *keyargs[10];
gpgme_key_t keys[10+1];
int keycount = 0;
int i;
gpgme_encrypt_flags_t flags = GPGME_ENCRYPT_ALWAYS_TRUST;
+ gpgme_off_t offset;
if (argc)
{ argc--; argv++; }
@@ -120,6 +140,11 @@ main (int argc, char **argv)
print_status = 1;
argc--; argv++;
}
+ else if (!strcmp (*argv, "--progress"))
+ {
+ print_progress = 1;
+ argc--; argv++;
+ }
else if (!strcmp (*argv, "--openpgp"))
{
protocol = GPGME_PROTOCOL_OpenPGP;
@@ -179,7 +204,12 @@ main (int argc, char **argv)
gpgme_set_protocol (ctx, protocol);
gpgme_set_armor (ctx, 1);
if (print_status)
- gpgme_set_status_cb (ctx, status_cb, NULL);
+ {
+ gpgme_set_status_cb (ctx, status_cb, NULL);
+ gpgme_set_ctx_flag (ctx, "full-status", "1");
+ }
+ if (print_progress)
+ gpgme_set_progress_cb (ctx, progress_cb, NULL);
if (use_loopback)
{
gpgme_set_pinentry_mode (ctx, GPGME_PINENTRY_MODE_LOOPBACK);
@@ -200,6 +230,41 @@ main (int argc, char **argv)
*argv, gpg_strerror (err));
exit (1);
}
+ offset = gpgme_data_seek (in, 0, SEEK_END);
+ if (offset == (gpgme_off_t)(-1))
+ {
+ err = gpg_error_from_syserror ();
+ fprintf (stderr, PGM ": error seeking `%s': %s\n",
+ *argv, gpg_strerror (err));
+ exit (1);
+ }
+ if (gpgme_data_seek (in, 0, SEEK_SET) == (gpgme_off_t)(-1))
+ {
+ err = gpg_error_from_syserror ();
+ fprintf (stderr, PGM ": error seeking `%s': %s\n",
+ *argv, gpg_strerror (err));
+ exit (1);
+ }
+ {
+ char numbuf[50];
+ char *p;
+
+ p = numbuf + sizeof numbuf;
+ *--p = 0;
+ do
+ {
+ *--p = '0' + (offset % 10);
+ offset /= 10;
+ }
+ while (offset);
+ err = gpgme_data_set_flag (in, "size-hint", p);
+ if (err)
+ {
+ fprintf (stderr, PGM ": error setting size-hint for `%s': %s\n",
+ *argv, gpg_strerror (err));
+ exit (1);
+ }
+ }
err = gpgme_data_new (&out);
fail_if_err (err);