1 | <?php |
||
13 | class ThreemaGateway_Helper_Random |
||
14 | { |
||
15 | /** |
||
16 | * Generates a random numeric string. |
||
17 | * |
||
18 | * @param int $length The length of the string |
||
19 | * @return string |
||
20 | */ |
||
21 | public static function getRandomNumeric($length) |
||
25 | |||
26 | /** |
||
27 | * Generates a random alphabetic string. (only lower letters). |
||
28 | * |
||
29 | * @param int $length The length of the string |
||
30 | * @return string |
||
31 | */ |
||
32 | public static function getRandomAlpha($length) |
||
36 | |||
37 | /** |
||
38 | * Generates a random alphanumeric string. (only lower letters). |
||
39 | * |
||
40 | * This excludes letters which are commonly confused such as O and 0. |
||
41 | * |
||
42 | * @param int $length The length of the string |
||
43 | * @return string |
||
44 | */ |
||
45 | public static function getRandomAlphaNum($length) |
||
49 | |||
50 | /** |
||
51 | * Generates a random string. |
||
52 | * |
||
53 | * Note that they $keyspace parameter may be ignored if libsodium is not |
||
54 | * available as XenForo's native method has a hardcoded keyspace. |
||
55 | * |
||
56 | * @link https://paragonie.com/blog/2015/07/how-safely-generate-random-strings-and-integers-in-php |
||
57 | * @param int $length The length of the string |
||
58 | * @param string $keyspace The characters to choose from |
||
59 | * @return string |
||
60 | */ |
||
61 | public static function getRandomString($length, $keyspace = 'abcdefghijklmnopqrstuvwxyz01234567') |
||
84 | |||
85 | /** |
||
86 | * Generates some random bytes. |
||
87 | * |
||
88 | * @link https://paragonie.com/book/pecl-libsodium/read/02-random-data.md |
||
89 | * @param int $number Number of bytes to return |
||
90 | * @return string |
||
91 | */ |
||
92 | public static function getRandomBytes($number) |
||
125 | |||
126 | /** |
||
127 | * Generates some random integers. |
||
128 | * |
||
129 | * IMPORTANT: This required Libsodium >= 0.2.0. If libsodium is not |
||
130 | * installed |
||
131 | * |
||
132 | * @link https://paragonie.com/book/pecl-libsodium/read/02-random-data.md |
||
133 | * @param int $range Upper bound |
||
134 | * @throws XenForo_Exception |
||
135 | * @return int |
||
136 | */ |
||
137 | public static function getRandomInteger($range) |
||
143 | |||
144 | /** |
||
145 | * Tests whether the libsodium library can be used. |
||
146 | * |
||
147 | * @throws XenForo_Exception |
||
148 | */ |
||
149 | protected static function assertLibsodiumAvailable() |
||
155 | |||
156 | /** |
||
157 | * Tests whether the libsodium library can be used. |
||
158 | * |
||
159 | * @return bool |
||
160 | */ |
||
161 | protected static function canUseLibsodium() |
||
165 | } |
||
166 |