Add gnupg_geterrorinfo and cover gnupg_geterror

This commit is contained in:
Jakub Zelenka 2021-01-03 16:03:41 +00:00
parent e6c0456610
commit 474a2b9e97
7 changed files with 125 additions and 0 deletions

2
.gitignore vendored
View file

@ -69,6 +69,8 @@ tests/pubring.kbx
tests/random_seed tests/random_seed
tests/sshcontrol tests/sshcontrol
tests/trustdb.gpg tests/trustdb.gpg
tests/init_oo_home/
tests/init_res_home/
# coverage # coverage
/coverage.info /coverage.info

28
gnupg.c
View file

@ -315,6 +315,7 @@ phpc_function_entry gnupg_methods[] = {
PHP_GNUPG_FALIAS(verify, arginfo_gnupg_verify_method) PHP_GNUPG_FALIAS(verify, arginfo_gnupg_verify_method)
PHP_GNUPG_FALIAS(getengineinfo, arginfo_gnupg_void_method) PHP_GNUPG_FALIAS(getengineinfo, arginfo_gnupg_void_method)
PHP_GNUPG_FALIAS(geterror, 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(clearsignkeys, arginfo_gnupg_void_method)
PHP_GNUPG_FALIAS(clearencryptkeys, arginfo_gnupg_void_method) PHP_GNUPG_FALIAS(clearencryptkeys, arginfo_gnupg_void_method)
PHP_GNUPG_FALIAS(cleardecryptkeys, 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_encryptsign, arginfo_gnupg_text_function)
PHP_FE(gnupg_decryptverify, arginfo_gnupg_decryptverify_function) PHP_FE(gnupg_decryptverify, arginfo_gnupg_decryptverify_function)
PHP_FE(gnupg_geterror, arginfo_gnupg_void_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_addsignkey, arginfo_gnupg_key_passphrase_function)
PHP_FE(gnupg_addencryptkey, arginfo_gnupg_key_function) PHP_FE(gnupg_addencryptkey, arginfo_gnupg_key_function)
PHP_FE(gnupg_adddecryptkey, arginfo_gnupg_key_passphrase_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) /* {{{ proto int gnupg_getprotocol(void)
* returns the currently used pgp-protocol. * returns the currently used pgp-protocol.
* atm only OpenPGP is supported * atm only OpenPGP is supported

View file

@ -54,6 +54,7 @@ PHP_FUNCTION(gnupg_keyinfo);
PHP_FUNCTION(gnupg_verify); PHP_FUNCTION(gnupg_verify);
PHP_FUNCTION(gnupg_getengineinfo); PHP_FUNCTION(gnupg_getengineinfo);
PHP_FUNCTION(gnupg_geterror); PHP_FUNCTION(gnupg_geterror);
PHP_FUNCTION(gnupg_geterrorinfo);
PHP_FUNCTION(gnupg_setsignmode); PHP_FUNCTION(gnupg_setsignmode);
PHP_FUNCTION(gnupg_setarmor); PHP_FUNCTION(gnupg_setarmor);
PHP_FUNCTION(gnupg_sign); PHP_FUNCTION(gnupg_sign);

View file

@ -0,0 +1,19 @@
--TEST--
get error
--SKIPIF--
<?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = new gnupg();
var_dump($gpg->geterror());
?>
--EXPECTF--
bool(false)
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -0,0 +1,28 @@
--TEST--
get error info
--SKIPIF--
<?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = new gnupg();
var_dump($gpg->geterrorinfo());
?>
--EXPECT--
array(4) {
["generic_message"]=>
bool(false)
["gpgme_code"]=>
int(0)
["gpgme_source"]=>
string(18) "Unspecified source"
["gpgme_message"]=>
string(7) "Success"
}
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -0,0 +1,19 @@
--TEST--
get error
--SKIPIF--
<?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = gnupg_init();
var_dump(gnupg_geterror($gpg));
?>
--EXPECT--
bool(false)
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -0,0 +1,28 @@
--TEST--
get error info
--SKIPIF--
<?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = gnupg_init();
var_dump(gnupg_geterrorinfo($gpg));
?>
--EXPECT--
array(4) {
["generic_message"]=>
bool(false)
["gpgme_code"]=>
int(0)
["gpgme_source"]=>
string(18) "Unspecified source"
["gpgme_message"]=>
string(7) "Success"
}
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>