Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-inclu.../sodium_c.../src/Core
File: Util.php
<?php
[0] Fix | Delete
[1] Fix | Delete
if (class_exists('ParagonIE_Sodium_Core_Util', false)) {
[2] Fix | Delete
return;
[3] Fix | Delete
}
[4] Fix | Delete
[5] Fix | Delete
/**
[6] Fix | Delete
* Class ParagonIE_Sodium_Core_Util
[7] Fix | Delete
*/
[8] Fix | Delete
abstract class ParagonIE_Sodium_Core_Util
[9] Fix | Delete
{
[10] Fix | Delete
/**
[11] Fix | Delete
* @param int $integer
[12] Fix | Delete
* @param int $size (16, 32, 64)
[13] Fix | Delete
* @return int
[14] Fix | Delete
*/
[15] Fix | Delete
public static function abs($integer, $size = 0)
[16] Fix | Delete
{
[17] Fix | Delete
/** @var int $realSize */
[18] Fix | Delete
$realSize = (PHP_INT_SIZE << 3) - 1;
[19] Fix | Delete
if ($size) {
[20] Fix | Delete
--$size;
[21] Fix | Delete
} else {
[22] Fix | Delete
/** @var int $size */
[23] Fix | Delete
$size = $realSize;
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
$negative = -(($integer >> $size) & 1);
[27] Fix | Delete
return (int) (
[28] Fix | Delete
($integer ^ $negative)
[29] Fix | Delete
+
[30] Fix | Delete
(($negative >> $realSize) & 1)
[31] Fix | Delete
);
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Convert a binary string into a hexadecimal string without cache-timing
[36] Fix | Delete
* leaks
[37] Fix | Delete
*
[38] Fix | Delete
* @internal You should not use this directly from another application
[39] Fix | Delete
*
[40] Fix | Delete
* @param string $binaryString (raw binary)
[41] Fix | Delete
* @return string
[42] Fix | Delete
* @throws TypeError
[43] Fix | Delete
*/
[44] Fix | Delete
public static function bin2hex($binaryString)
[45] Fix | Delete
{
[46] Fix | Delete
/* Type checks: */
[47] Fix | Delete
if (!is_string($binaryString)) {
[48] Fix | Delete
throw new TypeError('Argument 1 must be a string, ' . gettype($binaryString) . ' given.');
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
$hex = '';
[52] Fix | Delete
$len = self::strlen($binaryString);
[53] Fix | Delete
for ($i = 0; $i < $len; ++$i) {
[54] Fix | Delete
/** @var array<int, int> $chunk */
[55] Fix | Delete
$chunk = unpack('C', $binaryString[$i]);
[56] Fix | Delete
/** @var int $c */
[57] Fix | Delete
$c = $chunk[1] & 0xf;
[58] Fix | Delete
/** @var int $b */
[59] Fix | Delete
$b = $chunk[1] >> 4;
[60] Fix | Delete
$hex .= pack(
[61] Fix | Delete
'CC',
[62] Fix | Delete
(87 + $b + ((($b - 10) >> 8) & ~38)),
[63] Fix | Delete
(87 + $c + ((($c - 10) >> 8) & ~38))
[64] Fix | Delete
);
[65] Fix | Delete
}
[66] Fix | Delete
return $hex;
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Convert a binary string into a hexadecimal string without cache-timing
[71] Fix | Delete
* leaks, returning uppercase letters (as per RFC 4648)
[72] Fix | Delete
*
[73] Fix | Delete
* @internal You should not use this directly from another application
[74] Fix | Delete
*
[75] Fix | Delete
* @param string $bin_string (raw binary)
[76] Fix | Delete
* @return string
[77] Fix | Delete
* @throws TypeError
[78] Fix | Delete
*/
[79] Fix | Delete
public static function bin2hexUpper($bin_string)
[80] Fix | Delete
{
[81] Fix | Delete
$hex = '';
[82] Fix | Delete
$len = self::strlen($bin_string);
[83] Fix | Delete
for ($i = 0; $i < $len; ++$i) {
[84] Fix | Delete
/** @var array<int, int> $chunk */
[85] Fix | Delete
$chunk = unpack('C', $bin_string[$i]);
[86] Fix | Delete
/**
[87] Fix | Delete
* Lower 16 bits
[88] Fix | Delete
*
[89] Fix | Delete
* @var int $c
[90] Fix | Delete
*/
[91] Fix | Delete
$c = $chunk[1] & 0xf;
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* Upper 16 bits
[95] Fix | Delete
* @var int $b
[96] Fix | Delete
*/
[97] Fix | Delete
$b = $chunk[1] >> 4;
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Use pack() and binary operators to turn the two integers
[101] Fix | Delete
* into hexadecimal characters. We don't use chr() here, because
[102] Fix | Delete
* it uses a lookup table internally and we want to avoid
[103] Fix | Delete
* cache-timing side-channels.
[104] Fix | Delete
*/
[105] Fix | Delete
$hex .= pack(
[106] Fix | Delete
'CC',
[107] Fix | Delete
(55 + $b + ((($b - 10) >> 8) & ~6)),
[108] Fix | Delete
(55 + $c + ((($c - 10) >> 8) & ~6))
[109] Fix | Delete
);
[110] Fix | Delete
}
[111] Fix | Delete
return $hex;
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
/**
[115] Fix | Delete
* Cache-timing-safe variant of ord()
[116] Fix | Delete
*
[117] Fix | Delete
* @internal You should not use this directly from another application
[118] Fix | Delete
*
[119] Fix | Delete
* @param string $chr
[120] Fix | Delete
* @return int
[121] Fix | Delete
* @throws SodiumException
[122] Fix | Delete
* @throws TypeError
[123] Fix | Delete
*/
[124] Fix | Delete
public static function chrToInt($chr)
[125] Fix | Delete
{
[126] Fix | Delete
/* Type checks: */
[127] Fix | Delete
if (!is_string($chr)) {
[128] Fix | Delete
throw new TypeError('Argument 1 must be a string, ' . gettype($chr) . ' given.');
[129] Fix | Delete
}
[130] Fix | Delete
if (self::strlen($chr) !== 1) {
[131] Fix | Delete
throw new SodiumException('chrToInt() expects a string that is exactly 1 character long');
[132] Fix | Delete
}
[133] Fix | Delete
/** @var array<int, int> $chunk */
[134] Fix | Delete
$chunk = unpack('C', $chr);
[135] Fix | Delete
return (int) ($chunk[1]);
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
/**
[139] Fix | Delete
* Compares two strings.
[140] Fix | Delete
*
[141] Fix | Delete
* @internal You should not use this directly from another application
[142] Fix | Delete
*
[143] Fix | Delete
* @param string $left
[144] Fix | Delete
* @param string $right
[145] Fix | Delete
* @param int $len
[146] Fix | Delete
* @return int
[147] Fix | Delete
* @throws SodiumException
[148] Fix | Delete
* @throws TypeError
[149] Fix | Delete
*/
[150] Fix | Delete
public static function compare($left, $right, $len = null)
[151] Fix | Delete
{
[152] Fix | Delete
$leftLen = self::strlen($left);
[153] Fix | Delete
$rightLen = self::strlen($right);
[154] Fix | Delete
if ($len === null) {
[155] Fix | Delete
$len = max($leftLen, $rightLen);
[156] Fix | Delete
$left = str_pad($left, $len, "\x00", STR_PAD_RIGHT);
[157] Fix | Delete
$right = str_pad($right, $len, "\x00", STR_PAD_RIGHT);
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
$gt = 0;
[161] Fix | Delete
$eq = 1;
[162] Fix | Delete
$i = $len;
[163] Fix | Delete
while ($i !== 0) {
[164] Fix | Delete
--$i;
[165] Fix | Delete
$gt |= ((self::chrToInt($right[$i]) - self::chrToInt($left[$i])) >> 8) & $eq;
[166] Fix | Delete
$eq &= ((self::chrToInt($right[$i]) ^ self::chrToInt($left[$i])) - 1) >> 8;
[167] Fix | Delete
}
[168] Fix | Delete
return ($gt + $gt + $eq) - 1;
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
/**
[172] Fix | Delete
* If a variable does not match a given type, throw a TypeError.
[173] Fix | Delete
*
[174] Fix | Delete
* @param mixed $mixedVar
[175] Fix | Delete
* @param string $type
[176] Fix | Delete
* @param int $argumentIndex
[177] Fix | Delete
* @throws TypeError
[178] Fix | Delete
* @throws SodiumException
[179] Fix | Delete
* @return void
[180] Fix | Delete
*/
[181] Fix | Delete
public static function declareScalarType(&$mixedVar = null, $type = 'void', $argumentIndex = 0)
[182] Fix | Delete
{
[183] Fix | Delete
if (func_num_args() === 0) {
[184] Fix | Delete
/* Tautology, by default */
[185] Fix | Delete
return;
[186] Fix | Delete
}
[187] Fix | Delete
if (func_num_args() === 1) {
[188] Fix | Delete
throw new TypeError('Declared void, but passed a variable');
[189] Fix | Delete
}
[190] Fix | Delete
$realType = strtolower(gettype($mixedVar));
[191] Fix | Delete
$type = strtolower($type);
[192] Fix | Delete
switch ($type) {
[193] Fix | Delete
case 'null':
[194] Fix | Delete
if ($mixedVar !== null) {
[195] Fix | Delete
throw new TypeError('Argument ' . $argumentIndex . ' must be null, ' . $realType . ' given.');
[196] Fix | Delete
}
[197] Fix | Delete
break;
[198] Fix | Delete
case 'integer':
[199] Fix | Delete
case 'int':
[200] Fix | Delete
$allow = array('int', 'integer');
[201] Fix | Delete
if (!in_array($type, $allow)) {
[202] Fix | Delete
throw new TypeError('Argument ' . $argumentIndex . ' must be an integer, ' . $realType . ' given.');
[203] Fix | Delete
}
[204] Fix | Delete
$mixedVar = (int) $mixedVar;
[205] Fix | Delete
break;
[206] Fix | Delete
case 'boolean':
[207] Fix | Delete
case 'bool':
[208] Fix | Delete
$allow = array('bool', 'boolean');
[209] Fix | Delete
if (!in_array($type, $allow)) {
[210] Fix | Delete
throw new TypeError('Argument ' . $argumentIndex . ' must be a boolean, ' . $realType . ' given.');
[211] Fix | Delete
}
[212] Fix | Delete
$mixedVar = (bool) $mixedVar;
[213] Fix | Delete
break;
[214] Fix | Delete
case 'string':
[215] Fix | Delete
if (!is_string($mixedVar)) {
[216] Fix | Delete
throw new TypeError('Argument ' . $argumentIndex . ' must be a string, ' . $realType . ' given.');
[217] Fix | Delete
}
[218] Fix | Delete
$mixedVar = (string) $mixedVar;
[219] Fix | Delete
break;
[220] Fix | Delete
case 'decimal':
[221] Fix | Delete
case 'double':
[222] Fix | Delete
case 'float':
[223] Fix | Delete
$allow = array('decimal', 'double', 'float');
[224] Fix | Delete
if (!in_array($type, $allow)) {
[225] Fix | Delete
throw new TypeError('Argument ' . $argumentIndex . ' must be a float, ' . $realType . ' given.');
[226] Fix | Delete
}
[227] Fix | Delete
$mixedVar = (float) $mixedVar;
[228] Fix | Delete
break;
[229] Fix | Delete
case 'object':
[230] Fix | Delete
if (!is_object($mixedVar)) {
[231] Fix | Delete
throw new TypeError('Argument ' . $argumentIndex . ' must be an object, ' . $realType . ' given.');
[232] Fix | Delete
}
[233] Fix | Delete
break;
[234] Fix | Delete
case 'array':
[235] Fix | Delete
if (!is_array($mixedVar)) {
[236] Fix | Delete
if (is_object($mixedVar)) {
[237] Fix | Delete
if ($mixedVar instanceof ArrayAccess) {
[238] Fix | Delete
return;
[239] Fix | Delete
}
[240] Fix | Delete
}
[241] Fix | Delete
throw new TypeError('Argument ' . $argumentIndex . ' must be an array, ' . $realType . ' given.');
[242] Fix | Delete
}
[243] Fix | Delete
break;
[244] Fix | Delete
default:
[245] Fix | Delete
throw new SodiumException('Unknown type (' . $realType .') does not match expect type (' . $type . ')');
[246] Fix | Delete
}
[247] Fix | Delete
}
[248] Fix | Delete
[249] Fix | Delete
/**
[250] Fix | Delete
* Evaluate whether or not two strings are equal (in constant-time)
[251] Fix | Delete
*
[252] Fix | Delete
* @param string $left
[253] Fix | Delete
* @param string $right
[254] Fix | Delete
* @return bool
[255] Fix | Delete
* @throws SodiumException
[256] Fix | Delete
* @throws TypeError
[257] Fix | Delete
*/
[258] Fix | Delete
public static function hashEquals($left, $right)
[259] Fix | Delete
{
[260] Fix | Delete
/* Type checks: */
[261] Fix | Delete
if (!is_string($left)) {
[262] Fix | Delete
throw new TypeError('Argument 1 must be a string, ' . gettype($left) . ' given.');
[263] Fix | Delete
}
[264] Fix | Delete
if (!is_string($right)) {
[265] Fix | Delete
throw new TypeError('Argument 2 must be a string, ' . gettype($right) . ' given.');
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
if (is_callable('hash_equals')) {
[269] Fix | Delete
return hash_equals($left, $right);
[270] Fix | Delete
}
[271] Fix | Delete
$d = 0;
[272] Fix | Delete
/** @var int $len */
[273] Fix | Delete
$len = self::strlen($left);
[274] Fix | Delete
if ($len !== self::strlen($right)) {
[275] Fix | Delete
return false;
[276] Fix | Delete
}
[277] Fix | Delete
for ($i = 0; $i < $len; ++$i) {
[278] Fix | Delete
$d |= self::chrToInt($left[$i]) ^ self::chrToInt($right[$i]);
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
if ($d !== 0) {
[282] Fix | Delete
return false;
[283] Fix | Delete
}
[284] Fix | Delete
return $left === $right;
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
/**
[288] Fix | Delete
* Catch hash_update() failures and throw instead of silently proceeding
[289] Fix | Delete
*
[290] Fix | Delete
* @param HashContext|resource &$hs
[291] Fix | Delete
* @param string $data
[292] Fix | Delete
* @return void
[293] Fix | Delete
* @throws SodiumException
[294] Fix | Delete
* @psalm-suppress PossiblyInvalidArgument
[295] Fix | Delete
*/
[296] Fix | Delete
protected static function hash_update(&$hs, $data)
[297] Fix | Delete
{
[298] Fix | Delete
if (!hash_update($hs, $data)) {
[299] Fix | Delete
throw new SodiumException('hash_update() failed');
[300] Fix | Delete
}
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
/**
[304] Fix | Delete
* Convert a hexadecimal string into a binary string without cache-timing
[305] Fix | Delete
* leaks
[306] Fix | Delete
*
[307] Fix | Delete
* @internal You should not use this directly from another application
[308] Fix | Delete
*
[309] Fix | Delete
* @param string $hexString
[310] Fix | Delete
* @param string $ignore
[311] Fix | Delete
* @param bool $strictPadding
[312] Fix | Delete
* @return string (raw binary)
[313] Fix | Delete
* @throws RangeException
[314] Fix | Delete
* @throws TypeError
[315] Fix | Delete
*/
[316] Fix | Delete
public static function hex2bin($hexString, $ignore = '', $strictPadding = false)
[317] Fix | Delete
{
[318] Fix | Delete
/* Type checks: */
[319] Fix | Delete
if (!is_string($hexString)) {
[320] Fix | Delete
throw new TypeError('Argument 1 must be a string, ' . gettype($hexString) . ' given.');
[321] Fix | Delete
}
[322] Fix | Delete
if (!is_string($ignore)) {
[323] Fix | Delete
throw new TypeError('Argument 2 must be a string, ' . gettype($hexString) . ' given.');
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
$hex_pos = 0;
[327] Fix | Delete
$bin = '';
[328] Fix | Delete
$c_acc = 0;
[329] Fix | Delete
$hex_len = self::strlen($hexString);
[330] Fix | Delete
$state = 0;
[331] Fix | Delete
if (($hex_len & 1) !== 0) {
[332] Fix | Delete
if ($strictPadding) {
[333] Fix | Delete
throw new RangeException(
[334] Fix | Delete
'Expected an even number of hexadecimal characters'
[335] Fix | Delete
);
[336] Fix | Delete
} else {
[337] Fix | Delete
$hexString = '0' . $hexString;
[338] Fix | Delete
++$hex_len;
[339] Fix | Delete
}
[340] Fix | Delete
}
[341] Fix | Delete
[342] Fix | Delete
$chunk = unpack('C*', $hexString);
[343] Fix | Delete
while ($hex_pos < $hex_len) {
[344] Fix | Delete
++$hex_pos;
[345] Fix | Delete
/** @var int $c */
[346] Fix | Delete
$c = $chunk[$hex_pos];
[347] Fix | Delete
$c_num = $c ^ 48;
[348] Fix | Delete
$c_num0 = ($c_num - 10) >> 8;
[349] Fix | Delete
$c_alpha = ($c & ~32) - 55;
[350] Fix | Delete
$c_alpha0 = (($c_alpha - 10) ^ ($c_alpha - 16)) >> 8;
[351] Fix | Delete
if (($c_num0 | $c_alpha0) === 0) {
[352] Fix | Delete
if ($ignore && $state === 0 && strpos($ignore, self::intToChr($c)) !== false) {
[353] Fix | Delete
continue;
[354] Fix | Delete
}
[355] Fix | Delete
throw new RangeException(
[356] Fix | Delete
'hex2bin() only expects hexadecimal characters'
[357] Fix | Delete
);
[358] Fix | Delete
}
[359] Fix | Delete
$c_val = ($c_num0 & $c_num) | ($c_alpha & $c_alpha0);
[360] Fix | Delete
if ($state === 0) {
[361] Fix | Delete
$c_acc = $c_val * 16;
[362] Fix | Delete
} else {
[363] Fix | Delete
$bin .= pack('C', $c_acc | $c_val);
[364] Fix | Delete
}
[365] Fix | Delete
$state ^= 1;
[366] Fix | Delete
}
[367] Fix | Delete
return $bin;
[368] Fix | Delete
}
[369] Fix | Delete
[370] Fix | Delete
/**
[371] Fix | Delete
* Turn an array of integers into a string
[372] Fix | Delete
*
[373] Fix | Delete
* @internal You should not use this directly from another application
[374] Fix | Delete
*
[375] Fix | Delete
* @param array<int, int> $ints
[376] Fix | Delete
* @return string
[377] Fix | Delete
*/
[378] Fix | Delete
public static function intArrayToString(array $ints)
[379] Fix | Delete
{
[380] Fix | Delete
$args = $ints;
[381] Fix | Delete
foreach ($args as $i => $v) {
[382] Fix | Delete
$args[$i] = (int) ($v & 0xff);
[383] Fix | Delete
}
[384] Fix | Delete
array_unshift($args, str_repeat('C', count($ints)));
[385] Fix | Delete
return (string) (call_user_func_array('pack', $args));
[386] Fix | Delete
}
[387] Fix | Delete
[388] Fix | Delete
/**
[389] Fix | Delete
* Cache-timing-safe variant of ord()
[390] Fix | Delete
*
[391] Fix | Delete
* @internal You should not use this directly from another application
[392] Fix | Delete
*
[393] Fix | Delete
* @param int $int
[394] Fix | Delete
* @return string
[395] Fix | Delete
* @throws TypeError
[396] Fix | Delete
*/
[397] Fix | Delete
public static function intToChr($int)
[398] Fix | Delete
{
[399] Fix | Delete
return pack('C', $int);
[400] Fix | Delete
}
[401] Fix | Delete
[402] Fix | Delete
/**
[403] Fix | Delete
* Load a 3 character substring into an integer
[404] Fix | Delete
*
[405] Fix | Delete
* @internal You should not use this directly from another application
[406] Fix | Delete
*
[407] Fix | Delete
* @param string $string
[408] Fix | Delete
* @return int
[409] Fix | Delete
* @throws RangeException
[410] Fix | Delete
* @throws TypeError
[411] Fix | Delete
*/
[412] Fix | Delete
public static function load_3($string)
[413] Fix | Delete
{
[414] Fix | Delete
/* Type checks: */
[415] Fix | Delete
if (!is_string($string)) {
[416] Fix | Delete
throw new TypeError('Argument 1 must be a string, ' . gettype($string) . ' given.');
[417] Fix | Delete
}
[418] Fix | Delete
[419] Fix | Delete
/* Input validation: */
[420] Fix | Delete
if (self::strlen($string) < 3) {
[421] Fix | Delete
throw new RangeException(
[422] Fix | Delete
'String must be 3 bytes or more; ' . self::strlen($string) . ' given.'
[423] Fix | Delete
);
[424] Fix | Delete
}
[425] Fix | Delete
/** @var array<int, int> $unpacked */
[426] Fix | Delete
$unpacked = unpack('V', $string . "\0");
[427] Fix | Delete
return (int) ($unpacked[1] & 0xffffff);
[428] Fix | Delete
}
[429] Fix | Delete
[430] Fix | Delete
/**
[431] Fix | Delete
* Load a 4 character substring into an integer
[432] Fix | Delete
*
[433] Fix | Delete
* @internal You should not use this directly from another application
[434] Fix | Delete
*
[435] Fix | Delete
* @param string $string
[436] Fix | Delete
* @return int
[437] Fix | Delete
* @throws RangeException
[438] Fix | Delete
* @throws TypeError
[439] Fix | Delete
*/
[440] Fix | Delete
public static function load_4($string)
[441] Fix | Delete
{
[442] Fix | Delete
/* Type checks: */
[443] Fix | Delete
if (!is_string($string)) {
[444] Fix | Delete
throw new TypeError('Argument 1 must be a string, ' . gettype($string) . ' given.');
[445] Fix | Delete
}
[446] Fix | Delete
[447] Fix | Delete
/* Input validation: */
[448] Fix | Delete
if (self::strlen($string) < 4) {
[449] Fix | Delete
throw new RangeException(
[450] Fix | Delete
'String must be 4 bytes or more; ' . self::strlen($string) . ' given.'
[451] Fix | Delete
);
[452] Fix | Delete
}
[453] Fix | Delete
/** @var array<int, int> $unpacked */
[454] Fix | Delete
$unpacked = unpack('V', $string);
[455] Fix | Delete
return (int) $unpacked[1];
[456] Fix | Delete
}
[457] Fix | Delete
[458] Fix | Delete
/**
[459] Fix | Delete
* Load a 8 character substring into an integer
[460] Fix | Delete
*
[461] Fix | Delete
* @internal You should not use this directly from another application
[462] Fix | Delete
*
[463] Fix | Delete
* @param string $string
[464] Fix | Delete
* @return int
[465] Fix | Delete
* @throws RangeException
[466] Fix | Delete
* @throws SodiumException
[467] Fix | Delete
* @throws TypeError
[468] Fix | Delete
*/
[469] Fix | Delete
public static function load64_le($string)
[470] Fix | Delete
{
[471] Fix | Delete
/* Type checks: */
[472] Fix | Delete
if (!is_string($string)) {
[473] Fix | Delete
throw new TypeError('Argument 1 must be a string, ' . gettype($string) . ' given.');
[474] Fix | Delete
}
[475] Fix | Delete
[476] Fix | Delete
/* Input validation: */
[477] Fix | Delete
if (self::strlen($string) < 4) {
[478] Fix | Delete
throw new RangeException(
[479] Fix | Delete
'String must be 4 bytes or more; ' . self::strlen($string) . ' given.'
[480] Fix | Delete
);
[481] Fix | Delete
}
[482] Fix | Delete
if (PHP_VERSION_ID >= 50603 && PHP_INT_SIZE === 8) {
[483] Fix | Delete
/** @var array<int, int> $unpacked */
[484] Fix | Delete
$unpacked = unpack('P', $string);
[485] Fix | Delete
return (int) $unpacked[1];
[486] Fix | Delete
}
[487] Fix | Delete
[488] Fix | Delete
/** @var int $result */
[489] Fix | Delete
$result = (self::chrToInt($string[0]) & 0xff);
[490] Fix | Delete
$result |= (self::chrToInt($string[1]) & 0xff) << 8;
[491] Fix | Delete
$result |= (self::chrToInt($string[2]) & 0xff) << 16;
[492] Fix | Delete
$result |= (self::chrToInt($string[3]) & 0xff) << 24;
[493] Fix | Delete
$result |= (self::chrToInt($string[4]) & 0xff) << 32;
[494] Fix | Delete
$result |= (self::chrToInt($string[5]) & 0xff) << 40;
[495] Fix | Delete
$result |= (self::chrToInt($string[6]) & 0xff) << 48;
[496] Fix | Delete
$result |= (self::chrToInt($string[7]) & 0xff) << 56;
[497] Fix | Delete
return (int) $result;
[498] Fix | Delete
}
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function