diff options
author | Mario <mario@mariovavti.com> | 2023-07-11 18:57:18 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2023-07-11 18:57:18 +0000 |
commit | 63fb8d03929189bfc8cbf53d23cb79984fe2c3cd (patch) | |
tree | b9f74bd8c7721dca7ece251fdbb9a7c4fe9b949a /vendor/spomky-labs/otphp/src/OTP.php | |
parent | 57796a2f962d045445cbf69237bb3d6786e4d0d4 (diff) | |
parent | 384de0925e502cfa8fe6ca287530ef5529fdff10 (diff) | |
download | volse-hubzilla-8.6.tar.gz volse-hubzilla-8.6.tar.bz2 volse-hubzilla-8.6.zip |
Merge branch '8.6RC'8.6
Diffstat (limited to 'vendor/spomky-labs/otphp/src/OTP.php')
-rw-r--r-- | vendor/spomky-labs/otphp/src/OTP.php | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/vendor/spomky-labs/otphp/src/OTP.php b/vendor/spomky-labs/otphp/src/OTP.php index 2cba067b3..4765d49eb 100644 --- a/vendor/spomky-labs/otphp/src/OTP.php +++ b/vendor/spomky-labs/otphp/src/OTP.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace OTPHP; +use function assert; use function chr; use function count; use Exception; @@ -49,6 +50,10 @@ abstract class OTP implements OTPInterface /** * The OTP at the specified input. + * + * @param 0|positive-int $input + * + * @return non-empty-string */ protected function generateOTP(int $input): string { @@ -65,7 +70,7 @@ abstract class OTP implements OTPInterface } /** - * @param array<string, mixed> $options + * @param array<non-empty-string, mixed> $options */ protected function filterOptions(array &$options): void { @@ -83,7 +88,10 @@ abstract class OTP implements OTPInterface } /** - * @param array<string, mixed> $options + * @param non-empty-string $type + * @param array<non-empty-string, mixed> $options + * + * @return non-empty-string */ protected function generateURI(string $type, array $options): string { @@ -102,20 +110,33 @@ abstract class OTP implements OTPInterface ); } + /** + * @param non-empty-string $safe + * @param non-empty-string $user + */ protected function compareOTP(string $safe, string $user): bool { return hash_equals($safe, $user); } + /** + * @return non-empty-string + */ private function getDecodedSecret(): string { try { - return Base32::decodeUpper($this->getSecret()); + $decoded = Base32::decodeUpper($this->getSecret()); } catch (Exception) { throw new RuntimeException('Unable to decode the secret. Is it correctly base32 encoded?'); } + assert($decoded !== ''); + + return $decoded; } + /** + * @param 0|positive-int $int + */ private function intToByteString(int $int): string { $result = []; |