File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -46,9 +46,18 @@ class Tokens
4646 *
4747 * @return string
4848 * Hex-encoded SHA-256 hash (64 characters).
49+ *
50+ * @throws \RuntimeException if pepper is empty
4951 */
5052 public static function exact (string $ normalized , string $ pepper ): string
5153 {
54+ if (empty ($ pepper )) {
55+ throw new \RuntimeException (
56+ 'SEARCH_PEPPER is not configured. Set it in your .env file for security. ' .
57+ 'Generate a random string: openssl rand -base64 32 '
58+ );
59+ }
60+
5261 return hash ('sha256 ' , $ normalized . $ pepper );
5362 }
5463
@@ -71,9 +80,18 @@ public static function exact(string $normalized, string $pepper): string
7180 *
7281 * @return string[]
7382 * An array of hex-encoded SHA-256 prefix tokens.
83+ *
84+ * @throws \RuntimeException if pepper is empty
7485 */
7586 public static function prefixes (string $ normalized , int $ maxDepth , string $ pepper ): array
7687 {
88+ if (empty ($ pepper )) {
89+ throw new \RuntimeException (
90+ 'SEARCH_PEPPER is not configured. Set it in your .env file for security. ' .
91+ 'Generate a random string: openssl rand -base64 32 '
92+ );
93+ }
94+
7795 $ out = [];
7896 $ len = mb_strlen ($ normalized , 'UTF-8 ' );
7997 $ depth = min ($ maxDepth , $ len );
You can’t perform that action at this time.
0 commit comments