1
0
mirror of https://github.com/danog/tgseclib.git synced 2024-11-30 04:39:02 +01:00

Merge branch '2.0'

This commit is contained in:
terrafrost 2019-09-15 17:31:53 -05:00
commit 677a15c122
3 changed files with 25 additions and 0 deletions

View File

@ -517,7 +517,14 @@ class GMP extends Engine
$result->bitmask = $this->bitmask;
if ($result->bitmask !== false) {
$flip = $result->value < 0;
if ($flip) {
$result->value = -$result->value;
}
$result->value = $result->value & $result->bitmask->value;
if ($flip) {
$result->value = -$result->value;
}
}
return $result;

View File

@ -157,6 +157,7 @@ abstract class PHP extends Engine
}
$temp = clone $this;
$temp->bitmask = false;
$temp->is_negative = false;
$divisor = new static();

View File

@ -485,4 +485,21 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase
$temp = $this->getInstance('-0');
$this->assertSame($temp->toString(), '0');
}
public function testNegativePrecision()
{
$vals = [
'-9223372036854775808', // eg. 8000 0000 0000 0000
'-1'
];
foreach ($vals as $val) {
$x = $this->getInstance($val);
$x->setPrecision(64); // ie. 8 bytes
$this->assertSame($val, "$x");
$r = $x->toBytes(true);
$this->assertSame(8, strlen($r));
$x2 = $this->getInstance($r, -256);
$this->assertSame(0, $x->compare($x2));
}
}
}