From 077eccc6970b723c00a30d95c70d67f892df0de7 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 18 Dec 2022 06:07:49 -0600 Subject: [PATCH] eliminate dynamic property --- lib/mcrypt.php | 11 ++++++----- tests/MCryptCompatTest.php | 8 ++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/mcrypt.php b/lib/mcrypt.php index bb426d5..ccab850 100644 --- a/lib/mcrypt.php +++ b/lib/mcrypt.php @@ -348,6 +348,8 @@ function phpseclib_mcrypt_module_open($algorithm, $algorithm_directory, $mode, $ $cipher->disablePadding(); + $cipher->key = null; + return $cipher; } @@ -688,7 +690,6 @@ function phpseclib_mcrypt_generic_init(Base $td, $key, $iv) phpseclib_set_iv($td, $iv); $td->enableContinuousBuffer(); - $td->mcrypt_polyfill_init = true; return 0; } @@ -710,7 +711,7 @@ function phpseclib_mcrypt_generic_helper(Base $td, &$data, $op) // Warning: mcrypt_generic(): supplied resource is not a valid MCrypt resource // that error doesn't really make a lot of sense in this context since $td is not a resource nor should it be one. // in light of that we'll just display the same error that you get when you don't call mcrypt_generic_init() at all - if (!isset($td->mcrypt_polyfill_init)) { + if (!isset($td->key)) { trigger_error('m' . $op . '_generic(): Operation disallowed prior to mcrypt_generic_init().', E_USER_WARNING); return false; } @@ -786,13 +787,13 @@ function phpseclib_mdecrypt_generic(Base $td, $data) */ function phpseclib_mcrypt_generic_deinit(Base $td) { - if (!isset($td->mcrypt_polyfill_init)) { + if (!isset($td->key)) { trigger_error('mcrypt_generic_deinit(): Could not terminate encryption specifier', E_USER_WARNING); return false; } $td->disableContinuousBuffer(); - unset($td->mcrypt_polyfill_init); + $td->key = null; return true; } @@ -807,7 +808,7 @@ function phpseclib_mcrypt_generic_deinit(Base $td) */ function phpseclib_mcrypt_module_close(Base $td) { - //unset($td->mcrypt_polyfill_init); + $td->key = null; return true; } diff --git a/tests/MCryptCompatTest.php b/tests/MCryptCompatTest.php index 8ca310f..d2a2b3d 100644 --- a/tests/MCryptCompatTest.php +++ b/tests/MCryptCompatTest.php @@ -1009,6 +1009,14 @@ public function testOFB() } } + public function testModuleOpenWithoutInit() + { + $this->setExpectedException('PHPUnit_Framework_Error_Warning'); + + $td = phpseclib_mcrypt_module_open('rijndael-128', '', 'cbc', ''); + $result = phpseclib_mcrypt_generic($td, 'zzz'); + } + public function mcryptModuleNameProvider() { return array(