mirror of
https://github.com/php-gnupg/php-gnupg.git
synced 2024-11-21 14:07:10 +00:00
Add gnupg_geterrorinfo and cover gnupg_geterror
This commit is contained in:
parent
e6c0456610
commit
474a2b9e97
7 changed files with 125 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -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
|
||||
|
|
28
gnupg.c
28
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
|
||||
|
|
|
@ -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);
|
||||
|
|
19
tests/gnupg_oo_geterror.phpt
Normal file
19
tests/gnupg_oo_geterror.phpt
Normal 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();
|
||||
?>
|
28
tests/gnupg_oo_geterrorinfo.phpt
Normal file
28
tests/gnupg_oo_geterrorinfo.phpt
Normal 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();
|
||||
?>
|
19
tests/gnupg_res_geterror.phpt
Normal file
19
tests/gnupg_res_geterror.phpt
Normal 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();
|
||||
?>
|
28
tests/gnupg_res_geterrorinfo.phpt
Normal file
28
tests/gnupg_res_geterrorinfo.phpt
Normal 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();
|
||||
?>
|
Loading…
Reference in a new issue