@@ -776,15 +776,15 @@ |
||
| 776 | 776 | if (!is_callable('random_int')) |
| 777 | 777 | { |
| 778 | 778 | /** |
| 779 | - * Fetch a random integer between $min and $max inclusive |
|
| 780 | - * |
|
| 781 | - * @param int $min |
|
| 782 | - * @param int $max |
|
| 783 | - * |
|
| 784 | - * @throws Exception |
|
| 785 | - * |
|
| 786 | - * @return int |
|
| 787 | - */ |
|
| 779 | + * Fetch a random integer between $min and $max inclusive |
|
| 780 | + * |
|
| 781 | + * @param int $min |
|
| 782 | + * @param int $max |
|
| 783 | + * |
|
| 784 | + * @throws Exception |
|
| 785 | + * |
|
| 786 | + * @return int |
|
| 787 | + */ |
|
| 788 | 788 | function random_int($min, $max) |
| 789 | 789 | { |
| 790 | 790 | /** |
@@ -371,7 +371,7 @@ |
||
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | return (string) substr( |
| 374 | - (string )$binary_string, |
|
| 374 | + (string) $binary_string, |
|
| 375 | 375 | (int) $start, |
| 376 | 376 | (int) $length |
| 377 | 377 | ); |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | 'member_name' => $regOptions['username'], |
| 587 | 587 | 'email_address' => $regOptions['email'], |
| 588 | 588 | 'passwd' => hash_password($regOptions['username'], $regOptions['password']), |
| 589 | - 'password_salt' => substr(md5($smcFunc['random_int']()), 0, 4) , |
|
| 589 | + 'password_salt' => substr(md5($smcFunc['random_int']()), 0, 4), |
|
| 590 | 590 | 'posts' => 0, |
| 591 | 591 | 'date_registered' => time(), |
| 592 | 592 | 'member_ip' => $regOptions['interface'] == 'admin' ? '127.0.0.1' : $user_info['ip'], |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | 'time_offset', |
| 677 | 677 | ); |
| 678 | 678 | $knownInets = array( |
| 679 | - 'member_ip','member_ip2', |
|
| 679 | + 'member_ip', 'member_ip2', |
|
| 680 | 680 | ); |
| 681 | 681 | |
| 682 | 682 | // Call an optional function to validate the users' input. |
@@ -904,7 +904,7 @@ discard block |
||
| 904 | 904 | $checkName = strtr($name, array('_' => '\\_', '%' => '\\%')); |
| 905 | 905 | |
| 906 | 906 | //when we got no wildcard we can use equal -> fast |
| 907 | - $operator = (strpos($checkName, '%') || strpos($checkName, '_') ? 'LIKE' : '=' ); |
|
| 907 | + $operator = (strpos($checkName, '%') || strpos($checkName, '_') ? 'LIKE' : '='); |
|
| 908 | 908 | |
| 909 | 909 | // Make sure they don't want someone else's name. |
| 910 | 910 | $request = $smcFunc['db_query']('', ' |
@@ -1273,7 +1273,7 @@ discard block |
||
| 1273 | 1273 | $user_info['buddies'][] = $userReceiver; |
| 1274 | 1274 | |
| 1275 | 1275 | // And add a nice alert. Don't abuse though! |
| 1276 | - if ((cache_get_data('Buddy-sent-'. $user_info['id'] .'-'. $userReceiver, 86400)) == null) |
|
| 1276 | + if ((cache_get_data('Buddy-sent-' . $user_info['id'] . '-' . $userReceiver, 86400)) == null) |
|
| 1277 | 1277 | { |
| 1278 | 1278 | $smcFunc['db_insert']('insert', |
| 1279 | 1279 | '{db_prefix}background_tasks', |
@@ -1288,7 +1288,7 @@ discard block |
||
| 1288 | 1288 | ); |
| 1289 | 1289 | |
| 1290 | 1290 | // Store this in a cache entry to avoid creating multiple alerts. Give it a long life cycle. |
| 1291 | - cache_put_data('Buddy-sent-'. $user_info['id'] .'-'. $userReceiver, '1', 86400); |
|
| 1291 | + cache_put_data('Buddy-sent-' . $user_info['id'] . '-' . $userReceiver, '1', 86400); |
|
| 1292 | 1292 | } |
| 1293 | 1293 | } |
| 1294 | 1294 | |
@@ -64,7 +64,8 @@ discard block |
||
| 64 | 64 | { |
| 65 | 65 | $this->buildLookup(); |
| 66 | 66 | |
| 67 | - if ($initKey !== null) { |
|
| 67 | + if ($initKey !== null) |
|
| 68 | + { |
|
| 68 | 69 | $this->setInitKey($initKey); |
| 69 | 70 | } |
| 70 | 71 | } |
@@ -98,7 +99,8 @@ discard block |
||
| 98 | 99 | */ |
| 99 | 100 | public function setRange($range) |
| 100 | 101 | { |
| 101 | - if (!is_numeric($range)) { |
|
| 102 | + if (!is_numeric($range)) |
|
| 103 | + { |
|
| 102 | 104 | throw new \InvalidArgumentException('Invalid window range'); |
| 103 | 105 | } |
| 104 | 106 | $this->range = $range; |
@@ -114,7 +116,8 @@ discard block |
||
| 114 | 116 | */ |
| 115 | 117 | public function setInitKey($key) |
| 116 | 118 | { |
| 117 | - if (preg_match('/^[' . implode('', array_keys($this->getLookup())) . ']+$/', $key) == false) { |
|
| 119 | + if (preg_match('/^[' . implode('', array_keys($this->getLookup())) . ']+$/', $key) == false) |
|
| 120 | + { |
|
| 118 | 121 | throw new \InvalidArgumentException('Invalid base32 hash!'); |
| 119 | 122 | } |
| 120 | 123 | $this->initKey = $key; |
@@ -140,7 +143,8 @@ discard block |
||
| 140 | 143 | */ |
| 141 | 144 | public function setLookup($lookup) |
| 142 | 145 | { |
| 143 | - if (!is_array($lookup)) { |
|
| 146 | + if (!is_array($lookup)) |
|
| 147 | + { |
|
| 144 | 148 | throw new \InvalidArgumentException('Lookup value must be an array'); |
| 145 | 149 | } |
| 146 | 150 | $this->lookup = $lookup; |
@@ -176,7 +180,8 @@ discard block |
||
| 176 | 180 | */ |
| 177 | 181 | public function setRefresh($seconds) |
| 178 | 182 | { |
| 179 | - if (!is_numeric($seconds)) { |
|
| 183 | + if (!is_numeric($seconds)) |
|
| 184 | + { |
|
| 180 | 185 | throw new \InvalidArgumentException('Seconds must be numeric'); |
| 181 | 186 | } |
| 182 | 187 | $this->refreshSeconds = $seconds; |
@@ -217,7 +222,8 @@ discard block |
||
| 217 | 222 | */ |
| 218 | 223 | public function validateCode($code, $initKey = null, $timestamp = null, $range = null) |
| 219 | 224 | { |
| 220 | - if (strlen($code) !== $this->getCodeLength()) { |
|
| 225 | + if (strlen($code) !== $this->getCodeLength()) |
|
| 226 | + { |
|
| 221 | 227 | throw new \InvalidArgumentException('Incorrect code length'); |
| 222 | 228 | } |
| 223 | 229 | |
@@ -227,8 +233,10 @@ discard block |
||
| 227 | 233 | |
| 228 | 234 | $binary = $this->base32_decode($initKey); |
| 229 | 235 | |
| 230 | - for ($time = ($timestamp - $range); $time <= ($timestamp + $range); $time++) { |
|
| 231 | - if ($this->generateOneTime($binary, $time) == $code) { |
|
| 236 | + for ($time = ($timestamp - $range); $time <= ($timestamp + $range); $time++) |
|
| 237 | + { |
|
| 238 | + if ($this->generateOneTime($binary, $time) == $code) |
|
| 239 | + { |
|
| 232 | 240 | return true; |
| 233 | 241 | } |
| 234 | 242 | } |
@@ -269,7 +277,8 @@ discard block |
||
| 269 | 277 | $lookup = implode('', array_keys($this->getLookup())); |
| 270 | 278 | $code = ''; |
| 271 | 279 | |
| 272 | - for ($i = 0; $i < $length; $i++) { |
|
| 280 | + for ($i = 0; $i < $length; $i++) |
|
| 281 | + { |
|
| 273 | 282 | $code .= $lookup[$smcFunc['random_int'](0, strlen($lookup) - 1)]; |
| 274 | 283 | } |
| 275 | 284 | |
@@ -315,7 +324,8 @@ discard block |
||
| 315 | 324 | { |
| 316 | 325 | $lookup = $this->getLookup(); |
| 317 | 326 | |
| 318 | - if (preg_match('/^[' . implode('', array_keys($lookup)) . ']+$/', $hash) == false) { |
|
| 327 | + if (preg_match('/^[' . implode('', array_keys($lookup)) . ']+$/', $hash) == false) |
|
| 328 | + { |
|
| 319 | 329 | throw new \InvalidArgumentException('Invalid base32 hash!'); |
| 320 | 330 | } |
| 321 | 331 | |
@@ -324,12 +334,14 @@ discard block |
||
| 324 | 334 | $length = 0; |
| 325 | 335 | $binary = ''; |
| 326 | 336 | |
| 327 | - for ($i = 0; $i < strlen($hash); $i++) { |
|
| 337 | + for ($i = 0; $i < strlen($hash); $i++) |
|
| 338 | + { |
|
| 328 | 339 | $buffer = $buffer << 5; |
| 329 | 340 | $buffer += $lookup[$hash[$i]]; |
| 330 | 341 | $length += 5; |
| 331 | 342 | |
| 332 | - if ($length >= 8) { |
|
| 343 | + if ($length >= 8) |
|
| 344 | + { |
|
| 333 | 345 | $length -= 8; |
| 334 | 346 | $binary .= chr(($buffer & (0xFF << $length)) >> $length); |
| 335 | 347 | } |
@@ -18,7 +18,8 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | namespace { |
| 20 | 20 | |
| 21 | - if (!defined('PASSWORD_DEFAULT')) { |
|
| 21 | + if (!defined('PASSWORD_DEFAULT')) |
|
| 22 | + { |
|
| 22 | 23 | |
| 23 | 24 | define('PASSWORD_BCRYPT', 1); |
| 24 | 25 | define('PASSWORD_DEFAULT', PASSWORD_BCRYPT); |
@@ -34,31 +35,39 @@ discard block |
||
| 34 | 35 | * |
| 35 | 36 | * @return string|false The hashed password, or false on error. |
| 36 | 37 | */ |
| 37 | - function password_hash($password, $algo, array $options = array()) { |
|
| 38 | + function password_hash($password, $algo, array $options = array()) |
|
| 39 | + { |
|
| 38 | 40 | global $smcFunc; |
| 39 | 41 | |
| 40 | - if (!function_exists('crypt')) { |
|
| 42 | + if (!function_exists('crypt')) |
|
| 43 | + { |
|
| 41 | 44 | trigger_error("Crypt must be loaded for password_hash to function", E_USER_WARNING); |
| 42 | 45 | return null; |
| 43 | 46 | } |
| 44 | - if (!is_string($password)) { |
|
| 47 | + if (!is_string($password)) |
|
| 48 | + { |
|
| 45 | 49 | trigger_error("password_hash(): Password must be a string", E_USER_WARNING); |
| 46 | 50 | return null; |
| 47 | 51 | } |
| 48 | - if (!is_int($algo)) { |
|
| 52 | + if (!is_int($algo)) |
|
| 53 | + { |
|
| 49 | 54 | trigger_error("password_hash() expects parameter 2 to be long, " . gettype($algo) . " given", E_USER_WARNING); |
| 50 | 55 | return null; |
| 51 | 56 | } |
| 52 | - if (PasswordCompat\binary\_strlen($password) > 72) { |
|
| 57 | + if (PasswordCompat\binary\_strlen($password) > 72) |
|
| 58 | + { |
|
| 53 | 59 | $password = PasswordCompat\binary\_substr($password, 0, 72); |
| 54 | 60 | } |
| 55 | - switch ($algo) { |
|
| 61 | + switch ($algo) |
|
| 62 | + { |
|
| 56 | 63 | case PASSWORD_BCRYPT: |
| 57 | 64 | // Note that this is a C constant, but not exposed to PHP, so we don't define it here. |
| 58 | 65 | $cost = 10; |
| 59 | - if (isset($options['cost'])) { |
|
| 66 | + if (isset($options['cost'])) |
|
| 67 | + { |
|
| 60 | 68 | $cost = $options['cost']; |
| 61 | - if ($cost < 4 || $cost > 31) { |
|
| 69 | + if ($cost < 4 || $cost > 31) |
|
| 70 | + { |
|
| 62 | 71 | trigger_error(sprintf("password_hash(): Invalid bcrypt cost parameter specified: %d", $cost), E_USER_WARNING); |
| 63 | 72 | return null; |
| 64 | 73 | } |
@@ -76,8 +85,10 @@ discard block |
||
| 76 | 85 | return null; |
| 77 | 86 | } |
| 78 | 87 | $salt_requires_encoding = false; |
| 79 | - if (isset($options['salt'])) { |
|
| 80 | - switch (gettype($options['salt'])) { |
|
| 88 | + if (isset($options['salt'])) |
|
| 89 | + { |
|
| 90 | + switch (gettype($options['salt'])) |
|
| 91 | + { |
|
| 81 | 92 | case 'NULL': |
| 82 | 93 | case 'boolean': |
| 83 | 94 | case 'integer': |
@@ -86,7 +97,8 @@ discard block |
||
| 86 | 97 | $salt = (string) $options['salt']; |
| 87 | 98 | break; |
| 88 | 99 | case 'object': |
| 89 | - if (method_exists($options['salt'], '__tostring')) { |
|
| 100 | + if (method_exists($options['salt'], '__tostring')) |
|
| 101 | + { |
|
| 90 | 102 | $salt = (string) $options['salt']; |
| 91 | 103 | break; |
| 92 | 104 | } |
@@ -96,51 +108,70 @@ discard block |
||
| 96 | 108 | trigger_error('password_hash(): Non-string salt parameter supplied', E_USER_WARNING); |
| 97 | 109 | return null; |
| 98 | 110 | } |
| 99 | - if (PasswordCompat\binary\_strlen($salt) < $required_salt_len) { |
|
| 111 | + if (PasswordCompat\binary\_strlen($salt) < $required_salt_len) |
|
| 112 | + { |
|
| 100 | 113 | trigger_error(sprintf("password_hash(): Provided salt is too short: %d expecting %d", PasswordCompat\binary\_strlen($salt), $required_salt_len), E_USER_WARNING); |
| 101 | 114 | return null; |
| 102 | - } elseif (0 == preg_match('#^[a-zA-Z0-9./]+$#D', $salt)) { |
|
| 115 | + } |
|
| 116 | + elseif (0 == preg_match('#^[a-zA-Z0-9./]+$#D', $salt)) |
|
| 117 | + { |
|
| 103 | 118 | $salt_requires_encoding = true; |
| 104 | 119 | } |
| 105 | - } else { |
|
| 120 | + } |
|
| 121 | + else |
|
| 122 | + { |
|
| 106 | 123 | $buffer = ''; |
| 107 | 124 | $buffer_valid = false; |
| 108 | - if (function_exists('random_bytes')) { |
|
| 125 | + if (function_exists('random_bytes')) |
|
| 126 | + { |
|
| 109 | 127 | $buffer = random_bytes($raw_salt_len); |
| 110 | - if ($buffer) { |
|
| 128 | + if ($buffer) |
|
| 129 | + { |
|
| 111 | 130 | $buffer_valid = true; |
| 112 | 131 | } |
| 113 | 132 | } |
| 114 | - if (!$buffer_valid && function_exists('mcrypt_create_iv') && !defined('PHALANGER')) { |
|
| 133 | + if (!$buffer_valid && function_exists('mcrypt_create_iv') && !defined('PHALANGER')) |
|
| 134 | + { |
|
| 115 | 135 | $buffer = mcrypt_create_iv($raw_salt_len, MCRYPT_DEV_URANDOM); |
| 116 | - if ($buffer) { |
|
| 136 | + if ($buffer) |
|
| 137 | + { |
|
| 117 | 138 | $buffer_valid = true; |
| 118 | 139 | } |
| 119 | 140 | } |
| 120 | - if (!$buffer_valid && function_exists('openssl_random_pseudo_bytes')) { |
|
| 141 | + if (!$buffer_valid && function_exists('openssl_random_pseudo_bytes')) |
|
| 142 | + { |
|
| 121 | 143 | $buffer = openssl_random_pseudo_bytes($raw_salt_len); |
| 122 | - if ($buffer) { |
|
| 144 | + if ($buffer) |
|
| 145 | + { |
|
| 123 | 146 | $buffer_valid = true; |
| 124 | 147 | } |
| 125 | 148 | } |
| 126 | - if (!$buffer_valid && @is_readable('/dev/urandom')) { |
|
| 149 | + if (!$buffer_valid && @is_readable('/dev/urandom')) |
|
| 150 | + { |
|
| 127 | 151 | $f = fopen('/dev/urandom', 'r'); |
| 128 | 152 | $read = PasswordCompat\binary\_strlen($buffer); |
| 129 | - while ($read < $raw_salt_len) { |
|
| 153 | + while ($read < $raw_salt_len) |
|
| 154 | + { |
|
| 130 | 155 | $buffer .= fread($f, $raw_salt_len - $read); |
| 131 | 156 | $read = PasswordCompat\binary\_strlen($buffer); |
| 132 | 157 | } |
| 133 | 158 | fclose($f); |
| 134 | - if ($read >= $raw_salt_len) { |
|
| 159 | + if ($read >= $raw_salt_len) |
|
| 160 | + { |
|
| 135 | 161 | $buffer_valid = true; |
| 136 | 162 | } |
| 137 | 163 | } |
| 138 | - if (!$buffer_valid || PasswordCompat\binary\_strlen($buffer) < $raw_salt_len) { |
|
| 164 | + if (!$buffer_valid || PasswordCompat\binary\_strlen($buffer) < $raw_salt_len) |
|
| 165 | + { |
|
| 139 | 166 | $bl = PasswordCompat\binary\_strlen($buffer); |
| 140 | - for ($i = 0; $i < $raw_salt_len; $i++) { |
|
| 141 | - if ($i < $bl) { |
|
| 167 | + for ($i = 0; $i < $raw_salt_len; $i++) |
|
| 168 | + { |
|
| 169 | + if ($i < $bl) |
|
| 170 | + { |
|
| 142 | 171 | $buffer[$i] = $buffer[$i] ^ chr($smcFunc['random_int'](0, 255)); |
| 143 | - } else { |
|
| 172 | + } |
|
| 173 | + else |
|
| 174 | + { |
|
| 144 | 175 | $buffer .= chr($smcFunc['random_int'](0, 255)); |
| 145 | 176 | } |
| 146 | 177 | } |
@@ -148,7 +179,8 @@ discard block |
||
| 148 | 179 | $salt = $buffer; |
| 149 | 180 | $salt_requires_encoding = true; |
| 150 | 181 | } |
| 151 | - if ($salt_requires_encoding) { |
|
| 182 | + if ($salt_requires_encoding) |
|
| 183 | + { |
|
| 152 | 184 | // encode string with the Base64 variant used by crypt |
| 153 | 185 | $base64_digits = |
| 154 | 186 | 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; |
@@ -164,7 +196,8 @@ discard block |
||
| 164 | 196 | |
| 165 | 197 | $ret = crypt($password, $hash); |
| 166 | 198 | |
| 167 | - if (!is_string($ret) || PasswordCompat\binary\_strlen($ret) != $resultLength) { |
|
| 199 | + if (!is_string($ret) || PasswordCompat\binary\_strlen($ret) != $resultLength) |
|
| 200 | + { |
|
| 168 | 201 | return false; |
| 169 | 202 | } |
| 170 | 203 | |
@@ -187,13 +220,15 @@ discard block |
||
| 187 | 220 | * |
| 188 | 221 | * @return array The array of information about the hash. |
| 189 | 222 | */ |
| 190 | - function password_get_info($hash) { |
|
| 223 | + function password_get_info($hash) |
|
| 224 | + { |
|
| 191 | 225 | $return = array( |
| 192 | 226 | 'algo' => 0, |
| 193 | 227 | 'algoName' => 'unknown', |
| 194 | 228 | 'options' => array(), |
| 195 | 229 | ); |
| 196 | - if (PasswordCompat\binary\_substr($hash, 0, 4) == '$2y$' && PasswordCompat\binary\_strlen($hash) == 60) { |
|
| 230 | + if (PasswordCompat\binary\_substr($hash, 0, 4) == '$2y$' && PasswordCompat\binary\_strlen($hash) == 60) |
|
| 231 | + { |
|
| 197 | 232 | $return['algo'] = PASSWORD_BCRYPT; |
| 198 | 233 | $return['algoName'] = 'bcrypt'; |
| 199 | 234 | list($cost) = sscanf($hash, "$2y$%d$"); |
@@ -213,15 +248,19 @@ discard block |
||
| 213 | 248 | * |
| 214 | 249 | * @return boolean True if the password needs to be rehashed. |
| 215 | 250 | */ |
| 216 | - function password_needs_rehash($hash, $algo, array $options = array()) { |
|
| 251 | + function password_needs_rehash($hash, $algo, array $options = array()) |
|
| 252 | + { |
|
| 217 | 253 | $info = password_get_info($hash); |
| 218 | - if ($info['algo'] != $algo) { |
|
| 254 | + if ($info['algo'] != $algo) |
|
| 255 | + { |
|
| 219 | 256 | return true; |
| 220 | 257 | } |
| 221 | - switch ($algo) { |
|
| 258 | + switch ($algo) |
|
| 259 | + { |
|
| 222 | 260 | case PASSWORD_BCRYPT: |
| 223 | 261 | $cost = isset($options['cost']) ? $options['cost'] : 10; |
| 224 | - if ($cost != $info['options']['cost']) { |
|
| 262 | + if ($cost != $info['options']['cost']) |
|
| 263 | + { |
|
| 225 | 264 | return true; |
| 226 | 265 | } |
| 227 | 266 | break; |
@@ -237,21 +276,26 @@ discard block |
||
| 237 | 276 | * |
| 238 | 277 | * @return boolean If the password matches the hash |
| 239 | 278 | */ |
| 240 | - function password_verify($password, $hash) { |
|
| 241 | - if (!function_exists('crypt')) { |
|
| 279 | + function password_verify($password, $hash) |
|
| 280 | + { |
|
| 281 | + if (!function_exists('crypt')) |
|
| 282 | + { |
|
| 242 | 283 | trigger_error("Crypt must be loaded for password_verify to function", E_USER_WARNING); |
| 243 | 284 | return false; |
| 244 | 285 | } |
| 245 | - if (PasswordCompat\binary\_strlen($password) > 72) { |
|
| 286 | + if (PasswordCompat\binary\_strlen($password) > 72) |
|
| 287 | + { |
|
| 246 | 288 | $password = PasswordCompat\binary\_substr($password, 0, 72); |
| 247 | 289 | } |
| 248 | 290 | $ret = crypt($password, $hash); |
| 249 | - if (!is_string($ret) || PasswordCompat\binary\_strlen($ret) != PasswordCompat\binary\_strlen($hash) || PasswordCompat\binary\_strlen($ret) <= 13) { |
|
| 291 | + if (!is_string($ret) || PasswordCompat\binary\_strlen($ret) != PasswordCompat\binary\_strlen($hash) || PasswordCompat\binary\_strlen($ret) <= 13) |
|
| 292 | + { |
|
| 250 | 293 | return false; |
| 251 | 294 | } |
| 252 | 295 | |
| 253 | 296 | $status = 0; |
| 254 | - for ($i = 0; $i < PasswordCompat\binary\_strlen($ret); $i++) { |
|
| 297 | + for ($i = 0; $i < PasswordCompat\binary\_strlen($ret); $i++) |
|
| 298 | + { |
|
| 255 | 299 | $status |= (ord($ret[$i]) ^ ord($hash[$i])); |
| 256 | 300 | } |
| 257 | 301 | |
@@ -273,8 +317,10 @@ discard block |
||
| 273 | 317 | * @internal |
| 274 | 318 | * @return int The number of bytes |
| 275 | 319 | */ |
| 276 | - function _strlen($binary_string) { |
|
| 277 | - if (function_exists('mb_strlen')) { |
|
| 320 | + function _strlen($binary_string) |
|
| 321 | + { |
|
| 322 | + if (function_exists('mb_strlen')) |
|
| 323 | + { |
|
| 278 | 324 | return mb_strlen($binary_string, '8bit'); |
| 279 | 325 | } |
| 280 | 326 | return strlen($binary_string); |
@@ -292,8 +338,10 @@ discard block |
||
| 292 | 338 | * @internal |
| 293 | 339 | * @return string The substring |
| 294 | 340 | */ |
| 295 | - function _substr($binary_string, $start, $length) { |
|
| 296 | - if (function_exists('mb_substr')) { |
|
| 341 | + function _substr($binary_string, $start, $length) |
|
| 342 | + { |
|
| 343 | + if (function_exists('mb_substr')) |
|
| 344 | + { |
|
| 297 | 345 | return mb_substr($binary_string, $start, $length, '8bit'); |
| 298 | 346 | } |
| 299 | 347 | return substr($binary_string, $start, $length); |