1
0
mirror of https://github.com/danog/phpseclib.git synced 2024-12-12 09:09:39 +01:00

BigInteger: fix for hex numbers with new lines in them

This commit is contained in:
terrafrost 2023-02-11 18:31:58 -06:00
parent de80c6a955
commit e42185c672
2 changed files with 5 additions and 5 deletions

View File

@ -408,7 +408,7 @@ class BigInteger
$x = substr($x, 1); $x = substr($x, 1);
} }
$x = preg_replace('#^(?:0x)?([A-Fa-f0-9]*).*#', '$1', $x); $x = preg_replace('#^(?:0x)?([A-Fa-f0-9]*).*#s', '$1', $x);
$is_negative = false; $is_negative = false;
if ($base < 0 && hexdec($x[0]) >= 8) { if ($base < 0 && hexdec($x[0]) >= 8) {
@ -444,7 +444,7 @@ class BigInteger
// (?<!^)(?:-).*: find any -'s that aren't at the beginning and then any characters that follow that // (?<!^)(?:-).*: find any -'s that aren't at the beginning and then any characters that follow that
// (?<=^|-)0*: find any 0's that are preceded by the start of the string or by a - (ie. octals) // (?<=^|-)0*: find any 0's that are preceded by the start of the string or by a - (ie. octals)
// [^-0-9].*: find any non-numeric characters and then any characters that follow that // [^-0-9].*: find any non-numeric characters and then any characters that follow that
$x = preg_replace('#(?<!^)(?:-).*|(?<=^|-)0*|[^-0-9].*#', '', $x); $x = preg_replace('#(?<!^)(?:-).*|(?<=^|-)0*|[^-0-9].*#s', '', $x);
if (!strlen($x) || $x == '-') { if (!strlen($x) || $x == '-') {
$x = '0'; $x = '0';
} }
@ -486,7 +486,7 @@ class BigInteger
$x = substr($x, 1); $x = substr($x, 1);
} }
$x = preg_replace('#^([01]*).*#', '$1', $x); $x = preg_replace('#^([01]*).*#s', '$1', $x);
$x = str_pad($x, strlen($x) + (3 * strlen($x)) % 4, 0, STR_PAD_LEFT); $x = str_pad($x, strlen($x) + (3 * strlen($x)) % 4, 0, STR_PAD_LEFT);
$str = '0x'; $str = '0x';

View File

@ -459,7 +459,7 @@ FFBD504C5A756A2E6BB5CECC13BCA7503F6DF8B52ACE5C410997E98809DB4DC30D943DE4E81
2A47553DCE54844A78E36401D13F77DC650619FED88D8B3926E3D8E319C80C744779AC5D6AB 2A47553DCE54844A78E36401D13F77DC650619FED88D8B3926E3D8E319C80C744779AC5D6AB
E252896950917476ECE5E8FC27D5F053D6018D91B502C4787558A002B9283DA7', 16); E252896950917476ECE5E8FC27D5F053D6018D91B502C4787558A002B9283DA7', 16);
$y = $this->getInstance('0xE932AC92252F585B3A80A4DD76A897C8B7652952FE788F6EC8DD640587A1EE5647670A8AD'); $y = $this->getInstance('0xE932AC92252F585B3A80A4DD76A897C8B7652952FE788F6EC8DD640587A1EE5647670A8AD', 16);
$this->assertSame($x, $y); $this->assertSame("$x", "$y");
} }
} }