1 | <?php |
||
35 | final class Str |
||
36 | { |
||
37 | /** |
||
38 | * Compares two strings in constant time. Strings are hashed before |
||
39 | * comparison so information is not leaked when strings are not of |
||
40 | * equal length. |
||
41 | * |
||
42 | * @param string $known The string of known length to compare against |
||
43 | * @param string $given The string that the user can control |
||
44 | * |
||
45 | * @return bool |
||
46 | */ |
||
47 | 34 | public static function equal(string $known, string $given): bool |
|
58 | |||
59 | /** |
||
60 | * Determine the length of the output of a given hash algorithm in bytes. |
||
61 | * |
||
62 | * @param string $algo Name of algorithm to look up |
||
63 | * |
||
64 | * @return int |
||
65 | */ |
||
66 | 35 | public static function hashSize(string $algo): int |
|
70 | |||
71 | /** |
||
72 | * Returns the number of bytes in a string. |
||
73 | * |
||
74 | * @param string $string The string whose length we wish to obtain |
||
75 | * |
||
76 | * @return int |
||
77 | */ |
||
78 | 44 | public static function strlen(string $string): int |
|
82 | |||
83 | /** |
||
84 | * Returns part of a string. |
||
85 | * |
||
86 | * @param string $string The string whose length we wish to obtain |
||
87 | * @param int $start Offset to start gathering output |
||
88 | * @param int $length Distance from starting offset to gather |
||
89 | * |
||
90 | * @return string |
||
91 | */ |
||
92 | 33 | public static function substr( |
|
99 | } |
||
100 |