🐛 correct some minor issues

This commit is contained in:
William Hall
2021-03-08 18:20:07 +00:00
parent 2aa6f46e20
commit 58d3354367
3 changed files with 10 additions and 13 deletions
+3 -3
View File
@@ -16,12 +16,12 @@ class NTPTimeProvider implements ITimeProvider
$this->host = $host;
if (!is_int($port) || $port <= 0 || $port > 65535) {
throw new \TimeException('Port must be 0 < port < 65535');
throw new TimeException('Port must be 0 < port < 65535');
}
$this->port = $port;
if (!is_int($timeout) || $timeout < 0) {
throw new \TimeException('Timeout must be >= 0');
throw new TimeException('Timeout must be >= 0');
}
$this->timeout = $timeout;
}
@@ -46,7 +46,7 @@ class NTPTimeProvider implements ITimeProvider
/* Interpret response */
$data = unpack('N12', $recv);
$timestamp = sprintf('%u', $data[9]);
$timestamp = (int) sprintf('%u', $data[9]);
/* NTP is number of seconds since 0000 UT on 1 January 1900 Unix time is seconds since 0000 UT on 1 January 1970 */
return $timestamp - 2208988800;
+4 -8
View File
@@ -62,7 +62,7 @@ class TwoFactorAuth
public function createSecret($bits = 80, $requirecryptosecure = true)
{
$secret = '';
$bytes = ceil($bits / 5); //We use 5 bits of each byte (since we have a 32-character 'alphabet' / BASE32)
$bytes = (int) ceil($bits / 5); //We use 5 bits of each byte (since we have a 32-character 'alphabet' / BASE32)
$rngprovider = $this->getRngProvider();
if ($requirecryptosecure && !$rngprovider->isCryptographicallySecure()) {
throw new TwoFactorAuthException('RNG provider is not cryptographically secure');
@@ -87,7 +87,7 @@ class TwoFactorAuth
$value = unpack('N', $hashpart); // Unpack binary value
$value = $value[1] & 0x7FFFFFFF; // Drop MSB, keep only 31 bits
return str_pad($value % pow(10, $this->digits), $this->digits, '0', STR_PAD_LEFT);
return str_pad((string) ($value % pow(10, $this->digits)), $this->digits, '0', STR_PAD_LEFT);
}
/**
@@ -153,10 +153,6 @@ class TwoFactorAuth
*/
public function ensureCorrectTime(array $timeproviders = null, $leniency = 5)
{
if ($timeproviders !== null && !is_array($timeproviders)) {
throw new TwoFactorAuthException('No timeproviders specified');
}
if ($timeproviders === null) {
$timeproviders = array(
new NTPTimeProvider(),
@@ -216,7 +212,7 @@ class TwoFactorAuth
$buffer = '';
foreach (str_split($value) as $char) {
if ($char !== '=') {
$buffer .= str_pad(decbin(self::$_base32lookup[$char]), 5, 0, STR_PAD_LEFT);
$buffer .= str_pad(decbin(self::$_base32lookup[$char]), 5, '0', STR_PAD_LEFT);
}
}
$length = strlen($buffer);
@@ -224,7 +220,7 @@ class TwoFactorAuth
$output = '';
foreach (explode(' ', $blocks) as $block) {
$output .= chr(bindec(str_pad($block, 8, 0, STR_PAD_RIGHT)));
$output .= chr(bindec(str_pad($block, 8, '0', STR_PAD_RIGHT)));
}
return $output;
}
+3 -2
View File
@@ -14,10 +14,11 @@ trait MightNotMakeAssertions
{
foreach (class_parents($this) as $parent) {
if (method_exists($parent, 'expectNotToPerformAssertions')) {
return parent::expectNotToPerformAssertions();
parent::expectNotToPerformAssertions();
return;
}
}
return $this->assertTrue(true);
$this->assertTrue(true);
}
}