mirror of
https://github.com/danog/phpseclib.git
synced 2024-11-27 04:46:26 +01:00
BigInteger: add engine to __debugInfo output and add unit test
This commit is contained in:
parent
37535744b2
commit
c655b16f75
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user