wp/wp-includes/sodium_compat/src/Core/Util.php
changeset 18 be944660c56a
parent 9 177826044cd9
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
   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
       
   291      *
       
   292      * @param HashContext|resource &$hs
       
   293      * @param string $data
       
   294      * @return void
       
   295      * @throws SodiumException
       
   296      * @psalm-suppress PossiblyInvalidArgument
       
   297      */
       
   298     protected static function hash_update(&$hs, $data)
       
   299     {
       
   300         if (!hash_update($hs, $data)) {
       
   301             throw new SodiumException('hash_update() failed');
       
   302         }
       
   303     }
       
   304 
       
   305     /**
   290      * Convert a hexadecimal string into a binary string without cache-timing
   306      * Convert a hexadecimal string into a binary string without cache-timing
   291      * leaks
   307      * leaks
   292      *
   308      *
   293      * @internal You should not use this directly from another application
   309      * @internal You should not use this directly from another application
   294      *
   310      *
   901     /**
   917     /**
   902      * Returns whether or not mbstring.func_overload is in effect.
   918      * Returns whether or not mbstring.func_overload is in effect.
   903      *
   919      *
   904      * @internal You should not use this directly from another application
   920      * @internal You should not use this directly from another application
   905      *
   921      *
       
   922      * Note: MB_OVERLOAD_STRING === 2, but we don't reference the constant
       
   923      * (for nuisance-free PHP 8 support)
       
   924      *
   906      * @return bool
   925      * @return bool
   907      */
   926      */
   908     protected static function isMbStringOverride()
   927     protected static function isMbStringOverride()
   909     {
   928     {
   910         static $mbstring = null;
   929         static $mbstring = null;
   911 
   930 
   912         if ($mbstring === null) {
   931         if ($mbstring === null) {
   913             $mbstring = extension_loaded('mbstring')
   932             $mbstring = extension_loaded('mbstring')
       
   933                 && defined('MB_OVERLOAD_STRING')
   914                 &&
   934                 &&
   915             ((int) (ini_get('mbstring.func_overload')) & MB_OVERLOAD_STRING);
   935             ((int) (ini_get('mbstring.func_overload')) & 2);
       
   936             // MB_OVERLOAD_STRING === 2
   916         }
   937         }
   917         /** @var bool $mbstring */
   938         /** @var bool $mbstring */
   918 
   939 
   919         return $mbstring;
   940         return $mbstring;
   920     }
   941     }