1 | <?php |
||
37 | final class Str |
||
38 | { |
||
39 | /** |
||
40 | * Compares two strings in constant time. Strings are hashed before |
||
41 | * comparison so information is not leaked when strings are not of |
||
42 | * equal length. |
||
43 | * |
||
44 | * @param string $known The string of known length to compare against |
||
45 | * @param string $given The string that the user can control |
||
46 | * |
||
47 | * @throws Exception |
||
48 | * |
||
49 | * @return bool |
||
50 | */ |
||
51 | 37 | public static function equal(string $known, string $given): bool |
|
62 | |||
63 | /** |
||
64 | * Determine the length of the output of a given hash algorithm in bytes. |
||
65 | * |
||
66 | * @param string $algo Name of algorithm to look up |
||
67 | * |
||
68 | * @return int |
||
69 | */ |
||
70 | 38 | public static function hashSize(string $algo): int |
|
74 | |||
75 | /** |
||
76 | * Returns the number of bytes in a string. |
||
77 | * |
||
78 | * @param string $string The string whose length we wish to obtain |
||
79 | * |
||
80 | * @return int |
||
81 | */ |
||
82 | 39 | public static function strlen(string $string): int |
|
86 | |||
87 | /** |
||
88 | * Returns part of a string. |
||
89 | * |
||
90 | * @param string $string The string whose length we wish to obtain |
||
91 | * @param int $start Offset to start gathering output |
||
92 | * @param int|null $length Distance from starting offset to gather |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | 36 | public static function substr(string $string, int $start, int $length = null): string |
|
100 | |||
101 | /** |
||
102 | * Shifts bytes off of the front of a string and return. Input string is modified. |
||
103 | * |
||
104 | * @param string $input |
||
105 | * @param int $bytes |
||
106 | * |
||
107 | * @return string |
||
108 | */ |
||
109 | 36 | public static function shift(string &$input, int $bytes): string |
|
117 | } |
||
118 |