1 | <?php |
||
32 | final class Str |
||
33 | { |
||
34 | /** |
||
35 | * Compares two strings in constant time. Strings are hashed before |
||
36 | * comparison so information is not leaked when strings are not of |
||
37 | * equal length. |
||
38 | * |
||
39 | * @param string $known The string of known length to compare against |
||
40 | * @param string $given The string that the user can control |
||
41 | * |
||
42 | 14 | * @return bool |
|
43 | */ |
||
44 | 14 | public static function equal(string $known, string $given): bool |
|
56 | |||
57 | /** |
||
58 | * Determine the length of the output of a given hash algorithm in bytes. |
||
59 | * |
||
60 | * @param string $algo Name of algorithm to look up |
||
61 | * |
||
62 | * @return int |
||
63 | */ |
||
64 | public static function hashSize(string $algo): int |
||
68 | |||
69 | /** |
||
70 | * Returns the number of bytes in a string. |
||
71 | 14 | * |
|
72 | * @param string $string The string whose length we wish to obtain |
||
73 | 14 | * |
|
74 | 14 | * @return int |
|
75 | */ |
||
76 | 14 | public static function strlen(string $string): int |
|
84 | |||
85 | /** |
||
86 | * Returns part of a string. |
||
87 | * |
||
88 | * @param string $string The string whose length we wish to obtain |
||
89 | * @param int $start |
||
90 | 10 | * @param int $length |
|
91 | * |
||
92 | 10 | * @return string the extracted part of string; or FALSE on failure, or an empty string. |
|
93 | */ |
||
94 | public static function substr(string $string, int $start, int $length = null): string |
||
107 | } |
||
108 |