aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/spomky-labs/otphp/src/TOTP.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2023-05-30 08:36:17 +0000
committerMario <mario@mariovavti.com>2023-05-30 08:36:17 +0000
commitb9812ba06ac16899df2a25f0abf25962ae3273f2 (patch)
tree35762d0183f5b0c6d866b00cdeebfbae595cfa56 /vendor/spomky-labs/otphp/src/TOTP.php
parentbc6aded074156ec81084334a4d6aa58bc0f37a68 (diff)
downloadvolse-hubzilla-b9812ba06ac16899df2a25f0abf25962ae3273f2.tar.gz
volse-hubzilla-b9812ba06ac16899df2a25f0abf25962ae3273f2.tar.bz2
volse-hubzilla-b9812ba06ac16899df2a25f0abf25962ae3273f2.zip
update composer libs
Diffstat (limited to 'vendor/spomky-labs/otphp/src/TOTP.php')
-rw-r--r--vendor/spomky-labs/otphp/src/TOTP.php19
1 files changed, 14 insertions, 5 deletions
diff --git a/vendor/spomky-labs/otphp/src/TOTP.php b/vendor/spomky-labs/otphp/src/TOTP.php
index e9bce9e14..3a7d72870 100644
--- a/vendor/spomky-labs/otphp/src/TOTP.php
+++ b/vendor/spomky-labs/otphp/src/TOTP.php
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace OTPHP;
+use function assert;
use InvalidArgumentException;
use function is_int;
@@ -50,7 +51,7 @@ final class TOTP extends OTP implements TOTPInterface
public function getPeriod(): int
{
$value = $this->getParameter('period');
- is_int($value) || throw new InvalidArgumentException('Invalid "period" parameter.');
+ (is_int($value) && $value > 0) || throw new InvalidArgumentException('Invalid "period" parameter.');
return $value;
}
@@ -58,7 +59,7 @@ final class TOTP extends OTP implements TOTPInterface
public function getEpoch(): int
{
$value = $this->getParameter('epoch');
- is_int($value) || throw new InvalidArgumentException('Invalid "epoch" parameter.');
+ (is_int($value) && $value >= 0) || throw new InvalidArgumentException('Invalid "epoch" parameter.');
return $value;
}
@@ -128,7 +129,7 @@ final class TOTP extends OTP implements TOTPInterface
}
/**
- * @return array<string, callable>
+ * @return array<non-empty-string, callable>
*/
protected function getParameterMap(): array
{
@@ -152,7 +153,7 @@ final class TOTP extends OTP implements TOTPInterface
}
/**
- * @param array<string, mixed> $options
+ * @param array<non-empty-string, mixed> $options
*/
protected function filterOptions(array &$options): void
{
@@ -165,8 +166,16 @@ final class TOTP extends OTP implements TOTPInterface
ksort($options);
}
+ /**
+ * @param 0|positive-int $timestamp
+ *
+ * @return 0|positive-int
+ */
private function timecode(int $timestamp): int
{
- return (int) floor(($timestamp - $this->getEpoch()) / $this->getPeriod());
+ $timecode = (int) floor(($timestamp - $this->getEpoch()) / $this->getPeriod());
+ assert($timecode >= 0);
+
+ return $timecode;
}
}