1 | <?php declare(strict_types=1); |
||
31 | final class Str |
||
32 | { |
||
33 | /** |
||
34 | * Compares two strings in constant time. Strings are hashed before |
||
35 | * comparison so information is not leaked when strings are not of |
||
36 | * equal length. |
||
37 | * |
||
38 | * @param string $known The string of known length to compare against |
||
39 | * @param string $given The string that the user can control |
||
40 | * @return bool |
||
41 | */ |
||
42 | 25 | public static function equal(string $known, string $given): bool |
|
53 | |||
54 | /** |
||
55 | * Determine the length of the output of a given hash algorithm in bytes. |
||
56 | * |
||
57 | * @param string $algo Name of algorithm to look up |
||
58 | * @return int |
||
59 | */ |
||
60 | 26 | public static function hashSize(string $algo): int |
|
64 | |||
65 | /** |
||
66 | * Returns the number of bytes in a string. |
||
67 | * |
||
68 | * @param string $string The string whose length we wish to obtain |
||
69 | * @return int |
||
70 | */ |
||
71 | 34 | public static function strlen(string $string): int |
|
75 | |||
76 | /** |
||
77 | * Returns part of a string. |
||
78 | * |
||
79 | * @param string $string The string whose length we wish to obtain |
||
80 | * @param int $start |
||
81 | * @param int $length |
||
82 | * |
||
83 | * @return string the extracted part of string; or FALSE on failure, or an empty string. |
||
84 | */ |
||
85 | 24 | public static function substr(string $string, int $start, int $length = null): string |
|
89 | } |
||
90 |