All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 3m3s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 16s
Build, Push and Deploy / deploy-staging (push) Successful in 32s
Build, Push and Deploy / deploy-production (push) Has been skipped
Build, Push and Deploy / cleanup (push) Successful in 1s
62 lines
1.9 KiB
PHP
62 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Safe;
|
|
|
|
use Safe\Exceptions\HashException;
|
|
|
|
/**
|
|
*
|
|
*
|
|
* @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 $key Input keying material (raw binary). Cannot be empty.
|
|
* @param int $length Desired output length in bytes.
|
|
* Cannot be greater than 255 times the chosen hash function size.
|
|
*
|
|
* If length is 0, the output length
|
|
* will default to the chosen hash function size.
|
|
* @param string $info Application/context-specific info string.
|
|
* @param string $salt Salt to use during derivation.
|
|
*
|
|
* While optional, adding random salt significantly improves the strength of HKDF.
|
|
* @return false|non-falsy-string Returns a string containing a raw binary representation of the derived key
|
|
* (also known as output keying material - OKM).
|
|
*
|
|
*/
|
|
function hash_hkdf(string $algo, string $key, int $length = 0, string $info = "", string $salt = "")
|
|
{
|
|
error_clear_last();
|
|
$safeResult = \hash_hkdf($algo, $key, $length, $info, $salt);
|
|
return $safeResult;
|
|
}
|
|
|
|
|
|
/**
|
|
*
|
|
*
|
|
* @param \HashContext $context Hashing context returned by hash_init.
|
|
* @param string $filename URL describing location of file to be hashed; Supports fopen wrappers.
|
|
* @param \HashContext|null $stream_context Stream context as returned by stream_context_create.
|
|
* @throws HashException
|
|
*
|
|
*/
|
|
function hash_update_file(\HashContext $context, string $filename, ?\HashContext $stream_context = null): void
|
|
{
|
|
error_clear_last();
|
|
if ($stream_context !== null) {
|
|
$safeResult = \hash_update_file($context, $filename, $stream_context);
|
|
} else {
|
|
$safeResult = \hash_update_file($context, $filename);
|
|
}
|
|
if ($safeResult === false) {
|
|
throw HashException::createFromPhpError();
|
|
}
|
|
}
|