Refactore gnupg_deletekey to allow boolean allow_secret

This commit is contained in:
Jakub Zelenka 2021-01-03 15:16:00 +00:00
parent e4ab851f1f
commit e6c0456610

16
gnupg.c
View file

@ -1845,6 +1845,10 @@ PHP_FUNCTION(gnupg_import)
} }
/* }}} */ /* }}} */
#ifndef GPGME_DELETE_ALLOW_SECRET
#define GPGME_DELETE_ALLOW_SECRET 1
#endif
/* {{{ proto book gnupg_deletekey(string key) /* {{{ proto book gnupg_deletekey(string key)
* deletes a key from the keyring * deletes a key from the keyring
*/ */
@ -1852,18 +1856,19 @@ PHP_FUNCTION(gnupg_deletekey)
{ {
char *key; char *key;
phpc_str_size_t key_len; phpc_str_size_t key_len;
phpc_long_t allow_secret = 0; zend_bool allow_secret = 0;
gpgme_key_t gpgme_key; gpgme_key_t gpgme_key;
unsigned int flags = 0;
GNUPG_GETOBJ(); GNUPG_GETOBJ();
if (this) { if (this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b",
&key, &key_len, &allow_secret) == FAILURE) { &key, &key_len, &allow_secret) == FAILURE) {
return; return;
} }
} else { } else {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|b",
&res, &key, &key_len, &allow_secret) == FAILURE) { &res, &key, &key_len, &allow_secret) == FAILURE) {
return; return;
} }
@ -1874,7 +1879,10 @@ PHP_FUNCTION(gnupg_deletekey)
GNUPG_ERR("get_key failed"); GNUPG_ERR("get_key failed");
return; return;
} }
if (!PHP_GNUPG_DO(gpgme_op_delete(PHPC_THIS->ctx, gpgme_key, allow_secret))) { if (allow_secret) {
flags = GPGME_DELETE_ALLOW_SECRET;
}
if (!PHP_GNUPG_DO(gpgme_op_delete(PHPC_THIS->ctx, gpgme_key, flags))) {
GNUPG_ERR("delete failed"); GNUPG_ERR("delete failed");
RETVAL_FALSE; RETVAL_FALSE;
} else { } else {