public static function ParagonIE_Sodium_Core_Util::load64_le in Automatic Updates 7
Same name and namespace in other branches
- 8 vendor/paragonie/sodium_compat/src/Core/Util.php \ParagonIE_Sodium_Core_Util::load64_le()
Load a 8 character substring into an integer
@internal You should not use this directly from another application
Parameters
string $string:
Return value
int
Throws
RangeException
SodiumException
TypeError
File
- vendor/
paragonie/ sodium_compat/ src/ Core/ Util.php, line 459
Class
- ParagonIE_Sodium_Core_Util
- Class ParagonIE_Sodium_Core_Util
Code
public static function load64_le($string) {
/* Type checks: */
if (!is_string($string)) {
throw new TypeError('Argument 1 must be a string, ' . gettype($string) . ' given.');
}
/* Input validation: */
if (self::strlen($string) < 4) {
throw new RangeException('String must be 4 bytes or more; ' . self::strlen($string) . ' given.');
}
if (PHP_VERSION_ID >= 50603 && PHP_INT_SIZE === 8) {
/** @var array<int, int> $unpacked */
$unpacked = unpack('P', $string);
return (int) $unpacked[1];
}
/** @var int $result */
$result = self::chrToInt($string[0]) & 0xff;
$result |= (self::chrToInt($string[1]) & 0xff) << 8;
$result |= (self::chrToInt($string[2]) & 0xff) << 16;
$result |= (self::chrToInt($string[3]) & 0xff) << 24;
$result |= (self::chrToInt($string[4]) & 0xff) << 32;
$result |= (self::chrToInt($string[5]) & 0xff) << 40;
$result |= (self::chrToInt($string[6]) & 0xff) << 48;
$result |= (self::chrToInt($string[7]) & 0xff) << 56;
return (int) $result;
}