diff options
author | Mario <mario@mariovavti.com> | 2023-05-30 08:36:17 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2023-05-30 08:36:17 +0000 |
commit | b9812ba06ac16899df2a25f0abf25962ae3273f2 (patch) | |
tree | 35762d0183f5b0c6d866b00cdeebfbae595cfa56 /vendor/spomky-labs/otphp/src/ParameterTrait.php | |
parent | bc6aded074156ec81084334a4d6aa58bc0f37a68 (diff) | |
download | volse-hubzilla-b9812ba06ac16899df2a25f0abf25962ae3273f2.tar.gz volse-hubzilla-b9812ba06ac16899df2a25f0abf25962ae3273f2.tar.bz2 volse-hubzilla-b9812ba06ac16899df2a25f0abf25962ae3273f2.zip |
update composer libs
Diffstat (limited to 'vendor/spomky-labs/otphp/src/ParameterTrait.php')
-rw-r--r-- | vendor/spomky-labs/otphp/src/ParameterTrait.php | 32 |
1 files changed, 22 insertions, 10 deletions
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<string, mixed> + * @var array<non-empty-string, mixed> */ 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<string, mixed> + * @return array<non-empty-string, mixed> */ 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<string, callable> + * @return array<non-empty-string, callable> */ 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']; |