static void pygpgme_context_dealloc(PyGpgmeContext *self) { gpgme_passphrase_cb_t passphrase_cb; gpgme_progress_cb_t progress_cb; PyObject *callback; if (self->ctx) { /* free the passphrase callback */ gpgme_get_passphrase_cb(self->ctx, &passphrase_cb, (void **)&callback); if (passphrase_cb == pygpgme_passphrase_cb) { Py_DECREF(callback); } /* free the progress callback */ gpgme_get_progress_cb(self->ctx, &progress_cb, (void **)&callback); if (progress_cb == pygpgme_progress_cb) { Py_DECREF(callback); } gpgme_release(self->ctx); } self->ctx = NULL; PyObject_Del(self); }
//note: passphrase callback seems broken for keygen SEXP R_gpg_keygen(SEXP params){ void * cb = NULL; gpgme_get_passphrase_cb(ctx, NULL, &cb); gpgme_set_passphrase_cb(ctx, NULL, NULL); const char * par = Rf_length(params) ? CHAR(STRING_ELT(params, 0)) : NULL; bail(gpgme_op_genkey(ctx, par, NULL, NULL), "generate key"); gpgme_genkey_result_t res = gpgme_op_genkey_result(ctx); gpgme_key_t key; bail(gpgme_get_key(ctx, res->fpr, &key, 0), "get new key"); gpgme_set_passphrase_cb(ctx, pwprompt, cb); return mkString(key->subkeys->keyid); }
static PyObject * pygpgme_context_get_passphrase_cb(PyGpgmeContext *self) { gpgme_passphrase_cb_t passphrase_cb; PyObject *callback; /* free the passphrase callback */ gpgme_get_passphrase_cb(self->ctx, &passphrase_cb, (void **)&callback); if (passphrase_cb == pygpgme_passphrase_cb) { Py_INCREF(callback); return callback; } else { Py_RETURN_NONE; } }
/* Generate the edit parameters needed for changing the passphrase. */ static struct edit_parms_s* gpa_gpgme_edit_passwd_parms_new (GpaContext *ctx, gpgme_data_t out) { struct edit_parms_s *edit_parms = g_malloc0 (sizeof (struct edit_parms_s)); struct passwd_parms_s *passwd_parms = g_malloc0 (sizeof (struct passwd_parms_s)); edit_parms->state = PASSWD_START; edit_parms->action = edit_passwd_fnc_action; edit_parms->transit = edit_passwd_fnc_transit; edit_parms->out = out; edit_parms->opaque = passwd_parms; gpgme_get_passphrase_cb (ctx->ctx, &passwd_parms->func, &passwd_parms->opaque); /* Make sure the cleanup is run when the edit completes */ edit_parms->signal_id = g_signal_connect (G_OBJECT (ctx), "done", G_CALLBACK (gpa_gpgme_edit_passwd_parms_release), edit_parms); return edit_parms; }
static int pygpgme_context_set_passphrase_cb(PyGpgmeContext *self, PyObject *value) { gpgme_passphrase_cb_t passphrase_cb; PyObject *callback; /* free the passphrase callback */ gpgme_get_passphrase_cb(self->ctx, &passphrase_cb, (void **)&callback); if (passphrase_cb == pygpgme_passphrase_cb) { Py_DECREF(callback); } /* callback of None == unset */ if (value == Py_None) value = NULL; if (value != NULL) { Py_INCREF(value); gpgme_set_passphrase_cb(self->ctx, pygpgme_passphrase_cb, value); } else { gpgme_set_passphrase_cb(self->ctx, NULL, NULL); } return 0; }