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