Example for GPGME function "gpgme_set_passphrase_cb" ?
Werner Koch
wk@gnupg.org
Tue Mar 5 16:36:01 2002
On Tue, 05 Mar 2002 16:00:24 +0100, Laurent Cheylus said:
> But I don't understand how to get the status of the passphrase entry. I
> have some code who works well when the passphrase is good but how get
> the status, if the passphrase is bad or missing ??
>From Sylpheed:
static const char *
passphrase_cb (void *opaque, const char *desc, void *r_hd)
{
struct passphrase_cb_info_s *info = opaque;
GpgmeCtx ctx = info ? info->c : NULL;
const char *pass;
if (!desc) {
/* FIXME: cleanup by looking at *r_hd */
return NULL;
}
g_message ("%% requesting passphrase for `%s': ", desc );
pass = gpgmegtk_passphrase_mbox (desc);
if (!pass) {
g_message ("%% cancel passphrase entry");
gpgme_cancel (ctx);
}
else
g_message ("%% sending passphrase");
return pass;
}
Somewhere in gpgmegtk_passphrase_mbox the window is created and the
displayed prompt varied by looking at the first line of the
description (TRY_AGAIN)
static GtkWidget *
create_description (const gchar *desc)
{
const gchar *cmd=NULL, *uid=NULL, *info=NULL;
gchar *buf;
GtkWidget *label;
cmd = desc;
uid = strchr (cmd, '\n');
if (uid) {
info = strchr (++uid, '\n');
if (info )
info++;
}
if (!uid)
uid = _("[no user id]");
if (!info)
info = "";
buf = g_strdup_printf (_("%sPlease enter the passphrase for:\n\n"
" %.*s \n"
"(%.*s)\n"),
!strncmp (cmd, "TRY_AGAIN", 9 ) ?
_("Bad passphrase! Try again...\n\n") : "",
linelen (uid), uid, linelen (info), info);
label = gtk_label_new (buf);
g_free (buf);
return label;
}
--
Werner Koch Omnis enim res, quae dando non deficit, dum habetur
g10 Code GmbH et non datur, nondum habetur, quomodo habenda est.
Privacy Solutions -- Augustinus