Skip to content

Commit a438f83

Browse files
sandesh-asSpomky
authored andcommitted
Fix PHP 8.5 deprecation
1 parent 52b0c9b commit a438f83

File tree

1 file changed

+7
-3
lines changed
  • src/Library/Signature/Algorithm/Util

1 file changed

+7
-3
lines changed

src/Library/Signature/Algorithm/Util/RSA.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ private static function encodeEMSAPSS(string $message, int $modulusLength, Hash
147147
$db = $ps . chr(1) . $salt;
148148
$dbMask = self::getMGF1($h, $emLen - $hash->getLength() - 1, $hash);
149149
$maskedDB = $db ^ $dbMask;
150-
$maskedDB[0] = ~chr(0xFF << ($modulusLength & 7)) & $maskedDB[0];
150+
// PHP 8.5 Compatibility: Constrain value to 0-255 before passing to chr()
151+
$shiftBits = $modulusLength & 7;
152+
$maskedDB[0] = ~chr((0xFF << $shiftBits) & 0xFF) & $maskedDB[0];
151153

152154
return $maskedDB . $h . chr(0xBC);
153155
}
@@ -168,13 +170,15 @@ private static function verifyEMSAPSS(string $m, string $em, int $emBits, Hash $
168170
}
169171
$maskedDB = substr($em, 0, -$hash->getLength() - 1);
170172
$h = substr($em, -$hash->getLength() - 1, $hash->getLength());
171-
$temp = chr(0xFF << ($emBits & 7));
173+
// PHP 8.5 Compatibility: Constrain value to 0-255 before passing to chr()
174+
$shiftBits = $emBits & 7;
175+
$temp = chr((0xFF << $shiftBits) & 0xFF);
172176
if ((~$maskedDB[0] & $temp) !== $temp) {
173177
throw new InvalidArgumentException();
174178
}
175179
$dbMask = self::getMGF1($h, $emLen - $hash->getLength() - 1, $hash/*MGF*/);
176180
$db = $maskedDB ^ $dbMask;
177-
$db[0] = ~chr(0xFF << ($emBits & 7)) & $db[0];
181+
$db[0] = ~chr((0xFF << $shiftBits) & 0xFF) & $db[0];
178182
$temp = $emLen - $hash->getLength() - $sLen - 2;
179183
if (substr($db, 0, $temp) !== str_repeat(chr(0), $temp)) {
180184
throw new InvalidArgumentException();

0 commit comments

Comments
 (0)