Merge branch 'next'

This commit is contained in:
Jakub Zelenka 2018-05-17 20:24:29 +01:00
commit 337ccfb4a0
30 changed files with 252 additions and 114 deletions

1
.gitignore vendored
View file

@ -15,6 +15,7 @@ config.nice
config.status
config.sub
configure
configure.ac
configure.in
extras
include

7
TODO.md Normal file
View file

@ -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

View file

@ -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.

34
gnupg.c
View file

@ -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;
}

View file

@ -1,11 +1,11 @@
--TEST--n
--TEST--
delete a key from the keyring
--SKIPIF--
<?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING);
@ -14,3 +14,8 @@ var_dump($ret);
?>
--EXPECT--
bool(true)
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -4,14 +4,13 @@ encrypt and decrypt a text
<?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = new gnupg();
$gpg->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--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -4,8 +4,8 @@ encryptsign and decryptverify a text
<?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = new gnupg();
$gpg->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--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -4,8 +4,8 @@ export a key
<?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = new gnupg();
$gpg->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--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,11 +1,12 @@
--TEST--n
--TEST--
import a new key into the keyring
--SKIPIF--
<?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_clear_files();
require_once "gnupgt.inc";
gnupgt::delete_key();
$gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING);
$ret = $gpg->import($testkey);
@ -32,3 +33,8 @@ array(9) {
["fingerprint"]=>
string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E"
}
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -4,8 +4,8 @@ get keyinfo
<?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING);
@ -101,3 +101,8 @@ array(1) {
}
}
}
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,11 +1,11 @@
--TEST--n
--TEST--
list signatures
--SKIPIF--
<?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING);
@ -37,3 +37,8 @@ array(1) {
}
}
}
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -4,8 +4,8 @@ sign a text with sigmode SIG_MODE_CLEAR
<?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING);
@ -40,3 +40,8 @@ array(1) {
}
string(8) "foo bar
"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -4,8 +4,8 @@ sign a text with mode SIG_MODE_DETACH
<?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING);
@ -39,3 +39,8 @@ array(1) {
}
}
string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,11 +1,11 @@
--TEST--n
--TEST--
sign a text with mode SIG_MODE_DETACH and without armored output
--SKIPIF--
<?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING);
@ -40,3 +40,8 @@ array(1) {
}
}
string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,11 +1,11 @@
--TEST--n
--TEST--
sign a text with mode SIG_MODE_NORMAL
--SKIPIF--
<?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_WARNING);
@ -40,3 +40,8 @@ array(1) {
}
}
string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,11 +1,11 @@
--TEST--n
--TEST--
sign a text with mode SIG_MODE_NORMAL and without armored output
--SKIPIF--
<?php if(!class_exists("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = new gnupg();
$gpg->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--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--n
--TEST--
import a new key into the keyring
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_clear_files();
require_once "gnupgt.inc";
gnupgt::delete_key();
$gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -31,3 +33,8 @@ array(9) {
["fingerprint"]=>
string(40) "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E"
}
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--n
delete a key from the keyring
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -12,3 +14,8 @@ var_dump($ret);
?>
--EXPECT--
bool(true)
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--
encrypt and decrypt a text
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -20,3 +22,8 @@ var_dump($ret);
?>
--EXPECTF--
string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--
encryptsign and decryptverify a text
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -38,3 +40,8 @@ array(1) {
}
}
string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--
export a key
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -12,7 +14,6 @@ var_dump($ret);
?>
--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--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--n
get keyinfo
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -99,3 +101,8 @@ array(1) {
}
}
}
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--n
list signatures
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -35,3 +37,8 @@ array(1) {
}
}
}
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--n
sign a text with sigmode SIG_MODE_CLEAR
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -11,8 +13,6 @@ gnupg_setsignmode($gpg, GNUPG_SIG_MODE_CLEAR);
gnupg_addsignkey($gpg, $fingerprint, $passphrase);
$ret = gnupg_sign($gpg, $plaintext);
$gpg = NULL;
$gpg = gnupg_init();
$tmp = false;
$ret = gnupg_verify($gpg, $ret, false, $tmp);
@ -38,3 +38,8 @@ array(1) {
}
string(8) "foo bar
"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--n
sign a text with mode SIG_MODE_DETACH
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -11,8 +13,6 @@ gnupg_setsignmode($gpg, GNUPG_SIG_MODE_DETACH);
gnupg_addsignkey($gpg, $fingerprint, $passphrase);
$ret = gnupg_sign($gpg, $plaintext);
$gpg = NULL;
$gpg = gnupg_init();
$tmp = false;
$ret = gnupg_verify($gpg,$plaintext, $ret);
@ -37,3 +37,8 @@ array(1) {
}
}
string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--n
sign a text with mode SIG_MODE_DETACH and without armored output
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -38,3 +40,8 @@ array(1) {
}
}
string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--n
sign a text with mode SIG_MODE_NORMAL
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -38,3 +40,8 @@ array(1) {
}
}
string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

View file

@ -1,9 +1,11 @@
--TEST--n
sign a text with mode SIG_MODE_NORMAL and without armored output
--SKIPIF--
<?php if (!extension_loaded("gnupg")) die("skip"); ?>
--FILE--
<?php
require_once dirname(__FILE__) . "/vars.inc";
gnupg_test_import();
require_once "gnupgt.inc";
gnupgt::import_key();
$gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_WARNING);
@ -38,3 +40,8 @@ array(1) {
}
}
string(7) "foo bar"
--CLEAN--
<?php
require_once "gnupgt.inc";
gnupgt::delete_key();
?>

21
tests/gnupgt.inc Normal file
View file

@ -0,0 +1,21 @@
<?php
require_once __DIR__ . "/vars.inc";
class gnupgt {
static function import_key()
{
global $testkey;
self::delete_key();
$gpg = new gnupg();
$gpg->import($testkey);
}
static function delete_key()
{
@unlink(__DIR__ . "/pubring.gpg");
@unlink(__DIR__ . "/secring.gpg");
}
}

View file

@ -1,11 +1,10 @@
<?php
putenv("GNUPGHOME=" . dirname(__FILE__));
error_reporting(E_ALL);
putenv("GNUPGHOME=".dirname(__FILE__));
error_reporting (E_ALL);
$fingerprint = "64DF06E42FCF2094590CDEEE2E96F141B3DD2B2E";
$passphrase = "blabla";
$plaintext = "foo bar";
$secringfile = dirname(__FILE__) . "/secring.gpg";
$pubringfile = dirname(__FILE__) . "/pubring.gpg";
$passphrase = "blabla";
$plaintext = "foo bar";
$testkey =<<<EOF
-----BEGIN PGP PRIVATE KEY BLOCK-----
@ -36,28 +35,4 @@ BjoYSlJsrQm0AJ4m57ArwLXA7WXk5iQbMWlvhWCq4g==
=awlp
-----END PGP PRIVATE KEY BLOCK-----
EOF;
function gnupg_test_clear_files() {
global $secringfile, $pubringfile;
if (is_file($secringfile)) {
unlink($secringfile);
}
if (is_file($pubringfile)) {
unlink($pubringfile);
}
}
function gnupg_test_import() {
global $secringfile, $testkey;
if (!file_exists($secringfile) || !filesize($secringfile)) {
$gpg = new gnupg();
return $gpg->import($testkey);
}
return true;
}
?>