Skip to content

Commit

Permalink
Remove deprecated BigInteger::powerMod()
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Aug 18, 2020
1 parent 20dc2a7 commit d493693
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 30 deletions.
18 changes: 0 additions & 18 deletions src/BigInteger.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,24 +652,6 @@ public function modPow($exp, $mod) : BigInteger
return new BigInteger($result);
}

/**
* Returns this number raised into power with modulo.
*
* @deprecated Use modPow() instead.
*
* @param BigNumber|int|float|string $exp The positive exponent.
* @param BigNumber|int|float|string $mod The modulus. Must not be zero.
*
* @return BigInteger
*
* @throws NegativeNumberException If any of the operands is negative.
* @throws DivisionByZeroException If the modulus is zero.
*/
public function powerMod($exp, $mod) : BigInteger
{
return $this->modPow($exp, $mod);
}

/**
* Returns the greatest common divisor of this number and the given one.
*
Expand Down
23 changes: 11 additions & 12 deletions tests/BigIntegerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,6 @@ public function testModZeroThrowsException() : void
public function testModPow(string $base, string $exp, string $mod, string $expected) : void
{
self::assertBigIntegerEquals($expected, BigInteger::of($base)->modPow($exp, $mod));
self::assertBigIntegerEquals($expected, BigInteger::of($base)->powerMod($exp, $mod));
}

public function providerModPow() : array
Expand All @@ -1380,7 +1379,7 @@ public function providerModPow() : array
/**
* Crypto test from phpseclib test suite.
*/
public function testPowerModCrypto() : void
public function testModPowCrypto() : void
{
if (Calculator::get() instanceof Calculator\NativeCalculator) {
if (getenv('CI') === 'true') {
Expand Down Expand Up @@ -1419,25 +1418,25 @@ public function testPowerModCrypto() : void
16
);

$alicePublic = $generator->powerMod($alicePrivate, $prime);
$bobPublic = $generator->powerMod($bobPrivate, $prime);
$alicePublic = $generator->modPow($alicePrivate, $prime);
$bobPublic = $generator->modPow($bobPrivate, $prime);

$aliceShared = $bobPublic->powerMod($alicePrivate, $prime);
$bobShared = $alicePublic->powerMod($bobPrivate, $prime);
$aliceShared = $bobPublic->modPow($alicePrivate, $prime);
$bobShared = $alicePublic->modPow($bobPrivate, $prime);

self::assertTrue($aliceShared->isEqualTo($bobShared));
}

/**
* @dataProvider providerPowerModNegativeThrowsException
* @dataProvider providerModPowNegativeThrowsException
*/
public function testPowerModNegativeThrowsException(int $base, int $exp, int $mod) : void
public function testModPowNegativeThrowsException(int $base, int $exp, int $mod) : void
{
$this->expectException(NegativeNumberException::class);
BigInteger::of($base)->powerMod($exp, $mod);
BigInteger::of($base)->modPow($exp, $mod);
}

public function providerPowerModNegativeThrowsException() : array
public function providerModPowNegativeThrowsException() : array
{
return [
[ 1, 1, -1],
Expand All @@ -1446,10 +1445,10 @@ public function providerPowerModNegativeThrowsException() : array
];
}

public function testPowerModZeroThrowsException() : void
public function testModPowZeroThrowsException() : void
{
$this->expectException(DivisionByZeroException::class);
BigInteger::of(1)->powerMod(1, 0);
BigInteger::of(1)->modPow(1, 0);
}

/**
Expand Down

0 comments on commit d493693

Please sign in to comment.