From 474a2b9e971d56ea720dfcf4f04d7afe67ed400e Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Sun, 3 Jan 2021 16:03:41 +0000 Subject: [PATCH] Add gnupg_geterrorinfo and cover gnupg_geterror --- .gitignore | 2 ++ gnupg.c | 28 ++++++++++++++++++++++++++++ php_gnupg.h | 1 + tests/gnupg_oo_geterror.phpt | 19 +++++++++++++++++++ tests/gnupg_oo_geterrorinfo.phpt | 28 ++++++++++++++++++++++++++++ tests/gnupg_res_geterror.phpt | 19 +++++++++++++++++++ tests/gnupg_res_geterrorinfo.phpt | 28 ++++++++++++++++++++++++++++ 7 files changed, 125 insertions(+) create mode 100644 tests/gnupg_oo_geterror.phpt create mode 100644 tests/gnupg_oo_geterrorinfo.phpt create mode 100644 tests/gnupg_res_geterror.phpt create mode 100644 tests/gnupg_res_geterrorinfo.phpt diff --git a/.gitignore b/.gitignore index e8775cf..fa3665d 100644 --- a/.gitignore +++ b/.gitignore @@ -69,6 +69,8 @@ tests/pubring.kbx tests/random_seed tests/sshcontrol tests/trustdb.gpg +tests/init_oo_home/ +tests/init_res_home/ # coverage /coverage.info diff --git a/gnupg.c b/gnupg.c index 14209c0..15081ee 100644 --- a/gnupg.c +++ b/gnupg.c @@ -315,6 +315,7 @@ phpc_function_entry gnupg_methods[] = { PHP_GNUPG_FALIAS(verify, arginfo_gnupg_verify_method) PHP_GNUPG_FALIAS(getengineinfo, arginfo_gnupg_void_method) PHP_GNUPG_FALIAS(geterror, arginfo_gnupg_void_method) + PHP_GNUPG_FALIAS(geterrorinfo, arginfo_gnupg_void_method) PHP_GNUPG_FALIAS(clearsignkeys, arginfo_gnupg_void_method) PHP_GNUPG_FALIAS(clearencryptkeys, arginfo_gnupg_void_method) PHP_GNUPG_FALIAS(cleardecryptkeys, arginfo_gnupg_void_method) @@ -463,6 +464,7 @@ static zend_function_entry gnupg_functions[] = { PHP_FE(gnupg_encryptsign, arginfo_gnupg_text_function) PHP_FE(gnupg_decryptverify, arginfo_gnupg_decryptverify_function) PHP_FE(gnupg_geterror, arginfo_gnupg_void_function) + PHP_FE(gnupg_geterrorinfo, arginfo_gnupg_void_function) PHP_FE(gnupg_addsignkey, arginfo_gnupg_key_passphrase_function) PHP_FE(gnupg_addencryptkey, arginfo_gnupg_key_function) PHP_FE(gnupg_adddecryptkey, arginfo_gnupg_key_passphrase_function) @@ -956,6 +958,32 @@ PHP_FUNCTION(gnupg_geterror) } /* }}} */ +/* {{{ proto string gnupg_geterrorinfo(void) + * returns the last error info array + */ +PHP_FUNCTION(gnupg_geterrorinfo) +{ + GNUPG_GETOBJ(); + + if (!this) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { + return; + } + GNUPG_RES_FETCH(); + } + + PHPC_ARRAY_INIT(return_value); + if (PHPC_THIS->errortxt) { + PHPC_ARRAY_ADD_ASSOC_CSTR(return_value, "generic_message", PHPC_THIS->errortxt); + } else { + PHPC_ARRAY_ADD_ASSOC_BOOL(return_value, "generic_message", 0); + } + PHPC_ARRAY_ADD_ASSOC_LONG(return_value, "gpgme_code", PHPC_THIS->err); + PHPC_ARRAY_ADD_ASSOC_CSTR(return_value, "gpgme_source", (char *) gpgme_strsource(PHPC_THIS->err)); + PHPC_ARRAY_ADD_ASSOC_CSTR(return_value, "gpgme_message", (char *) gpgme_strerror(PHPC_THIS->err)); +} +/* }}} */ + /* {{{ proto int gnupg_getprotocol(void) * returns the currently used pgp-protocol. * atm only OpenPGP is supported diff --git a/php_gnupg.h b/php_gnupg.h index 1418813..30cabe9 100644 --- a/php_gnupg.h +++ b/php_gnupg.h @@ -54,6 +54,7 @@ PHP_FUNCTION(gnupg_keyinfo); PHP_FUNCTION(gnupg_verify); PHP_FUNCTION(gnupg_getengineinfo); PHP_FUNCTION(gnupg_geterror); +PHP_FUNCTION(gnupg_geterrorinfo); PHP_FUNCTION(gnupg_setsignmode); PHP_FUNCTION(gnupg_setarmor); PHP_FUNCTION(gnupg_sign); diff --git a/tests/gnupg_oo_geterror.phpt b/tests/gnupg_oo_geterror.phpt new file mode 100644 index 0000000..67e6975 --- /dev/null +++ b/tests/gnupg_oo_geterror.phpt @@ -0,0 +1,19 @@ +--TEST-- +get error +--SKIPIF-- + +--FILE-- +geterror()); +?> +--EXPECTF-- +bool(false) +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_geterrorinfo.phpt b/tests/gnupg_oo_geterrorinfo.phpt new file mode 100644 index 0000000..31a1e05 --- /dev/null +++ b/tests/gnupg_oo_geterrorinfo.phpt @@ -0,0 +1,28 @@ +--TEST-- +get error info +--SKIPIF-- + +--FILE-- +geterrorinfo()); +?> +--EXPECT-- +array(4) { + ["generic_message"]=> + bool(false) + ["gpgme_code"]=> + int(0) + ["gpgme_source"]=> + string(18) "Unspecified source" + ["gpgme_message"]=> + string(7) "Success" +} +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_res_geterror.phpt b/tests/gnupg_res_geterror.phpt new file mode 100644 index 0000000..3f93d57 --- /dev/null +++ b/tests/gnupg_res_geterror.phpt @@ -0,0 +1,19 @@ +--TEST-- +get error +--SKIPIF-- + +--FILE-- + +--EXPECT-- +bool(false) +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_res_geterrorinfo.phpt b/tests/gnupg_res_geterrorinfo.phpt new file mode 100644 index 0000000..b1e312d --- /dev/null +++ b/tests/gnupg_res_geterrorinfo.phpt @@ -0,0 +1,28 @@ +--TEST-- +get error info +--SKIPIF-- + +--FILE-- + +--EXPECT-- +array(4) { + ["generic_message"]=> + bool(false) + ["gpgme_code"]=> + int(0) + ["gpgme_source"]=> + string(18) "Unspecified source" + ["gpgme_message"]=> + string(7) "Success" +} +--CLEAN-- + \ No newline at end of file