From 47c419545afa35073b60c609c8b5aacb406a1f78 Mon Sep 17 00:00:00 2001 From: Matej Kravjar Date: Tue, 20 Jun 2017 12:40:49 +0200 Subject: [PATCH] Fixed #632 Fatal error: Cannot access self:: when no class scope is active --- phpseclib/Crypt/DES.php | 4 ++-- tests/Unit/Crypt/TripleDESTest.php | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/phpseclib/Crypt/DES.php b/phpseclib/Crypt/DES.php index 51220469..9a8225fb 100644 --- a/phpseclib/Crypt/DES.php +++ b/phpseclib/Crypt/DES.php @@ -1357,8 +1357,8 @@ class DES extends Base $k[self::ENCRYPT][$i] = '$ke[' . $i . ']'; $k[self::DECRYPT][$i] = '$kd[' . $i . ']'; } - $init_encrypt = '$ke = $self->keys[self::ENCRYPT];'; - $init_decrypt = '$kd = $self->keys[self::DECRYPT];'; + $init_encrypt = '$ke = $self->keys[$self::ENCRYPT];'; + $init_decrypt = '$kd = $self->keys[$self::DECRYPT];'; break; } diff --git a/tests/Unit/Crypt/TripleDESTest.php b/tests/Unit/Crypt/TripleDESTest.php index e41c4386..36ad218d 100644 --- a/tests/Unit/Crypt/TripleDESTest.php +++ b/tests/Unit/Crypt/TripleDESTest.php @@ -186,4 +186,15 @@ class Unit_Crypt_TripleDESTest extends PhpseclibTestCase $this->assertEquals($result, $expected, "Failed asserting inner chainin worked correctly in $engineName engine"); } } + + // test special case lambda function error + public function testCorrectSelfUseInLambda() + { + $td = new TripleDES( TripleDES::MODE_ECB ); + $td->setPreferredEngine( TripleDES::ENGINE_INTERNAL ); + for ( $i = 0; $i < 20; $i++ ) { + $td->setKey( str_repeat( 'a', 20 ) . pack( 'V', mt_rand() ) ); + $td->encrypt( str_repeat( 'a', 32 ) ); + } + } }