1 | <?php |
||
32 | final class Str |
||
33 | { |
||
34 | |||
35 | /** |
||
36 | * Private constant-time strcmp method to use when hash_equals is unavailable. |
||
37 | * |
||
38 | * @param string $knownHash Hash of the known string |
||
39 | * @param string $givenHash Hash of the given string |
||
40 | * |
||
41 | * @return bool true if the two strings are the same, false otherwise |
||
42 | */ |
||
43 | 12 | private static function strcmp($knownHash, $givenHash) |
|
56 | |||
57 | /** |
||
58 | * Compares two strings in constant time. Strings are hashed before |
||
59 | * comparison so information is not leaked when strings are not of |
||
60 | * equal length. |
||
61 | * |
||
62 | * @param string $known The string of known length to compare against |
||
63 | * @param string $given The string that the user can control |
||
64 | * |
||
65 | * @return bool |
||
66 | */ |
||
67 | 12 | public static function equal($known, $given) |
|
83 | |||
84 | /** |
||
85 | * Determine the length of the output of a given hash algorithm in bytes. |
||
86 | * |
||
87 | * @param string $algo Name of algorithm to look up |
||
88 | * |
||
89 | * @return int |
||
90 | */ |
||
91 | 10 | public static function hashSize($algo) |
|
95 | |||
96 | /** |
||
97 | * Returns the number of bytes in a string. |
||
98 | * |
||
99 | * @param string $string The string whose length we wish to obtain |
||
100 | * |
||
101 | * @return int |
||
102 | */ |
||
103 | 20 | public static function strlen($string) |
|
111 | |||
112 | /** |
||
113 | * Returns part of a string. |
||
114 | * |
||
115 | * @param string $string The string whose length we wish to obtain |
||
116 | * @param int $start |
||
117 | * @param int $length |
||
118 | * |
||
119 | * @return string the extracted part of string; or FALSE on failure, or an empty string. |
||
120 | */ |
||
121 | 14 | public static function substr($string, $start, $length = null) |
|
134 | |||
135 | } |
||
136 |