1 /* delete.c - Delete a key.
2 Copyright (C) 2001, 2002, 2003, 2004 g10 Code GmbH
4 This file is part of GPGME.
6 GPGME is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of
9 the License, or (at your option) any later version.
11 GPGME is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
34 delete_status_handler (void *priv, gpgme_status_code_t code, char *args)
36 if (code == GPGME_STATUS_DELETE_PROBLEM)
40 DELETE_No_Problem = 0,
41 DELETE_No_Such_Key = 1,
42 DELETE_Must_Delete_Secret_Key = 2,
43 DELETE_Ambiguous_Specification = 3
48 gpg_err_set_errno (0);
49 problem = strtol (args, &tail, 0);
50 if (errno || (*tail && *tail != ' '))
51 return gpg_error (GPG_ERR_INV_ENGINE);
55 case DELETE_No_Problem:
58 case DELETE_No_Such_Key:
59 return gpg_error (GPG_ERR_NO_PUBKEY);
61 case DELETE_Must_Delete_Secret_Key:
62 return gpg_error (GPG_ERR_CONFLICT);
64 case DELETE_Ambiguous_Specification:
65 return gpg_error (GPG_ERR_AMBIGUOUS_NAME);
68 return gpg_error (GPG_ERR_GENERAL);
76 delete_start (gpgme_ctx_t ctx, int synchronous, const gpgme_key_t key,
81 err = _gpgme_op_reset (ctx, synchronous);
85 _gpgme_engine_set_status_handler (ctx->engine, delete_status_handler, ctx);
87 return _gpgme_engine_op_delete (ctx->engine, key, allow_secret);
91 /* Delete KEY from the keyring. If ALLOW_SECRET is non-zero, secret
92 keys are also deleted. */
94 gpgme_op_delete_start (gpgme_ctx_t ctx, const gpgme_key_t key,
99 TRACE_BEG3 (DEBUG_CTX, "gpgme_op_delete", ctx,
100 "key=%p (%s), allow_secret=%i", key,
101 (key->subkeys && key->subkeys->fpr) ?
102 key->subkeys->fpr : "invalid", allow_secret);
103 err = delete_start (ctx, 0, key, allow_secret);
104 return TRACE_ERR (err);
108 /* Delete KEY from the keyring. If ALLOW_SECRET is non-zero, secret
109 keys are also deleted. */
111 gpgme_op_delete (gpgme_ctx_t ctx, const gpgme_key_t key, int allow_secret)
115 TRACE_BEG3 (DEBUG_CTX, "gpgme_op_delete", ctx,
116 "key=%p (%s), allow_secret=%i", key,
117 (key->subkeys && key->subkeys->fpr) ?
118 key->subkeys->fpr : "invalid", allow_secret);
119 err = delete_start (ctx, 1, key, allow_secret);
121 err = _gpgme_wait_one (ctx);