Changeset View
Changeset View
Standalone View
Standalone View
g10/delkey.c
Context not available. | |||||
#include "../common/i18n.h" | #include "../common/i18n.h" | ||||
#include "call-agent.h" | #include "call-agent.h" | ||||
static gpg_error_t | |||||
agent_delete_secret_key (ctrl_t ctrl, PKT_public_key *pk) | |||||
{ | |||||
gpg_error_t err; | |||||
char *prompt; | |||||
char *hexgrip; | |||||
if (agent_probe_secret_key (NULL, pk)) | |||||
return gpg_error (GPG_ERR_NO_SECKEY); | |||||
prompt = gpg_format_keydesc (ctrl, pk, FORMAT_KEYDESC_DELKEY, 1); | |||||
err = hexkeygrip_from_pk (pk, &hexgrip); | |||||
/* NB: We require --yes to advise the agent not to request a confirmation. | |||||
* The rationale for this extra pre-caution is that since 2.1 the secret key | |||||
* may also be used for other protocols and thus deleting it from the gpg | |||||
* would also delete the key for other tools. */ | |||||
if (!err && !opt.dry_run) | |||||
err = agent_delete_key (NULL, hexgrip, prompt, opt.answer_yes); | |||||
xfree (prompt); | |||||
xfree (hexgrip); | |||||
return err; | |||||
} | |||||
/**************** | /**************** | ||||
* Delete a public or secret key from a keyring. | * Delete a public or secret key from a keyring. | ||||
Context not available. | |||||
{ | { | ||||
if (secret) | if (secret) | ||||
{ | { | ||||
char *prompt; | |||||
gpg_error_t firsterr = 0; | gpg_error_t firsterr = 0; | ||||
char *hexgrip; | |||||
setup_main_keyids (keyblock); | setup_main_keyids (keyblock); | ||||
for (kbctx=NULL; (node = walk_kbnode (keyblock, &kbctx, 0)); ) | for (kbctx=NULL; (node = walk_kbnode (keyblock, &kbctx, 0)); ) | ||||
Context not available. | |||||
if (thiskeyonly && targetnode != node) | if (thiskeyonly && targetnode != node) | ||||
continue; | continue; | ||||
if (agent_probe_secret_key (NULL, node->pkt->pkt.public_key)) | err = agent_delete_secret_key (ctrl, node->pkt->pkt.public_key); | ||||
continue; /* No secret key for that public (sub)key. */ | |||||
if (err == GPG_ERR_NO_SECKEY) | |||||
prompt = gpg_format_keydesc (ctrl, | continue; /* No secret key for that public (sub)key. */ | ||||
node->pkt->pkt.public_key, | |||||
FORMAT_KEYDESC_DELKEY, 1); | else if (err) | ||||
err = hexkeygrip_from_pk (node->pkt->pkt.public_key, &hexgrip); | |||||
/* NB: We require --yes to advise the agent not to | |||||
* request a confirmation. The rationale for this extra | |||||
* pre-caution is that since 2.1 the secret key may also | |||||
* be used for other protocols and thus deleting it from | |||||
* the gpg would also delete the key for other tools. */ | |||||
if (!err && !opt.dry_run) | |||||
err = agent_delete_key (NULL, hexgrip, prompt, | |||||
opt.answer_yes); | |||||
xfree (prompt); | |||||
xfree (hexgrip); | |||||
if (err) | |||||
{ | { | ||||
if (gpg_err_code (err) == GPG_ERR_KEY_ON_CARD) | if (gpg_err_code (err) == GPG_ERR_KEY_ON_CARD) | ||||
write_status_text (STATUS_DELETE_PROBLEM, "1"); | write_status_text (STATUS_DELETE_PROBLEM, "1"); | ||||
Context not available. |