tests: Allow using run-sign to test loopback pinentry problems.

* tests/run-sign.c: Add options --status and --loopback.
This commit is contained in:
Werner Koch 2015-08-25 09:05:27 +02:00
parent ad46f4f655
commit 491fcd91b8
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -36,6 +36,14 @@
static int verbose; 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);
return 0;
}
static void static void
print_result (gpgme_sign_result_t result, gpgme_sig_mode_t type) print_result (gpgme_sign_result_t result, gpgme_sig_mode_t type)
@ -67,9 +75,11 @@ show_usage (int ex)
fputs ("usage: " PGM " [options] FILE\n\n" fputs ("usage: " PGM " [options] FILE\n\n"
"Options:\n" "Options:\n"
" --verbose run in verbose mode\n" " --verbose run in verbose mode\n"
" --status print status lines from the backend\n"
" --openpgp use the OpenPGP protocol (default)\n" " --openpgp use the OpenPGP protocol (default)\n"
" --cms use the CMS protocol\n" " --cms use the CMS protocol\n"
" --uiserver use the UI server\n" " --uiserver use the UI server\n"
" --loopback use a loopback pinentry\n"
" --key NAME use key NAME for signing\n" " --key NAME use key NAME for signing\n"
, stderr); , stderr);
exit (ex); exit (ex);
@ -87,6 +97,8 @@ main (int argc, char **argv)
gpgme_sig_mode_t sigmode = GPGME_SIG_MODE_NORMAL; gpgme_sig_mode_t sigmode = GPGME_SIG_MODE_NORMAL;
gpgme_data_t in, out; gpgme_data_t in, out;
gpgme_sign_result_t result; gpgme_sign_result_t result;
int print_status = 0;
int use_loopback = 0;
if (argc) if (argc)
{ argc--; argv++; } { argc--; argv++; }
@ -106,6 +118,11 @@ main (int argc, char **argv)
verbose = 1; verbose = 1;
argc--; argv++; argc--; argv++;
} }
else if (!strcmp (*argv, "--status"))
{
print_status = 1;
argc--; argv++;
}
else if (!strcmp (*argv, "--openpgp")) else if (!strcmp (*argv, "--openpgp"))
{ {
protocol = GPGME_PROTOCOL_OpenPGP; protocol = GPGME_PROTOCOL_OpenPGP;
@ -129,6 +146,11 @@ main (int argc, char **argv)
key_string = *argv; key_string = *argv;
argc--; argv++; argc--; argv++;
} }
else if (!strcmp (*argv, "--loopback"))
{
use_loopback = 1;
argc--; argv++;
}
else if (!strncmp (*argv, "--", 2)) else if (!strncmp (*argv, "--", 2))
show_usage (1); show_usage (1);
@ -149,6 +171,10 @@ main (int argc, char **argv)
fail_if_err (err); fail_if_err (err);
gpgme_set_protocol (ctx, protocol); gpgme_set_protocol (ctx, protocol);
gpgme_set_armor (ctx, 1); gpgme_set_armor (ctx, 1);
if (print_status)
gpgme_set_status_cb (ctx, status_cb, NULL);
if (use_loopback)
gpgme_set_pinentry_mode (ctx, GPGME_PINENTRY_MODE_LOOPBACK);
if (key_string) if (key_string)
{ {