Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Support/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,18 @@ class Tokens
*
* @return string
* Hex-encoded SHA-256 hash (64 characters).
*
* @throws \RuntimeException if pepper is empty
*/
public static function exact(string $normalized, string $pepper): string
{
if (empty($pepper)) {
throw new \RuntimeException(
'SEARCH_PEPPER is not configured. Set it in your .env file for security. ' .
'Generate a random string: openssl rand -base64 32'
);
}

return hash('sha256', $normalized . $pepper);
}

Expand All @@ -71,9 +80,18 @@ public static function exact(string $normalized, string $pepper): string
*
* @return string[]
* An array of hex-encoded SHA-256 prefix tokens.
*
* @throws \RuntimeException if pepper is empty
*/
public static function prefixes(string $normalized, int $maxDepth, string $pepper): array
{
if (empty($pepper)) {
throw new \RuntimeException(
'SEARCH_PEPPER is not configured. Set it in your .env file for security. ' .
'Generate a random string: openssl rand -base64 32'
);
}

$out = [];
$len = mb_strlen($normalized, 'UTF-8');
$depth = min($maxDepth, $len);
Expand Down
Loading