2017-09-30 00:46:49 +00:00
|
|
|
<?php
|
2017-09-30 11:44:37 +00:00
|
|
|
|
2022-06-04 15:31:21 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-02-23 02:48:51 +00:00
|
|
|
namespace phpseclib3\Tests\Unit\Math;
|
|
|
|
|
2019-11-07 05:41:40 +00:00
|
|
|
use phpseclib3\Math\BigInteger;
|
|
|
|
use phpseclib3\Math\BigInteger\Engines\BCMath;
|
|
|
|
use phpseclib3\Math\BigInteger\Engines\GMP;
|
|
|
|
use phpseclib3\Math\BigInteger\Engines\PHP32;
|
|
|
|
use phpseclib3\Math\BigInteger\Engines\PHP64;
|
2022-02-23 02:48:51 +00:00
|
|
|
use phpseclib3\Tests\PhpseclibTestCase;
|
2017-09-30 00:46:49 +00:00
|
|
|
|
2022-02-23 02:48:51 +00:00
|
|
|
class BigIntegerTest extends PhpseclibTestCase
|
2017-09-30 00:46:49 +00:00
|
|
|
{
|
2022-02-17 02:25:59 +00:00
|
|
|
/**
|
|
|
|
*/
|
2022-06-04 15:31:21 +00:00
|
|
|
private static function mockEngine(string $className, bool $isValid): void
|
2022-02-17 02:25:59 +00:00
|
|
|
{
|
|
|
|
eval(<<<ENGINE
|
2022-06-04 15:31:21 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-11-07 05:41:40 +00:00
|
|
|
namespace phpseclib3\Math\BigInteger\Engines;
|
2022-05-11 04:08:46 +00:00
|
|
|
class $className extends \phpseclib3\Math\BigInteger\Engines\Engine {
|
2017-09-30 00:46:49 +00:00
|
|
|
public function __construct(){}
|
2022-05-11 04:08:46 +00:00
|
|
|
public static function isValidEngine() { return $isValid; }
|
2022-06-04 15:31:21 +00:00
|
|
|
public static function setModExpEngine(\$engine): void {}
|
2017-09-30 00:46:49 +00:00
|
|
|
public function toString() { return __CLASS__; }
|
|
|
|
}
|
|
|
|
ENGINE
|
2022-02-17 02:25:59 +00:00
|
|
|
);
|
|
|
|
}
|
2017-09-30 00:46:49 +00:00
|
|
|
|
2022-06-04 15:31:21 +00:00
|
|
|
public static function provideBadConfigurationException(): array
|
2022-02-17 02:25:59 +00:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
GMP::class,
|
|
|
|
['GMP', true],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
PHP64::class,
|
|
|
|
['GMP', false],
|
|
|
|
['PHP64', true],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
BCMath::class,
|
|
|
|
['GMP', false],
|
|
|
|
['PHP64', false],
|
|
|
|
['BCMath', true],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
PHP32::class,
|
|
|
|
['GMP', false],
|
|
|
|
['PHP64', false],
|
|
|
|
['BCMath', false],
|
|
|
|
['PHP32', true],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2017-09-30 00:46:49 +00:00
|
|
|
|
2022-02-17 02:25:59 +00:00
|
|
|
/**
|
|
|
|
* BigInteger should choose another engine if one is not valid
|
2022-06-04 15:31:21 +00:00
|
|
|
*
|
2022-02-17 02:25:59 +00:00
|
|
|
* @dataProvider provideBadConfigurationException
|
|
|
|
* @preserveGlobalState disabled
|
|
|
|
* @runInSeparateProcess mocks must not disturb other tests
|
|
|
|
* @param array[] ...$engines
|
|
|
|
*/
|
2022-06-04 15:31:21 +00:00
|
|
|
public function testBadConfigurationException(string $expectedEngineClass, array ...$engines): void
|
2022-02-17 02:25:59 +00:00
|
|
|
{
|
|
|
|
foreach ($engines as $engine) {
|
|
|
|
static::mockEngine($engine[0], $engine[1]);
|
|
|
|
}
|
2017-09-30 00:46:49 +00:00
|
|
|
|
2022-02-17 02:25:59 +00:00
|
|
|
$bigint = new BigInteger();
|
2017-09-30 00:46:49 +00:00
|
|
|
|
2022-02-17 02:25:59 +00:00
|
|
|
static::assertSame($expectedEngineClass, $bigint->toString());
|
|
|
|
}
|
2017-09-30 00:46:49 +00:00
|
|
|
}
|