diff --git a/.gitignore b/.gitignore index 5a706e0..a05de41 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ config.nice config.status config.sub configure +configure.ac configure.in extras include diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..747d878 --- /dev/null +++ b/TODO.md @@ -0,0 +1,7 @@ +# TODO list + +- Introduce gnupg_geterrorinfo with more info about the error + - including error message from gpgme +- Allow setting engine info on object construction + - Add __construct / res init with gpgme_ctx_set_engine_info +- Return decrypt result if extra param supplied diff --git a/UPGRADING b/UPGRADING index 9f09c78..f60cfe3 100644 --- a/UPGRADING +++ b/UPGRADING @@ -3,7 +3,7 @@ PHP GNUPG UPGRADING NOTES This document lists backward incompatible change in the extension 1.4.0 -- gnupg_decryptverify $plaintext reference cannot be longer passed in +- gnupg_decryptverify $plaintext reference can no longer be passed in call_user_func_array which is conformant to user space code. See https://github.com/php-gnupg/php-gnupg/issues/4 for more details. diff --git a/gnupg.c b/gnupg.c index a8d2809..31cae35 100644 --- a/gnupg.c +++ b/gnupg.c @@ -82,13 +82,13 @@ PHPC_OBJ_DEFINE_HANDLER_VAR(gnupg); } while (0) /* }}} */ -/* {{{ gnupg_free_encryptkeys */ -static void gnupg_free_encryptkeys(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC) +/* {{{ php_gnupg_free_encryptkeys */ +static void php_gnupg_free_encryptkeys(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC) { if (PHPC_THIS) { int idx; /* loop through all encryptkeys and unref them in the gpgme-lib */ - for (idx=0; idx < PHPC_THIS->encrypt_size; idx++) { + for (idx = 0; idx < PHPC_THIS->encrypt_size; idx++) { gpgme_key_unref(PHPC_THIS->encryptkeys[idx]); } if (PHPC_THIS->encryptkeys != NULL) { @@ -100,8 +100,8 @@ static void gnupg_free_encryptkeys(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC) } /* }}} */ -/* {{{ gnupg_free_resource_ptr */ -static void gnupg_free_resource_ptr(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC) +/* {{{ php_gnupg_free_resource_ptr */ +static void php_gnupg_free_resource_ptr(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC) { if (PHPC_THIS) { if (PHPC_THIS->ctx) { @@ -111,7 +111,7 @@ static void gnupg_free_resource_ptr(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC) PHPC_THIS->ctx = NULL; } /* basic cleanup */ - gnupg_free_encryptkeys(PHPC_THIS TSRMLS_CC); + php_gnupg_free_encryptkeys(PHPC_THIS TSRMLS_CC); zend_hash_destroy(PHPC_THIS->signkeys); FREE_HASHTABLE(PHPC_THIS->signkeys); zend_hash_destroy(PHPC_THIS->decryptkeys); @@ -120,17 +120,17 @@ static void gnupg_free_resource_ptr(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC) } /* }}} */ -/* {{{ gnupg_res_dtor */ -static void gnupg_res_dtor(phpc_res_entry_t *rsrc TSRMLS_DC) /* {{{ */ +/* {{{ php_gnupg_res_dtor */ +static void php_gnupg_res_dtor(phpc_res_entry_t *rsrc TSRMLS_DC) /* {{{ */ { PHPC_THIS_DECLARE(gnupg) = rsrc->ptr; - gnupg_free_resource_ptr(PHPC_THIS TSRMLS_CC); + php_gnupg_free_resource_ptr(PHPC_THIS TSRMLS_CC); efree(PHPC_THIS); } /* }}} */ -/* {{{ gnupg_res_init */ -static void gnupg_res_init(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC) +/* {{{ php_gnupg_res_init */ +static void php_gnupg_res_init(PHPC_THIS_DECLARE(gnupg) TSRMLS_DC) { /* init the gpgme-lib and set the default values */ gpgme_ctx_t ctx; @@ -161,7 +161,7 @@ PHPC_OBJ_HANDLER_FREE(gnupg) { PHPC_OBJ_HANDLER_FREE_INIT(gnupg); - gnupg_free_resource_ptr(PHPC_THIS TSRMLS_CC); + php_gnupg_free_resource_ptr(PHPC_THIS TSRMLS_CC); PHPC_OBJ_HANDLER_FREE_DESTROY(); } @@ -171,7 +171,7 @@ PHPC_OBJ_HANDLER_CREATE_EX(gnupg) { PHPC_OBJ_HANDLER_CREATE_EX_INIT(gnupg); - gnupg_res_init(PHPC_THIS TSRMLS_CC); + php_gnupg_res_init(PHPC_THIS TSRMLS_CC); PHPC_OBJ_HANDLER_CREATE_EX_RETURN(gnupg); } @@ -450,7 +450,7 @@ PHP_MINIT_FUNCTION(gnupg) /* register resource */ le_gnupg = zend_register_list_destructors_ex( - gnupg_res_dtor, NULL, "ctx", module_number); + php_gnupg_res_dtor, NULL, "ctx", module_number); if (SUCCESS != gnupg_keylistiterator_init()) { return FAILURE; @@ -648,7 +648,7 @@ PHP_FUNCTION(gnupg_init) { PHPC_THIS_DECLARE(gnupg); PHPC_THIS = emalloc(sizeof(PHPC_OBJ_STRUCT_NAME(gnupg))); - gnupg_res_init(PHPC_THIS TSRMLS_CC); + php_gnupg_res_init(PHPC_THIS TSRMLS_CC); PHPC_RES_RETURN(PHPC_RES_REGISTER(PHPC_THIS, le_gnupg)); } /* }}} */ @@ -726,7 +726,7 @@ PHP_FUNCTION(gnupg_seterrormode) */ PHP_FUNCTION(gnupg_setsignmode) { - phpc_long_t signmode; + phpc_long_t signmode; GNUPG_GETOBJ(); @@ -1068,7 +1068,7 @@ PHP_FUNCTION(gnupg_clearencryptkeys) } GNUPG_RES_FETCH(); } - gnupg_free_encryptkeys(PHPC_THIS TSRMLS_CC); + php_gnupg_free_encryptkeys(PHPC_THIS TSRMLS_CC); RETURN_TRUE; } diff --git a/tests/gnupg_oo_zzz_deletekey.phpt b/tests/gnupg_oo_deletekey.phpt similarity index 66% rename from tests/gnupg_oo_zzz_deletekey.phpt rename to tests/gnupg_oo_deletekey.phpt index 7e5fcd6..6366752 100644 --- a/tests/gnupg_oo_zzz_deletekey.phpt +++ b/tests/gnupg_oo_deletekey.phpt @@ -1,11 +1,11 @@ ---TEST--n +--TEST-- delete a key from the keyring --SKIPIF-- --FILE-- seterrormode(gnupg::ERROR_WARNING); @@ -14,3 +14,8 @@ var_dump($ret); ?> --EXPECT-- bool(true) +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_encrypt.phpt b/tests/gnupg_oo_encrypt.phpt index c9626db..b32be83 100644 --- a/tests/gnupg_oo_encrypt.phpt +++ b/tests/gnupg_oo_encrypt.phpt @@ -4,14 +4,13 @@ encrypt and decrypt a text --FILE-- seterrormode(gnupg::ERROR_WARNING); $gpg->addencryptkey($fingerprint); $enc = $gpg->encrypt($plaintext); -$gpg = NULL; $gpg = new gnupg(); $gpg->adddecryptkey($fingerprint, $passphrase); @@ -21,3 +20,8 @@ var_dump($ret); ?> --EXPECTF-- string(7) "foo bar" +--CLEAN-- + diff --git a/tests/gnupg_oo_encryptsign.phpt b/tests/gnupg_oo_encryptsign.phpt index b27d678..d0de745 100644 --- a/tests/gnupg_oo_encryptsign.phpt +++ b/tests/gnupg_oo_encryptsign.phpt @@ -4,8 +4,8 @@ encryptsign and decryptverify a text --FILE-- seterrormode(gnupg::ERROR_WARNING); @@ -13,9 +13,7 @@ $gpg->addencryptkey($fingerprint); $gpg->addsignkey($fingerprint, $passphrase); $enc = $gpg->encryptsign($plaintext); -$gpg = NULL; $plaintext = false; - $gpg = new gnupg(); $gpg->adddecryptkey($fingerprint, $passphrase); $ret = $gpg->decryptverify ($enc, $plaintext); @@ -40,3 +38,8 @@ array(1) { } } string(7) "foo bar" +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_export.phpt b/tests/gnupg_oo_export.phpt index 6638501..cf0630b 100644 --- a/tests/gnupg_oo_export.phpt +++ b/tests/gnupg_oo_export.phpt @@ -4,8 +4,8 @@ export a key --FILE-- seterrormode(gnupg::ERROR_WARNING); @@ -14,7 +14,6 @@ var_dump($ret); ?> --EXPECTF-- string(%d) "-----BEGIN PGP PUBLIC KEY BLOCK----- -Version: GnuPG v1 mQGiBENQAKwRBADpy828KU+0SuoetJTrJ5dR86PiO3CsH8K6QRP7wY82Eh/9NTJ3 afRj0FNPaVSP0NciPeM4G4uFoQ3lsIf+FBEPXH1D97/XigWObU8K6ha2/s8wU98z @@ -38,3 +37,8 @@ drhhPQJw1AY6GEpSbK0JtACeJuewK8C1wO1l5OYkGzFpb4VgquI= =twR+ -----END PGP PUBLIC KEY BLOCK----- " +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_0001_import.phpt b/tests/gnupg_oo_import.phpt similarity index 81% rename from tests/gnupg_oo_0001_import.phpt rename to tests/gnupg_oo_import.phpt index d524ed9..66f0e03 100644 --- a/tests/gnupg_oo_0001_import.phpt +++ b/tests/gnupg_oo_import.phpt @@ -1,11 +1,12 @@ ---TEST--n +--TEST-- import a new key into the keyring --SKIPIF-- --FILE-- seterrormode(gnupg::ERROR_WARNING); $ret = $gpg->import($testkey); @@ -32,3 +33,8 @@ array(9) { ["fingerprint"]=> string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E" } +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_keyinfo.phpt b/tests/gnupg_oo_keyinfo.phpt index 52c49a9..79ad9c6 100644 --- a/tests/gnupg_oo_keyinfo.phpt +++ b/tests/gnupg_oo_keyinfo.phpt @@ -4,8 +4,8 @@ get keyinfo --FILE-- seterrormode(gnupg::ERROR_WARNING); @@ -101,3 +101,8 @@ array(1) { } } } +--CLEAN-- + diff --git a/tests/gnupg_oo_listsignatures.phpt b/tests/gnupg_oo_listsignatures.phpt index 8fdd9bc..19db17b 100644 --- a/tests/gnupg_oo_listsignatures.phpt +++ b/tests/gnupg_oo_listsignatures.phpt @@ -1,11 +1,11 @@ ---TEST--n +--TEST-- list signatures --SKIPIF-- --FILE-- seterrormode(gnupg::ERROR_WARNING); @@ -37,3 +37,8 @@ array(1) { } } } +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_sign_clear.phpt b/tests/gnupg_oo_sign_clear.phpt index 7e45f94..40b3e84 100644 --- a/tests/gnupg_oo_sign_clear.phpt +++ b/tests/gnupg_oo_sign_clear.phpt @@ -4,8 +4,8 @@ sign a text with sigmode SIG_MODE_CLEAR --FILE-- seterrormode(gnupg::ERROR_WARNING); @@ -40,3 +40,8 @@ array(1) { } string(8) "foo bar " +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_sign_detach.phpt b/tests/gnupg_oo_sign_detach.phpt index b510c0a..feb9e30 100644 --- a/tests/gnupg_oo_sign_detach.phpt +++ b/tests/gnupg_oo_sign_detach.phpt @@ -4,8 +4,8 @@ sign a text with mode SIG_MODE_DETACH --FILE-- seterrormode(gnupg::ERROR_WARNING); @@ -39,3 +39,8 @@ array(1) { } } string(7) "foo bar" +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_sign_detach_nonarmor.phpt b/tests/gnupg_oo_sign_detach_nonarmor.phpt index ab70bc1..4642aaf 100644 --- a/tests/gnupg_oo_sign_detach_nonarmor.phpt +++ b/tests/gnupg_oo_sign_detach_nonarmor.phpt @@ -1,11 +1,11 @@ ---TEST--n +--TEST-- sign a text with mode SIG_MODE_DETACH and without armored output --SKIPIF-- --FILE-- seterrormode(gnupg::ERROR_WARNING); @@ -40,3 +40,8 @@ array(1) { } } string(7) "foo bar" +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_sign_normal.phpt b/tests/gnupg_oo_sign_normal.phpt index 754a138..58d0117 100644 --- a/tests/gnupg_oo_sign_normal.phpt +++ b/tests/gnupg_oo_sign_normal.phpt @@ -1,11 +1,11 @@ ---TEST--n +--TEST-- sign a text with mode SIG_MODE_NORMAL --SKIPIF-- --FILE-- seterrormode(gnupg::ERROR_WARNING); @@ -40,3 +40,8 @@ array(1) { } } string(7) "foo bar" +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_oo_sign_normal_noarmor.phpt b/tests/gnupg_oo_sign_normal_noarmor.phpt index d9cd6df..ee42f47 100644 --- a/tests/gnupg_oo_sign_normal_noarmor.phpt +++ b/tests/gnupg_oo_sign_normal_noarmor.phpt @@ -1,11 +1,11 @@ ---TEST--n +--TEST-- sign a text with mode SIG_MODE_NORMAL and without armored output --SKIPIF-- --FILE-- seterrormode(gnupg::ERROR_WARNING); @@ -14,8 +14,6 @@ $gpg->setsignmode(gnupg::SIG_MODE_NORMAL); $gpg->addsignkey($fingerprint, $passphrase); $ret = $gpg->sign($plaintext); -$gpg = NULL; - $gpg = new gnupg(); //$ret = $gpg->verify($plaintext, $ret); $plaintext = false; @@ -41,3 +39,8 @@ array(1) { } } string(7) "foo bar" +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_res_0001_import.phpt b/tests/gnupg_res_0001_import.phpt index 291f323..6c6e672 100644 --- a/tests/gnupg_res_0001_import.phpt +++ b/tests/gnupg_res_0001_import.phpt @@ -1,9 +1,11 @@ ---TEST--n +--TEST-- import a new key into the keyring +--SKIPIF-- + --FILE-- string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E" } +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_res_zzz_deletekey.phpt b/tests/gnupg_res_deletekey.phpt similarity index 54% rename from tests/gnupg_res_zzz_deletekey.phpt rename to tests/gnupg_res_deletekey.phpt index e8b1901..0718809 100644 --- a/tests/gnupg_res_zzz_deletekey.phpt +++ b/tests/gnupg_res_deletekey.phpt @@ -1,9 +1,11 @@ --TEST--n delete a key from the keyring +--SKIPIF-- + --FILE-- --EXPECT-- bool(true) +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_res_encrypt.phpt b/tests/gnupg_res_encrypt.phpt index 5e6121d..fe5b155 100644 --- a/tests/gnupg_res_encrypt.phpt +++ b/tests/gnupg_res_encrypt.phpt @@ -1,9 +1,11 @@ --TEST-- encrypt and decrypt a text +--SKIPIF-- + --FILE-- --EXPECTF-- string(7) "foo bar" +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_res_encryptsign.phpt b/tests/gnupg_res_encryptsign.phpt index 44e5315..b6df88e 100644 --- a/tests/gnupg_res_encryptsign.phpt +++ b/tests/gnupg_res_encryptsign.phpt @@ -1,9 +1,11 @@ --TEST-- encryptsign and decryptverify a text +--SKIPIF-- + --FILE-- \ No newline at end of file diff --git a/tests/gnupg_res_export.phpt b/tests/gnupg_res_export.phpt index 9d4ad44..1fb879a 100644 --- a/tests/gnupg_res_export.phpt +++ b/tests/gnupg_res_export.phpt @@ -1,9 +1,11 @@ --TEST-- export a key +--SKIPIF-- + --FILE-- --EXPECTF-- string(%d) "-----BEGIN PGP PUBLIC KEY BLOCK----- -Version: GnuPG v1 mQGiBENQAKwRBADpy828KU+0SuoetJTrJ5dR86PiO3CsH8K6QRP7wY82Eh/9NTJ3 afRj0FNPaVSP0NciPeM4G4uFoQ3lsIf+FBEPXH1D97/XigWObU8K6ha2/s8wU98z @@ -36,3 +37,8 @@ drhhPQJw1AY6GEpSbK0JtACeJuewK8C1wO1l5OYkGzFpb4VgquI= =twR+ -----END PGP PUBLIC KEY BLOCK----- " +--CLEAN-- + \ No newline at end of file diff --git a/tests/gnupg_res_keyinfo.phpt b/tests/gnupg_res_keyinfo.phpt index 458c07a..5644f5f 100644 --- a/tests/gnupg_res_keyinfo.phpt +++ b/tests/gnupg_res_keyinfo.phpt @@ -1,9 +1,11 @@ --TEST--n get keyinfo +--SKIPIF-- + --FILE-- \ No newline at end of file diff --git a/tests/gnupg_res_listsignatures.phpt b/tests/gnupg_res_listsignatures.phpt index 97dec45..ee7b4ad 100644 --- a/tests/gnupg_res_listsignatures.phpt +++ b/tests/gnupg_res_listsignatures.phpt @@ -1,9 +1,11 @@ --TEST--n list signatures +--SKIPIF-- + --FILE-- \ No newline at end of file diff --git a/tests/gnupg_res_sign_clear.phpt b/tests/gnupg_res_sign_clear.phpt index 45d50dd..19d02c8 100644 --- a/tests/gnupg_res_sign_clear.phpt +++ b/tests/gnupg_res_sign_clear.phpt @@ -1,9 +1,11 @@ --TEST--n sign a text with sigmode SIG_MODE_CLEAR +--SKIPIF-- + --FILE-- \ No newline at end of file diff --git a/tests/gnupg_res_sign_detach.phpt b/tests/gnupg_res_sign_detach.phpt index 0a42b4e..8bf0a63 100644 --- a/tests/gnupg_res_sign_detach.phpt +++ b/tests/gnupg_res_sign_detach.phpt @@ -1,9 +1,11 @@ --TEST--n sign a text with mode SIG_MODE_DETACH +--SKIPIF-- + --FILE-- \ No newline at end of file diff --git a/tests/gnupg_res_sign_detach_nonarmor.phpt b/tests/gnupg_res_sign_detach_nonarmor.phpt index ef5bcce..19785e1 100644 --- a/tests/gnupg_res_sign_detach_nonarmor.phpt +++ b/tests/gnupg_res_sign_detach_nonarmor.phpt @@ -1,9 +1,11 @@ --TEST--n sign a text with mode SIG_MODE_DETACH and without armored output +--SKIPIF-- + --FILE-- \ No newline at end of file diff --git a/tests/gnupg_res_sign_normal.phpt b/tests/gnupg_res_sign_normal.phpt index 35999ff..825cc0d 100644 --- a/tests/gnupg_res_sign_normal.phpt +++ b/tests/gnupg_res_sign_normal.phpt @@ -1,9 +1,11 @@ --TEST--n sign a text with mode SIG_MODE_NORMAL +--SKIPIF-- + --FILE-- \ No newline at end of file diff --git a/tests/gnupg_res_sign_normal_noarmor.phpt b/tests/gnupg_res_sign_normal_noarmor.phpt index bafaa2b..8cee2a9 100644 --- a/tests/gnupg_res_sign_normal_noarmor.phpt +++ b/tests/gnupg_res_sign_normal_noarmor.phpt @@ -1,9 +1,11 @@ --TEST--n sign a text with mode SIG_MODE_NORMAL and without armored output +--SKIPIF-- + --FILE-- \ No newline at end of file diff --git a/tests/gnupgt.inc b/tests/gnupgt.inc new file mode 100644 index 0000000..7b3363f --- /dev/null +++ b/tests/gnupgt.inc @@ -0,0 +1,21 @@ +import($testkey); + } + + static function delete_key() + { + @unlink(__DIR__ . "/pubring.gpg"); + @unlink(__DIR__ . "/secring.gpg"); + } +} \ No newline at end of file diff --git a/tests/vars.inc b/tests/vars.inc index 527bd99..1d4de35 100644 --- a/tests/vars.inc +++ b/tests/vars.inc @@ -1,11 +1,10 @@ import($testkey); - } - - return true; -} - ?> -