Merge branch '3.0'

This commit is contained in:
terrafrost 2023-07-26 22:00:22 -05:00
commit 5babbd028c
2 changed files with 22 additions and 2 deletions

View File

@ -294,8 +294,11 @@ class Integer extends Base
*/ */
public function toBytes(): string public function toBytes(): string
{ {
$length = static::$modulo[$this->instanceID]->getLengthInBytes(); if (isset(static::$modulo[$this->instanceID])) {
return str_pad($this->value->toBytes(), $length, "\0", STR_PAD_LEFT); $length = static::$modulo[$this->instanceID]->getLengthInBytes();
return str_pad($this->value->toBytes(), $length, "\0", STR_PAD_LEFT);
}
return $this->value->toBytes();
} }
/** /**

View File

@ -22,4 +22,21 @@ class PrimeFieldTest extends PhpseclibTestCase
echo $num2->squareRoot(); echo $num2->squareRoot();
} }
/**
* @group github1929
*/
public function testGarbageCollectedToBytes()
{
$blob = base64_decode('BFgsTFQeqKr0toyURbtT43INMDS7FTHjz3yn3MR1/Yv/pb2b9ZCYNQ/Tafe5hQpEJ4TpZOKfikP/hWZvFL8QCPgqbIGqw/KTfA==');
$public = "\0" . substr($blob, 0, 49);
$private = substr($blob, -24);
$point = \phpseclib3\Crypt\EC\Formats\Keys\PKCS1::extractPoint(
$public,
new \phpseclib3\Crypt\EC\Curves\secp192r1()
);
$this->assertIsString($point[0]->toBytes());
}
} }