equal
deleted
inserted
replaced
285 } |
285 } |
286 return $left === $right; |
286 return $left === $right; |
287 } |
287 } |
288 |
288 |
289 /** |
289 /** |
290 * Catch hash_update() failures and throw instead of silently proceding |
290 * Catch hash_update() failures and throw instead of silently proceeding |
291 * |
291 * |
292 * @param HashContext|resource &$hs |
292 * @param HashContext|resource &$hs |
293 * @param string $data |
293 * @param string $data |
294 * @return void |
294 * @return void |
295 * @throws SodiumException |
295 * @throws SodiumException |
456 'String must be 4 bytes or more; ' . self::strlen($string) . ' given.' |
456 'String must be 4 bytes or more; ' . self::strlen($string) . ' given.' |
457 ); |
457 ); |
458 } |
458 } |
459 /** @var array<int, int> $unpacked */ |
459 /** @var array<int, int> $unpacked */ |
460 $unpacked = unpack('V', $string); |
460 $unpacked = unpack('V', $string); |
461 return (int) ($unpacked[1] & 0xffffffff); |
461 return (int) $unpacked[1]; |
462 } |
462 } |
463 |
463 |
464 /** |
464 /** |
465 * Load a 8 character substring into an integer |
465 * Load a 8 character substring into an integer |
466 * |
466 * |
584 for ($i = $size; $i >= 0; --$i) { |
584 for ($i = $size; $i >= 0; --$i) { |
585 $c += (int) ($a & -($b & 1)); |
585 $c += (int) ($a & -($b & 1)); |
586 $a <<= 1; |
586 $a <<= 1; |
587 $b >>= 1; |
587 $b >>= 1; |
588 } |
588 } |
|
589 $c = (int) @($c & -1); |
589 |
590 |
590 /** |
591 /** |
591 * If $b was negative, we then apply the same value to $c here. |
592 * If $b was negative, we then apply the same value to $c here. |
592 * It doesn't matter much if $a was negative; the $c += above would |
593 * It doesn't matter much if $a was negative; the $c += above would |
593 * have produced a negative integer to begin with. But a negative $b |
594 * have produced a negative integer to begin with. But a negative $b |
610 */ |
611 */ |
611 public static function numericTo64BitInteger($num) |
612 public static function numericTo64BitInteger($num) |
612 { |
613 { |
613 $high = 0; |
614 $high = 0; |
614 /** @var int $low */ |
615 /** @var int $low */ |
615 $low = $num & 0xffffffff; |
616 if (PHP_INT_SIZE === 4) { |
|
617 $low = (int) $num; |
|
618 } else { |
|
619 $low = $num & 0xffffffff; |
|
620 } |
616 |
621 |
617 if ((+(abs($num))) >= 1) { |
622 if ((+(abs($num))) >= 1) { |
618 if ($num > 0) { |
623 if ($num > 0) { |
619 /** @var int $high */ |
624 /** @var int $high */ |
620 $high = min((+(floor($num/4294967296))), 4294967295); |
625 $high = min((+(floor($num/4294967296))), 4294967295); |
927 protected static function isMbStringOverride() |
932 protected static function isMbStringOverride() |
928 { |
933 { |
929 static $mbstring = null; |
934 static $mbstring = null; |
930 |
935 |
931 if ($mbstring === null) { |
936 if ($mbstring === null) { |
|
937 if (!defined('MB_OVERLOAD_STRING')) { |
|
938 $mbstring = false; |
|
939 return $mbstring; |
|
940 } |
932 $mbstring = extension_loaded('mbstring') |
941 $mbstring = extension_loaded('mbstring') |
933 && defined('MB_OVERLOAD_STRING') |
942 && defined('MB_OVERLOAD_STRING') |
934 && |
943 && |
935 ((int) (ini_get('mbstring.func_overload')) & 2); |
944 ((int) (ini_get('mbstring.func_overload')) & 2); |
936 // MB_OVERLOAD_STRING === 2 |
945 // MB_OVERLOAD_STRING === 2 |