From b9812ba06ac16899df2a25f0abf25962ae3273f2 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 30 May 2023 08:36:17 +0000 Subject: update composer libs --- vendor/spomky-labs/otphp/src/ParameterTrait.php | 32 +++++++++++++++++-------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'vendor/spomky-labs/otphp/src/ParameterTrait.php') diff --git a/vendor/spomky-labs/otphp/src/ParameterTrait.php b/vendor/spomky-labs/otphp/src/ParameterTrait.php index b05092351..3b2641e0c 100644 --- a/vendor/spomky-labs/otphp/src/ParameterTrait.php +++ b/vendor/spomky-labs/otphp/src/ParameterTrait.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace OTPHP; use function array_key_exists; +use function assert; use function in_array; use InvalidArgumentException; use function is_int; @@ -13,18 +14,24 @@ use function is_string; trait ParameterTrait { /** - * @var array + * @var array */ private array $parameters = []; + /** + * @var non-empty-string|null + */ private null|string $issuer = null; + /** + * @var non-empty-string|null + */ private null|string $label = null; private bool $issuer_included_as_parameter = true; /** - * @return array + * @return array */ public function getParameters(): array { @@ -40,7 +47,7 @@ trait ParameterTrait public function getSecret(): string { $value = $this->getParameter('secret'); - is_string($value) || throw new InvalidArgumentException('Invalid "secret" parameter.'); + (is_string($value) && $value !== '') || throw new InvalidArgumentException('Invalid "secret" parameter.'); return $value; } @@ -78,7 +85,7 @@ trait ParameterTrait public function getDigits(): int { $value = $this->getParameter('digits'); - is_int($value) || throw new InvalidArgumentException('Invalid "digits" parameter.'); + (is_int($value) && $value > 0) || throw new InvalidArgumentException('Invalid "digits" parameter.'); return $value; } @@ -86,7 +93,7 @@ trait ParameterTrait public function getDigest(): string { $value = $this->getParameter('algorithm'); - is_string($value) || throw new InvalidArgumentException('Invalid "algorithm" parameter.'); + (is_string($value) && $value !== '') || throw new InvalidArgumentException('Invalid "algorithm" parameter.'); return $value; } @@ -137,20 +144,21 @@ trait ParameterTrait } /** - * @return array + * @return array */ protected function getParameterMap(): array { return [ - 'label' => function ($value) { + 'label' => function (string $value): string { + assert($value !== ''); $this->hasColon($value) === false || throw new InvalidArgumentException( 'Label must not contain a colon.' ); return $value; }, - 'secret' => static fn ($value): string => mb_strtoupper(trim((string) $value, '=')), - 'algorithm' => static function ($value): string { + 'secret' => static fn (string $value): string => mb_strtoupper(trim($value, '=')), + 'algorithm' => static function (string $value): string { $value = mb_strtolower($value); in_array($value, hash_algos(), true) || throw new InvalidArgumentException(sprintf( 'The "%s" digest is not supported.', @@ -164,7 +172,8 @@ trait ParameterTrait return (int) $value; }, - 'issuer' => function ($value) { + 'issuer' => function (string $value): string { + assert($value !== ''); $this->hasColon($value) === false || throw new InvalidArgumentException( 'Issuer must not contain a colon.' ); @@ -174,6 +183,9 @@ trait ParameterTrait ]; } + /** + * @param non-empty-string $value + */ private function hasColon(string $value): bool { $colons = [':', '%3A', '%3a']; -- cgit v1.2.3