diff --git a/generated/8.1/functionsList.php b/generated/8.1/functionsList.php index c170d754..2ec34c4a 100644 --- a/generated/8.1/functionsList.php +++ b/generated/8.1/functionsList.php @@ -264,6 +264,8 @@ 'gztell', 'gzuncompress', 'gzwrite', + 'hash_file', + 'hash_hmac_file', 'hash_update_file', 'header_register_callback', 'hex2bin', diff --git a/generated/8.1/rector-migrate.php b/generated/8.1/rector-migrate.php index f74d9bc4..6fd91b65 100644 --- a/generated/8.1/rector-migrate.php +++ b/generated/8.1/rector-migrate.php @@ -272,6 +272,8 @@ 'gztell' => 'Safe\gztell', 'gzuncompress' => 'Safe\gzuncompress', 'gzwrite' => 'Safe\gzwrite', + 'hash_file' => 'Safe\hash_file', + 'hash_hmac_file' => 'Safe\hash_hmac_file', 'hash_update_file' => 'Safe\hash_update_file', 'header_register_callback' => 'Safe\header_register_callback', 'hex2bin' => 'Safe\hex2bin', diff --git a/generated/8.2/functionsList.php b/generated/8.2/functionsList.php index bb161c46..a6f203e2 100644 --- a/generated/8.2/functionsList.php +++ b/generated/8.2/functionsList.php @@ -269,6 +269,8 @@ 'gztell', 'gzuncompress', 'gzwrite', + 'hash_file', + 'hash_hmac_file', 'hash_update_file', 'header_register_callback', 'hex2bin', diff --git a/generated/8.2/rector-migrate.php b/generated/8.2/rector-migrate.php index da4eae51..7dfc8482 100644 --- a/generated/8.2/rector-migrate.php +++ b/generated/8.2/rector-migrate.php @@ -277,6 +277,8 @@ 'gztell' => 'Safe\gztell', 'gzuncompress' => 'Safe\gzuncompress', 'gzwrite' => 'Safe\gzwrite', + 'hash_file' => 'Safe\hash_file', + 'hash_hmac_file' => 'Safe\hash_hmac_file', 'hash_update_file' => 'Safe\hash_update_file', 'header_register_callback' => 'Safe\header_register_callback', 'hex2bin' => 'Safe\hex2bin', diff --git a/generated/8.3/functionsList.php b/generated/8.3/functionsList.php index bb161c46..a6f203e2 100644 --- a/generated/8.3/functionsList.php +++ b/generated/8.3/functionsList.php @@ -269,6 +269,8 @@ 'gztell', 'gzuncompress', 'gzwrite', + 'hash_file', + 'hash_hmac_file', 'hash_update_file', 'header_register_callback', 'hex2bin', diff --git a/generated/8.3/rector-migrate.php b/generated/8.3/rector-migrate.php index da4eae51..7dfc8482 100644 --- a/generated/8.3/rector-migrate.php +++ b/generated/8.3/rector-migrate.php @@ -277,6 +277,8 @@ 'gztell' => 'Safe\gztell', 'gzuncompress' => 'Safe\gzuncompress', 'gzwrite' => 'Safe\gzwrite', + 'hash_file' => 'Safe\hash_file', + 'hash_hmac_file' => 'Safe\hash_hmac_file', 'hash_update_file' => 'Safe\hash_update_file', 'header_register_callback' => 'Safe\header_register_callback', 'hex2bin' => 'Safe\hex2bin', diff --git a/generated/8.4/functionsList.php b/generated/8.4/functionsList.php index 2b371b9f..b29dc325 100644 --- a/generated/8.4/functionsList.php +++ b/generated/8.4/functionsList.php @@ -268,6 +268,8 @@ 'gztell', 'gzuncompress', 'gzwrite', + 'hash_file', + 'hash_hmac_file', 'hash_update_file', 'header_register_callback', 'hex2bin', diff --git a/generated/8.4/rector-migrate.php b/generated/8.4/rector-migrate.php index c497c581..ec0e3bc1 100644 --- a/generated/8.4/rector-migrate.php +++ b/generated/8.4/rector-migrate.php @@ -276,6 +276,8 @@ 'gztell' => 'Safe\gztell', 'gzuncompress' => 'Safe\gzuncompress', 'gzwrite' => 'Safe\gzwrite', + 'hash_file' => 'Safe\hash_file', + 'hash_hmac_file' => 'Safe\hash_hmac_file', 'hash_update_file' => 'Safe\hash_update_file', 'header_register_callback' => 'Safe\header_register_callback', 'hex2bin' => 'Safe\hex2bin', diff --git a/generated/8.5/functionsList.php b/generated/8.5/functionsList.php index d011a1d4..2bac0f65 100644 --- a/generated/8.5/functionsList.php +++ b/generated/8.5/functionsList.php @@ -269,6 +269,7 @@ 'gzuncompress', 'gzwrite', 'hash_file', + 'hash_hmac_file', 'hash_update_file', 'header_register_callback', 'hex2bin', diff --git a/generated/8.5/hash.php b/generated/8.5/hash.php index abf90721..255b05ea 100644 --- a/generated/8.5/hash.php +++ b/generated/8.5/hash.php @@ -4,34 +4,6 @@ use Safe\Exceptions\HashException; -/** - * - * - * @param string $algo Name of selected hashing algorithm (e.g. "sha256"). - * For a list of supported algorithms see hash_algos. - * @param string $filename URL describing location of file to be hashed; Supports fopen wrappers. - * @param bool $binary When set to TRUE, outputs raw binary data. - * FALSE outputs lowercase hexits. - * @param array $options An array of options for the various hashing algorithms. - * Currently, only the "seed" parameter is - * supported by the MurmurHash variants. - * @return non-falsy-string Returns a string containing the calculated message digest as lowercase hexits - * unless binary is set to true in which case the raw - * binary representation of the message digest is returned. - * @throws HashException - * - */ -function hash_file(string $algo, string $filename, bool $binary = false, array $options = []): string -{ - error_clear_last(); - $safeResult = \hash_file($algo, $filename, $binary, $options); - if ($safeResult === false) { - throw HashException::createFromPhpError(); - } - return $safeResult; -} - - /** * * diff --git a/generated/8.5/rector-migrate.php b/generated/8.5/rector-migrate.php index 302eb8dc..c74b8a12 100644 --- a/generated/8.5/rector-migrate.php +++ b/generated/8.5/rector-migrate.php @@ -277,6 +277,7 @@ 'gzuncompress' => 'Safe\gzuncompress', 'gzwrite' => 'Safe\gzwrite', 'hash_file' => 'Safe\hash_file', + 'hash_hmac_file' => 'Safe\hash_hmac_file', 'hash_update_file' => 'Safe\hash_update_file', 'header_register_callback' => 'Safe\header_register_callback', 'hex2bin' => 'Safe\hex2bin', diff --git a/lib/special_cases.php b/lib/special_cases.php index 3b191ffe..dec26515 100644 --- a/lib/special_cases.php +++ b/lib/special_cases.php @@ -18,6 +18,7 @@ use Safe\Exceptions\PcreException; use Safe\Exceptions\SimplexmlException; use Safe\Exceptions\FilesystemException; +use Safe\Exceptions\HashException; use const PREG_NO_ERROR; @@ -429,3 +430,64 @@ function passthru(string $command, ?int &$result_code = null): void throw ExecException::createFromPhpError(); } } + +/** + * + * + * @param string $algo Name of selected hashing algorithm (e.g. "sha256"). + * For a list of supported algorithms see hash_algos. + * @param string $filename URL describing location of file to be hashed; Supports fopen wrappers. + * @param bool $binary When set to TRUE, outputs raw binary data. + * FALSE outputs lowercase hexits. + * @phpstan-param array $options + * @param array $options An array of options for the various hashing algorithms. + * Currently, only the "seed" parameter is + * supported by the MurmurHash variants. + * @return non-falsy-string Returns a string containing the calculated message digest as lowercase hexits + * unless binary is set to true in which case the raw + * binary representation of the message digest is returned. + * @throws HashException + * + */ +function hash_file(string $algo, string $filename, bool $binary = false, array $options = []): string +{ + error_clear_last(); + $safeResult = \hash_file($algo, $filename, $binary, $options); + if ($safeResult === false) { + throw HashException::createFromPhpError(); + } + return $safeResult; +} + +/** + * + * + * @param string $algo Name of selected hashing algorithm (e.g. "sha256"). + * For a list of supported algorithms see hash_hmac_algos. + * + * + * Non-cryptographic hash functions are not allowed. + * + * + * + * Non-cryptographic hash functions are not allowed. + * @param string $filename URL describing location of file to be hashed; Supports fopen wrappers. + * @param string $key Shared secret key used for generating the HMAC variant of the message digest. + * @param bool $binary When set to TRUE, outputs raw binary data. + * FALSE outputs lowercase hexits. + * @return non-falsy-string Returns a string containing the calculated message digest as lowercase hexits + * unless binary is set to true in which case the raw + * binary representation of the message digest is returned. + * Returns FALSE if the file filename cannot be read. + * @throws HashException + * + */ +function hash_hmac_file(string $algo, string $filename, string $key, bool $binary = false): string +{ + error_clear_last(); + $safeResult = \hash_hmac_file($algo, $filename, $key, $binary); + if ($safeResult === false) { + throw HashException::createFromPhpError(); + } + return $safeResult; +}