From c655b16f7529a9d3ceee5224cdaaed72443f7996 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Tue, 1 Dec 2015 19:30:49 -0600 Subject: [PATCH] BigInteger: add engine to __debugInfo output and add unit test --- phpseclib/Math/BigInteger.php | 23 ++++++++++++++++++++++- tests/Unit/Math/BigInteger/TestCase.php | 11 +++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/phpseclib/Math/BigInteger.php b/phpseclib/Math/BigInteger.php index 4ba64240..98ec4a93 100644 --- a/phpseclib/Math/BigInteger.php +++ b/phpseclib/Math/BigInteger.php @@ -820,7 +820,28 @@ class Math_BigInteger */ function __debugInfo() { - return array('value' => '0x' . $this->toHex(true)); + $opts = array(); + switch (MATH_BIGINTEGER_MODE) { + case MATH_BIGINTEGER_MODE_GMP: + $engine = 'gmp'; + break; + case MATH_BIGINTEGER_MODE_BCMATH: + $engine = 'bcmath'; + break; + case MATH_BIGINTEGER_MODE_INTERNAL: + $engine = 'internal'; + $opts[] = PHP_INT_SIZE == 8 ? '64-bit' : '32-bit'; + } + if (MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_GMP && defined('MATH_BIGINTEGER_OPENSSL_ENABLED')) { + $opts[] = 'OpenSSL'; + } + if (!empty($opts)) { + $engine.= ' (' . implode($opts, ', ') . ')'; + } + return array( + 'value' => '0x' . $this->toHex(true), + 'engine' => $engine + ); } /** diff --git a/tests/Unit/Math/BigInteger/TestCase.php b/tests/Unit/Math/BigInteger/TestCase.php index 10eacc66..827b2b90 100644 --- a/tests/Unit/Math/BigInteger/TestCase.php +++ b/tests/Unit/Math/BigInteger/TestCase.php @@ -358,4 +358,15 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase 'Failed asserting that Alice and Bob share the same BigInteger.' ); } + + /** + * @requires PHP 5.6 + */ + public function testDebugInfo() + { + $num = new Math_BigInteger(50); + $str = print_r($num, true); + $this->assertContains('[value] => 0x32', $str); + return $str; + } }