diff --git a/brick/math/src/BigDecimal.php b/brick/math/src/BigDecimal.php index 31d22ab30..0932fd642 100644 --- a/brick/math/src/BigDecimal.php +++ b/brick/math/src/BigDecimal.php @@ -8,6 +8,7 @@ use Brick\Math\Exception\MathException; use Brick\Math\Exception\NegativeNumberException; use Brick\Math\Internal\Calculator; +use Override; /** * Immutable, arbitrary-precision signed decimal numbers. @@ -47,6 +48,7 @@ protected function __construct(string $value, int $scale = 0) /** * @psalm-pure */ + #[Override] protected static function from(BigNumber $number): static { return $number->toBigDecimal(); @@ -58,19 +60,23 @@ protected static function from(BigNumber $number): static * Example: `(12345, 3)` will result in the BigDecimal `12.345`. * * @param BigNumber|int|float|string $value The unscaled value. Must be convertible to a BigInteger. - * @param int $scale The scale of the number, positive or zero. - * - * @throws \InvalidArgumentException If the scale is negative. + * @param int $scale The scale of the number. If negative, the scale will be set to zero + * and the unscaled value will be adjusted accordingly. * * @psalm-pure */ public static function ofUnscaledValue(BigNumber|int|float|string $value, int $scale = 0) : BigDecimal { + $value = (string) BigInteger::of($value); + if ($scale < 0) { - throw new \InvalidArgumentException('The scale cannot be negative.'); + if ($value !== '0') { + $value .= \str_repeat('0', -$scale); + } + $scale = 0; } - return new BigDecimal((string) BigInteger::of($value), $scale); + return new BigDecimal($value, $scale); } /** @@ -535,6 +541,7 @@ public function negated() : BigDecimal return new BigDecimal(Calculator::get()->neg($this->value), $this->scale); } + #[Override] public function compareTo(BigNumber|int|float|string $that) : int { $that = BigNumber::of($that); @@ -552,6 +559,7 @@ public function compareTo(BigNumber|int|float|string $that) : int return - $that->compareTo($this); } + #[Override] public function getSign() : int { return ($this->value === '0') ? 0 : (($this->value[0] === '-') ? -1 : 1); @@ -567,6 +575,33 @@ public function getScale() : int return $this->scale; } + /** + * Returns the number of significant digits in the number. + * + * This is the number of digits to both sides of the decimal point, stripped of leading zeros. + * The sign has no impact on the result. + * + * Examples: + * 0 => 0 + * 0.0 => 0 + * 123 => 3 + * 123.456 => 6 + * 0.00123 => 3 + * 0.0012300 => 5 + */ + public function getPrecision(): int + { + $value = $this->value; + + if ($value === '0') { + return 0; + } + + $length = \strlen($value); + + return ($value[0] === '-') ? $length - 1 : $length; + } + /** * Returns a string representing the integral part of this decimal number. * @@ -609,6 +644,7 @@ public function hasNonZeroFractionalPart() : bool return $this->getFractionalPart() !== \str_repeat('0', $this->scale); } + #[Override] public function toBigInteger() : BigInteger { $zeroScaleDecimal = $this->scale === 0 ? $this : $this->dividedBy(1, 0); @@ -616,11 +652,13 @@ public function toBigInteger() : BigInteger return self::newBigInteger($zeroScaleDecimal->value); } + #[Override] public function toBigDecimal() : BigDecimal { return $this; } + #[Override] public function toBigRational() : BigRational { $numerator = self::newBigInteger($this->value); @@ -629,6 +667,7 @@ public function toBigRational() : BigRational return self::newBigRational($numerator, $denominator, false); } + #[Override] public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal { if ($scale === $this->scale) { @@ -638,24 +677,32 @@ public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::U return $this->dividedBy(BigDecimal::one(), $scale, $roundingMode); } + #[Override] public function toInt() : int { return $this->toBigInteger()->toInt(); } + #[Override] public function toFloat() : float { return (float) (string) $this; } + /** + * @return numeric-string + */ + #[Override] public function __toString() : string { if ($this->scale === 0) { + /** @var numeric-string */ return $this->value; } $value = $this->getUnscaledValueWithLeadingZeros(); + /** @var numeric-string */ return \substr($value, 0, -$this->scale) . '.' . \substr($value, -$this->scale); } diff --git a/brick/math/src/BigInteger.php b/brick/math/src/BigInteger.php index 73dcc89a2..6ede65e3a 100644 --- a/brick/math/src/BigInteger.php +++ b/brick/math/src/BigInteger.php @@ -10,6 +10,7 @@ use Brick\Math\Exception\NegativeNumberException; use Brick\Math\Exception\NumberFormatException; use Brick\Math\Internal\Calculator; +use Override; /** * An arbitrary-size integer. @@ -42,6 +43,7 @@ protected function __construct(string $value) /** * @psalm-pure */ + #[Override] protected static function from(BigNumber $number): static { return $number->toBigInteger(); @@ -856,6 +858,7 @@ public function testBit(int $n) : bool return $this->shiftedRight($n)->isOdd(); } + #[Override] public function compareTo(BigNumber|int|float|string $that) : int { $that = BigNumber::of($that); @@ -867,31 +870,37 @@ public function compareTo(BigNumber|int|float|string $that) : int return - $that->compareTo($this); } + #[Override] public function getSign() : int { return ($this->value === '0') ? 0 : (($this->value[0] === '-') ? -1 : 1); } + #[Override] public function toBigInteger() : BigInteger { return $this; } + #[Override] public function toBigDecimal() : BigDecimal { return self::newBigDecimal($this->value); } + #[Override] public function toBigRational() : BigRational { return self::newBigRational($this, BigInteger::one(), false); } + #[Override] public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal { return $this->toBigDecimal()->toScale($scale, $roundingMode); } + #[Override] public function toInt() : int { $intValue = (int) $this->value; @@ -903,6 +912,7 @@ public function toInt() : int return $intValue; } + #[Override] public function toFloat() : float { return (float) $this->value; @@ -1013,8 +1023,13 @@ public function toBytes(bool $signed = true) : string return \hex2bin($hex); } + /** + * @return numeric-string + */ + #[Override] public function __toString() : string { + /** @var numeric-string */ return $this->value; } diff --git a/brick/math/src/BigNumber.php b/brick/math/src/BigNumber.php index 5a0df7837..5dabd314b 100644 --- a/brick/math/src/BigNumber.php +++ b/brick/math/src/BigNumber.php @@ -8,6 +8,7 @@ use Brick\Math\Exception\MathException; use Brick\Math\Exception\NumberFormatException; use Brick\Math\Exception\RoundingNecessaryException; +use Override; /** * Common interface for arbitrary-precision rational numbers. @@ -51,8 +52,9 @@ abstract class BigNumber implements \JsonSerializable * - strings containing a `.` character or using an exponential notation are returned as BigDecimal * - strings containing only digits with an optional leading `+` or `-` sign are returned as BigInteger * - * @throws NumberFormatException If the format of the number is not valid. + * @throws NumberFormatException If the format of the number is not valid. * @throws DivisionByZeroException If the value represents a rational number with a denominator of zero. + * @throws RoundingNecessaryException If the value cannot be converted to an instance of the subclass without rounding. * * @psalm-pure */ @@ -71,6 +73,9 @@ final public static function of(BigNumber|int|float|string $value) : static } /** + * @throws NumberFormatException If the format of the number is not valid. + * @throws DivisionByZeroException If the value represents a rational number with a denominator of zero. + * * @psalm-pure */ private static function _of(BigNumber|int|float|string $value) : BigNumber @@ -163,7 +168,7 @@ private static function _of(BigNumber|int|float|string $value) : BigNumber /** * Overridden by subclasses to convert a BigNumber to an instance of the subclass. * - * @throws MathException If the value cannot be converted. + * @throws RoundingNecessaryException If the value cannot be converted. * * @psalm-pure */ @@ -502,6 +507,7 @@ abstract public function toFloat() : float; */ abstract public function __toString() : string; + #[Override] final public function jsonSerialize() : string { return $this->__toString(); diff --git a/brick/math/src/BigRational.php b/brick/math/src/BigRational.php index fc3060ede..fc36e5573 100644 --- a/brick/math/src/BigRational.php +++ b/brick/math/src/BigRational.php @@ -8,6 +8,7 @@ use Brick\Math\Exception\MathException; use Brick\Math\Exception\NumberFormatException; use Brick\Math\Exception\RoundingNecessaryException; +use Override; /** * An arbitrarily large rational number. @@ -57,6 +58,7 @@ protected function __construct(BigInteger $numerator, BigInteger $denominator, b /** * @psalm-pure */ + #[Override] protected static function from(BigNumber $number): static { return $number->toBigRational(); @@ -320,16 +322,19 @@ public function simplified() : BigRational return new BigRational($numerator, $denominator, false); } + #[Override] public function compareTo(BigNumber|int|float|string $that) : int { return $this->minus($that)->getSign(); } + #[Override] public function getSign() : int { return $this->numerator->getSign(); } + #[Override] public function toBigInteger() : BigInteger { $simplified = $this->simplified(); @@ -341,32 +346,38 @@ public function toBigInteger() : BigInteger return $simplified->numerator; } + #[Override] public function toBigDecimal() : BigDecimal { return $this->numerator->toBigDecimal()->exactlyDividedBy($this->denominator); } + #[Override] public function toBigRational() : BigRational { return $this; } + #[Override] public function toScale(int $scale, RoundingMode $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal { return $this->numerator->toBigDecimal()->dividedBy($this->denominator, $scale, $roundingMode); } + #[Override] public function toInt() : int { return $this->toBigInteger()->toInt(); } + #[Override] public function toFloat() : float { $simplified = $this->simplified(); return $simplified->numerator->toFloat() / $simplified->denominator->toFloat(); } + #[Override] public function __toString() : string { $numerator = (string) $this->numerator; @@ -376,7 +387,7 @@ public function __toString() : string return $numerator; } - return $this->numerator . '/' . $this->denominator; + return $numerator . '/' . $denominator; } /** diff --git a/brick/math/src/Exception/MathException.php b/brick/math/src/Exception/MathException.php index 46e9c3fe4..8facd9c62 100644 --- a/brick/math/src/Exception/MathException.php +++ b/brick/math/src/Exception/MathException.php @@ -7,6 +7,6 @@ /** * Base class for all math exceptions. */ -class MathException extends \Exception +class MathException extends \RuntimeException { } diff --git a/brick/math/src/Internal/Calculator/BcMathCalculator.php b/brick/math/src/Internal/Calculator/BcMathCalculator.php index 067085e21..93a27ff81 100644 --- a/brick/math/src/Internal/Calculator/BcMathCalculator.php +++ b/brick/math/src/Internal/Calculator/BcMathCalculator.php @@ -5,6 +5,7 @@ namespace Brick\Math\Internal\Calculator; use Brick\Math\Internal\Calculator; +use Override; /** * Calculator implementation built around the bcmath library. @@ -15,31 +16,37 @@ */ class BcMathCalculator extends Calculator { + #[Override] public function add(string $a, string $b) : string { return \bcadd($a, $b, 0); } + #[Override] public function sub(string $a, string $b) : string { return \bcsub($a, $b, 0); } + #[Override] public function mul(string $a, string $b) : string { return \bcmul($a, $b, 0); } + #[Override] public function divQ(string $a, string $b) : string { return \bcdiv($a, $b, 0); } + #[Override] public function divR(string $a, string $b) : string { return \bcmod($a, $b, 0); } + #[Override] public function divQR(string $a, string $b) : array { $q = \bcdiv($a, $b, 0); @@ -48,16 +55,19 @@ public function divQR(string $a, string $b) : array return [$q, $r]; } + #[Override] public function pow(string $a, int $e) : string { return \bcpow($a, (string) $e, 0); } + #[Override] public function modPow(string $base, string $exp, string $mod) : string { return \bcpowmod($base, $exp, $mod, 0); } + #[Override] public function sqrt(string $n) : string { return \bcsqrt($n, 0); diff --git a/brick/math/src/Internal/Calculator/GmpCalculator.php b/brick/math/src/Internal/Calculator/GmpCalculator.php index 42d4c6927..0e44deeb3 100644 --- a/brick/math/src/Internal/Calculator/GmpCalculator.php +++ b/brick/math/src/Internal/Calculator/GmpCalculator.php @@ -5,6 +5,7 @@ namespace Brick\Math\Internal\Calculator; use Brick\Math\Internal\Calculator; +use Override; /** * Calculator implementation built around the GMP library. @@ -15,31 +16,37 @@ */ class GmpCalculator extends Calculator { + #[Override] public function add(string $a, string $b) : string { return \gmp_strval(\gmp_add($a, $b)); } + #[Override] public function sub(string $a, string $b) : string { return \gmp_strval(\gmp_sub($a, $b)); } + #[Override] public function mul(string $a, string $b) : string { return \gmp_strval(\gmp_mul($a, $b)); } + #[Override] public function divQ(string $a, string $b) : string { return \gmp_strval(\gmp_div_q($a, $b)); } + #[Override] public function divR(string $a, string $b) : string { return \gmp_strval(\gmp_div_r($a, $b)); } + #[Override] public function divQR(string $a, string $b) : array { [$q, $r] = \gmp_div_qr($a, $b); @@ -50,11 +57,13 @@ public function divQR(string $a, string $b) : array ]; } + #[Override] public function pow(string $a, int $e) : string { return \gmp_strval(\gmp_pow($a, $e)); } + #[Override] public function modInverse(string $x, string $m) : ?string { $result = \gmp_invert($x, $m); @@ -66,41 +75,49 @@ public function modInverse(string $x, string $m) : ?string return \gmp_strval($result); } + #[Override] public function modPow(string $base, string $exp, string $mod) : string { return \gmp_strval(\gmp_powm($base, $exp, $mod)); } + #[Override] public function gcd(string $a, string $b) : string { return \gmp_strval(\gmp_gcd($a, $b)); } + #[Override] public function fromBase(string $number, int $base) : string { return \gmp_strval(\gmp_init($number, $base)); } + #[Override] public function toBase(string $number, int $base) : string { return \gmp_strval($number, $base); } + #[Override] public function and(string $a, string $b) : string { return \gmp_strval(\gmp_and($a, $b)); } + #[Override] public function or(string $a, string $b) : string { return \gmp_strval(\gmp_or($a, $b)); } + #[Override] public function xor(string $a, string $b) : string { return \gmp_strval(\gmp_xor($a, $b)); } + #[Override] public function sqrt(string $n) : string { return \gmp_strval(\gmp_sqrt($n)); diff --git a/brick/math/src/Internal/Calculator/NativeCalculator.php b/brick/math/src/Internal/Calculator/NativeCalculator.php index 6acd06382..f71c55bed 100644 --- a/brick/math/src/Internal/Calculator/NativeCalculator.php +++ b/brick/math/src/Internal/Calculator/NativeCalculator.php @@ -5,6 +5,7 @@ namespace Brick\Math\Internal\Calculator; use Brick\Math\Internal\Calculator; +use Override; /** * Calculator implementation using only native PHP code. @@ -37,6 +38,7 @@ public function __construct() }; } + #[Override] public function add(string $a, string $b) : string { /** @@ -68,11 +70,13 @@ public function add(string $a, string $b) : string return $result; } + #[Override] public function sub(string $a, string $b) : string { return $this->add($a, $this->neg($b)); } + #[Override] public function mul(string $a, string $b) : string { /** @@ -116,16 +120,19 @@ public function mul(string $a, string $b) : string return $result; } + #[Override] public function divQ(string $a, string $b) : string { return $this->divQR($a, $b)[0]; } + #[Override] public function divR(string $a, string $b): string { return $this->divQR($a, $b)[1]; } + #[Override] public function divQR(string $a, string $b) : array { if ($a === '0') { @@ -179,6 +186,7 @@ public function divQR(string $a, string $b) : array return [$q, $r]; } + #[Override] public function pow(string $a, int $e) : string { if ($e === 0) { @@ -207,6 +215,7 @@ public function pow(string $a, int $e) : string /** * Algorithm from: https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/ */ + #[Override] public function modPow(string $base, string $exp, string $mod) : string { // special case: the algorithm below fails with 0 power 0 mod 1 (returns 1 instead of 0) @@ -241,6 +250,7 @@ public function modPow(string $base, string $exp, string $mod) : string /** * Adapted from https://cp-algorithms.com/num_methods/roots_newton.html */ + #[Override] public function sqrt(string $n) : string { if ($n === '0') { @@ -488,6 +498,22 @@ private function doDiv(string $a, string $b) : array $r = $a; // remainder $z = $y; // focus length, always $y or $y+1 + /** @psalm-var numeric-string $b */ + $nb = $b * 1; // cast to number + // performance optimization in cases where the remainder will never cause int overflow + if (is_int(($nb - 1) * 10 + 9)) { + $r = (int) \substr($a, 0, $z - 1); + + for ($i = $z - 1; $i < $x; $i++) { + $n = $r * 10 + (int) $a[$i]; + /** @psalm-var int $nb */ + $q .= \intdiv($n, $nb); + $r = $n % $nb; + } + + return [\ltrim($q, '0') ?: '0', (string) $r]; + } + for (;;) { $focus = \substr($a, 0, $z); diff --git a/composer.json b/composer.json index 3cfd092bb..6b06efa2b 100644 --- a/composer.json +++ b/composer.json @@ -64,7 +64,7 @@ "symfony/routing": "^6.4.30", "symfony/translation": "^6.4.30", "wapmorgan/mp3info": "^0.1.1", - "web-auth/webauthn-lib": "^4.9.1" + "web-auth/webauthn-lib": "^4.9.2" }, "replace": { "symfony/polyfill-php80": "*", diff --git a/composer.lock b/composer.lock index 921e5ba6d..58be860ab 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7951620de61026d772a5d30175d2c5c4", + "content-hash": "8af699e31390019c407c50ade7c2ebdd", "packages": [ { "name": "aws/aws-crt-php", @@ -193,16 +193,16 @@ }, { "name": "brick/math", - "version": "0.12.1", + "version": "0.13.1", "source": { "type": "git", "url": "https://github.com/brick/math.git", - "reference": "f510c0a40911935b77b86859eb5223d58d660df1" + "reference": "fc7ed316430118cc7836bf45faff18d5dfc8de04" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/brick/math/zipball/f510c0a40911935b77b86859eb5223d58d660df1", - "reference": "f510c0a40911935b77b86859eb5223d58d660df1", + "url": "https://api.github.com/repos/brick/math/zipball/fc7ed316430118cc7836bf45faff18d5dfc8de04", + "reference": "fc7ed316430118cc7836bf45faff18d5dfc8de04", "shasum": "" }, "require": { @@ -211,7 +211,7 @@ "require-dev": { "php-coveralls/php-coveralls": "^2.2", "phpunit/phpunit": "^10.1", - "vimeo/psalm": "5.16.0" + "vimeo/psalm": "6.8.8" }, "type": "library", "autoload": { @@ -241,7 +241,7 @@ ], "support": { "issues": "https://github.com/brick/math/issues", - "source": "https://github.com/brick/math/tree/0.12.1" + "source": "https://github.com/brick/math/tree/0.13.1" }, "funding": [ { @@ -249,7 +249,7 @@ "type": "github" } ], - "time": "2023-11-29T23:19:16+00:00" + "time": "2025-03-29T13:50:30+00:00" }, { "name": "cweagans/composer-patches", @@ -2247,24 +2247,26 @@ }, { "name": "paragonie/constant_time_encoding", - "version": "v2.6.3", + "version": "v3.1.3", "source": { "type": "git", "url": "https://github.com/paragonie/constant_time_encoding.git", - "reference": "58c3f47f650c94ec05a151692652a868995d2938" + "reference": "d5b01a39b3415c2cd581d3bd3a3575c1ebbd8e77" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/58c3f47f650c94ec05a151692652a868995d2938", - "reference": "58c3f47f650c94ec05a151692652a868995d2938", + "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/d5b01a39b3415c2cd581d3bd3a3575c1ebbd8e77", + "reference": "d5b01a39b3415c2cd581d3bd3a3575c1ebbd8e77", "shasum": "" }, "require": { - "php": "^7|^8" + "php": "^8" }, "require-dev": { - "phpunit/phpunit": "^6|^7|^8|^9", - "vimeo/psalm": "^1|^2|^3|^4" + "infection/infection": "^0", + "nikic/php-fuzzer": "^0", + "phpunit/phpunit": "^9|^10|^11", + "vimeo/psalm": "^4|^5|^6" }, "type": "library", "autoload": { @@ -2310,7 +2312,7 @@ "issues": "https://github.com/paragonie/constant_time_encoding/issues", "source": "https://github.com/paragonie/constant_time_encoding" }, - "time": "2022-06-14T06:56:20+00:00" + "time": "2025-09-24T15:06:41+00:00" }, { "name": "pear/archive_tar", @@ -3937,40 +3939,28 @@ }, { "name": "spomky-labs/cbor-php", - "version": "3.0.4", + "version": "3.2.2", "source": { "type": "git", "url": "https://github.com/Spomky-Labs/cbor-php.git", - "reference": "658ed12a85a6b31fa312b89cd92f3a4ce6df4c6b" + "reference": "2a5fb86aacfe1004611370ead6caa2bfc88435d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Spomky-Labs/cbor-php/zipball/658ed12a85a6b31fa312b89cd92f3a4ce6df4c6b", - "reference": "658ed12a85a6b31fa312b89cd92f3a4ce6df4c6b", + "url": "https://api.github.com/repos/Spomky-Labs/cbor-php/zipball/2a5fb86aacfe1004611370ead6caa2bfc88435d0", + "reference": "2a5fb86aacfe1004611370ead6caa2bfc88435d0", "shasum": "" }, "require": { - "brick/math": "^0.9|^0.10|^0.11|^0.12", + "brick/math": "^0.9|^0.10|^0.11|^0.12|^0.13|^0.14", "ext-mbstring": "*", "php": ">=8.0" }, "require-dev": { - "ekino/phpstan-banned-code": "^1.0", "ext-json": "*", - "infection/infection": "^0.27", - "php-parallel-lint/php-parallel-lint": "^1.3", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "^1.0", - "phpstan/phpstan-beberlei-assert": "^1.0", - "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", - "phpstan/phpstan-strict-rules": "^1.0", - "phpunit/phpunit": "^10.1", - "qossmic/deptrac-shim": "^1.0", - "rector/rector": "^0.19", "roave/security-advisories": "dev-latest", - "symfony/var-dumper": "^6.0|^7.0", - "symplify/easy-coding-standard": "^12.0" + "symfony/error-handler": "^6.4|^7.1|^8.0", + "symfony/var-dumper": "^6.4|^7.1|^8.0" }, "suggest": { "ext-bcmath": "GMP or BCMath extensions will drastically improve the library performance. BCMath extension needed to handle the Big Float and Decimal Fraction Tags", @@ -4004,7 +3994,7 @@ ], "support": { "issues": "https://github.com/Spomky-Labs/cbor-php/issues", - "source": "https://github.com/Spomky-Labs/cbor-php/tree/3.0.4" + "source": "https://github.com/Spomky-Labs/cbor-php/tree/3.2.2" }, "funding": [ { @@ -4016,45 +4006,43 @@ "type": "patreon" } ], - "time": "2024-01-29T20:33:48+00:00" + "time": "2025-11-13T13:00:34+00:00" }, { "name": "spomky-labs/pki-framework", - "version": "1.2.1", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/Spomky-Labs/pki-framework.git", - "reference": "0b10c8b53366729417d6226ae89a665f9e2d61b6" + "reference": "bf6f55a9d9eb25b7781640221cb54f5c727850d7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Spomky-Labs/pki-framework/zipball/0b10c8b53366729417d6226ae89a665f9e2d61b6", - "reference": "0b10c8b53366729417d6226ae89a665f9e2d61b6", + "url": "https://api.github.com/repos/Spomky-Labs/pki-framework/zipball/bf6f55a9d9eb25b7781640221cb54f5c727850d7", + "reference": "bf6f55a9d9eb25b7781640221cb54f5c727850d7", "shasum": "" }, "require": { - "brick/math": "^0.10|^0.11|^0.12", + "brick/math": "^0.10|^0.11|^0.12|^0.13|^0.14", "ext-mbstring": "*", "php": ">=8.1" }, "require-dev": { - "ekino/phpstan-banned-code": "^1.0", + "ekino/phpstan-banned-code": "^1.0|^2.0|^3.0", "ext-gmp": "*", "ext-openssl": "*", - "infection/infection": "^0.28", + "infection/infection": "^0.28|^0.29|^0.31", "php-parallel-lint/php-parallel-lint": "^1.3", - "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^1.8", - "phpstan/phpstan-beberlei-assert": "^1.0", - "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.1", - "phpstan/phpstan-strict-rules": "^1.3", - "phpunit/phpunit": "^10.1|^11.0", - "rector/rector": "^1.0", + "phpstan/extension-installer": "^1.3|^2.0", + "phpstan/phpstan": "^1.8|^2.0", + "phpstan/phpstan-deprecation-rules": "^1.0|^2.0", + "phpstan/phpstan-phpunit": "^1.1|^2.0", + "phpstan/phpstan-strict-rules": "^1.3|^2.0", + "phpunit/phpunit": "^10.1|^11.0|^12.0", + "rector/rector": "^1.0|^2.0", "roave/security-advisories": "dev-latest", - "symfony/phpunit-bridge": "^6.4|^7.0", - "symfony/string": "^6.4|^7.0", - "symfony/var-dumper": "^6.4|^7.0", + "symfony/string": "^6.4|^7.0|^8.0", + "symfony/var-dumper": "^6.4|^7.0|^8.0", "symplify/easy-coding-standard": "^12.0" }, "suggest": { @@ -4115,7 +4103,7 @@ ], "support": { "issues": "https://github.com/Spomky-Labs/pki-framework/issues", - "source": "https://github.com/Spomky-Labs/pki-framework/tree/1.2.1" + "source": "https://github.com/Spomky-Labs/pki-framework/tree/1.4.0" }, "funding": [ { @@ -4127,7 +4115,7 @@ "type": "patreon" } ], - "time": "2024-03-30T18:03:49+00:00" + "time": "2025-10-22T08:24:34+00:00" }, { "name": "stecman/symfony-console-completion", @@ -5378,20 +5366,20 @@ }, { "name": "symfony/polyfill-uuid", - "version": "v1.29.0", + "version": "v1.33.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-uuid.git", - "reference": "3abdd21b0ceaa3000ee950097bc3cf9efc137853" + "reference": "21533be36c24be3f4b1669c4725c7d1d2bab4ae2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-uuid/zipball/3abdd21b0ceaa3000ee950097bc3cf9efc137853", - "reference": "3abdd21b0ceaa3000ee950097bc3cf9efc137853", + "url": "https://api.github.com/repos/symfony/polyfill-uuid/zipball/21533be36c24be3f4b1669c4725c7d1d2bab4ae2", + "reference": "21533be36c24be3f4b1669c4725c7d1d2bab4ae2", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "provide": { "ext-uuid": "*" @@ -5402,8 +5390,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -5437,7 +5425,7 @@ "uuid" ], "support": { - "source": "https://github.com/symfony/polyfill-uuid/tree/v1.29.0" + "source": "https://github.com/symfony/polyfill-uuid/tree/v1.33.0" }, "funding": [ { @@ -5448,12 +5436,16 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-01-29T20:11:03+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "symfony/process", @@ -5966,16 +5958,16 @@ }, { "name": "symfony/uid", - "version": "v6.4.3", + "version": "v6.4.24", "source": { "type": "git", "url": "https://github.com/symfony/uid.git", - "reference": "1d31267211cc3a2fff32bcfc7c1818dac41b6fc0" + "reference": "17da16a750541a42cf2183935e0f6008316c23f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/uid/zipball/1d31267211cc3a2fff32bcfc7c1818dac41b6fc0", - "reference": "1d31267211cc3a2fff32bcfc7c1818dac41b6fc0", + "url": "https://api.github.com/repos/symfony/uid/zipball/17da16a750541a42cf2183935e0f6008316c23f7", + "reference": "17da16a750541a42cf2183935e0f6008316c23f7", "shasum": "" }, "require": { @@ -6020,7 +6012,7 @@ "uuid" ], "support": { - "source": "https://github.com/symfony/uid/tree/v6.4.3" + "source": "https://github.com/symfony/uid/tree/v6.4.24" }, "funding": [ { @@ -6031,12 +6023,16 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-01-23T14:51:35+00:00" + "time": "2025-07-10T08:14:14+00:00" }, { "name": "wapmorgan/mp3info", @@ -6086,38 +6082,37 @@ }, { "name": "web-auth/cose-lib", - "version": "4.3.0", + "version": "4.4.2", "source": { "type": "git", "url": "https://github.com/web-auth/cose-lib.git", - "reference": "e5c417b3b90e06c84638a18d350e438d760cb955" + "reference": "a93b61c48fb587855f64a9ec11ad7b60e867cb15" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/web-auth/cose-lib/zipball/e5c417b3b90e06c84638a18d350e438d760cb955", - "reference": "e5c417b3b90e06c84638a18d350e438d760cb955", + "url": "https://api.github.com/repos/web-auth/cose-lib/zipball/a93b61c48fb587855f64a9ec11ad7b60e867cb15", + "reference": "a93b61c48fb587855f64a9ec11ad7b60e867cb15", "shasum": "" }, "require": { - "brick/math": "^0.9|^0.10|^0.11|^0.12", + "brick/math": "^0.9|^0.10|^0.11|^0.12|^0.13", "ext-json": "*", - "ext-mbstring": "*", "ext-openssl": "*", "php": ">=8.1", "spomky-labs/pki-framework": "^1.0" }, "require-dev": { - "ekino/phpstan-banned-code": "^1.0", - "infection/infection": "^0.27", + "deptrac/deptrac": "^3.0", + "ekino/phpstan-banned-code": "^1.0|^2.0|^3.0", + "infection/infection": "^0.29", "php-parallel-lint/php-parallel-lint": "^1.3", "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^1.7", - "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.1", - "phpstan/phpstan-strict-rules": "^1.2", - "phpunit/phpunit": "^10.1", - "qossmic/deptrac-shim": "^1.0", - "rector/rector": "^0.19", + "phpstan/phpstan": "^1.7|^2.0", + "phpstan/phpstan-deprecation-rules": "^1.0|^2.0", + "phpstan/phpstan-phpunit": "^1.1|^2.0", + "phpstan/phpstan-strict-rules": "^1.0|^2.0", + "phpunit/phpunit": "^10.1|^11.0|^12.0", + "rector/rector": "^2.0", "symfony/phpunit-bridge": "^6.4|^7.0", "symplify/easy-coding-standard": "^12.0" }, @@ -6153,7 +6148,7 @@ ], "support": { "issues": "https://github.com/web-auth/cose-lib/issues", - "source": "https://github.com/web-auth/cose-lib/tree/4.3.0" + "source": "https://github.com/web-auth/cose-lib/tree/4.4.2" }, "funding": [ { @@ -6165,20 +6160,20 @@ "type": "patreon" } ], - "time": "2024-02-05T21:00:39+00:00" + "time": "2025-08-14T20:33:29+00:00" }, { "name": "web-auth/webauthn-lib", - "version": "4.9.1", + "version": "4.9.2", "source": { "type": "git", "url": "https://github.com/web-auth/webauthn-lib.git", - "reference": "fd7a0943c663b325e92ad562c2bcc943e77beeac" + "reference": "008b25171c27cf4813420d0de31cc059bcc71f1a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/web-auth/webauthn-lib/zipball/fd7a0943c663b325e92ad562c2bcc943e77beeac", - "reference": "fd7a0943c663b325e92ad562c2bcc943e77beeac", + "url": "https://api.github.com/repos/web-auth/webauthn-lib/zipball/008b25171c27cf4813420d0de31cc059bcc71f1a", + "reference": "008b25171c27cf4813420d0de31cc059bcc71f1a", "shasum": "" }, "require": { @@ -6212,8 +6207,8 @@ "type": "library", "extra": { "thanks": { - "name": "web-auth/webauthn-framework", - "url": "https://github.com/web-auth/webauthn-framework" + "url": "https://github.com/web-auth/webauthn-framework", + "name": "web-auth/webauthn-framework" } }, "autoload": { @@ -6243,7 +6238,7 @@ "webauthn" ], "support": { - "source": "https://github.com/web-auth/webauthn-lib/tree/4.9.1" + "source": "https://github.com/web-auth/webauthn-lib/tree/4.9.2" }, "funding": [ { @@ -6255,7 +6250,7 @@ "type": "patreon" } ], - "time": "2024-07-16T18:36:36+00:00" + "time": "2025-01-04T09:47:58+00:00" } ], "packages-dev": [], diff --git a/composer/autoload_classmap.php b/composer/autoload_classmap.php index da100095d..e47585b5d 100644 --- a/composer/autoload_classmap.php +++ b/composer/autoload_classmap.php @@ -348,6 +348,8 @@ 'CBOR\\CBORObject' => $vendorDir . '/spomky-labs/cbor-php/src/CBORObject.php', 'CBOR\\Decoder' => $vendorDir . '/spomky-labs/cbor-php/src/Decoder.php', 'CBOR\\DecoderInterface' => $vendorDir . '/spomky-labs/cbor-php/src/DecoderInterface.php', + 'CBOR\\Encoder' => $vendorDir . '/spomky-labs/cbor-php/src/Encoder.php', + 'CBOR\\EncoderInterface' => $vendorDir . '/spomky-labs/cbor-php/src/EncoderInterface.php', 'CBOR\\IndefiniteLengthByteStringObject' => $vendorDir . '/spomky-labs/cbor-php/src/IndefiniteLengthByteStringObject.php', 'CBOR\\IndefiniteLengthListObject' => $vendorDir . '/spomky-labs/cbor-php/src/IndefiniteLengthListObject.php', 'CBOR\\IndefiniteLengthMapObject' => $vendorDir . '/spomky-labs/cbor-php/src/IndefiniteLengthMapObject.php', diff --git a/composer/autoload_static.php b/composer/autoload_static.php index 0fa3ab02e..afa455bd9 100644 --- a/composer/autoload_static.php +++ b/composer/autoload_static.php @@ -875,6 +875,8 @@ class ComposerStaticInit2f23f73bc0cc116b4b1eee1521aa8652 'CBOR\\CBORObject' => __DIR__ . '/..' . '/spomky-labs/cbor-php/src/CBORObject.php', 'CBOR\\Decoder' => __DIR__ . '/..' . '/spomky-labs/cbor-php/src/Decoder.php', 'CBOR\\DecoderInterface' => __DIR__ . '/..' . '/spomky-labs/cbor-php/src/DecoderInterface.php', + 'CBOR\\Encoder' => __DIR__ . '/..' . '/spomky-labs/cbor-php/src/Encoder.php', + 'CBOR\\EncoderInterface' => __DIR__ . '/..' . '/spomky-labs/cbor-php/src/EncoderInterface.php', 'CBOR\\IndefiniteLengthByteStringObject' => __DIR__ . '/..' . '/spomky-labs/cbor-php/src/IndefiniteLengthByteStringObject.php', 'CBOR\\IndefiniteLengthListObject' => __DIR__ . '/..' . '/spomky-labs/cbor-php/src/IndefiniteLengthListObject.php', 'CBOR\\IndefiniteLengthMapObject' => __DIR__ . '/..' . '/spomky-labs/cbor-php/src/IndefiniteLengthMapObject.php', diff --git a/composer/installed.json b/composer/installed.json index f641bc150..3563e8dd4 100644 --- a/composer/installed.json +++ b/composer/installed.json @@ -196,17 +196,17 @@ }, { "name": "brick/math", - "version": "0.12.1", - "version_normalized": "0.12.1.0", + "version": "0.13.1", + "version_normalized": "0.13.1.0", "source": { "type": "git", "url": "https://github.com/brick/math.git", - "reference": "f510c0a40911935b77b86859eb5223d58d660df1" + "reference": "fc7ed316430118cc7836bf45faff18d5dfc8de04" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/brick/math/zipball/f510c0a40911935b77b86859eb5223d58d660df1", - "reference": "f510c0a40911935b77b86859eb5223d58d660df1", + "url": "https://api.github.com/repos/brick/math/zipball/fc7ed316430118cc7836bf45faff18d5dfc8de04", + "reference": "fc7ed316430118cc7836bf45faff18d5dfc8de04", "shasum": "" }, "require": { @@ -215,9 +215,9 @@ "require-dev": { "php-coveralls/php-coveralls": "^2.2", "phpunit/phpunit": "^10.1", - "vimeo/psalm": "5.16.0" + "vimeo/psalm": "6.8.8" }, - "time": "2023-11-29T23:19:16+00:00", + "time": "2025-03-29T13:50:30+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -247,7 +247,7 @@ ], "support": { "issues": "https://github.com/brick/math/issues", - "source": "https://github.com/brick/math/tree/0.12.1" + "source": "https://github.com/brick/math/tree/0.13.1" }, "funding": [ { @@ -2340,27 +2340,29 @@ }, { "name": "paragonie/constant_time_encoding", - "version": "v2.6.3", - "version_normalized": "2.6.3.0", + "version": "v3.1.3", + "version_normalized": "3.1.3.0", "source": { "type": "git", "url": "https://github.com/paragonie/constant_time_encoding.git", - "reference": "58c3f47f650c94ec05a151692652a868995d2938" + "reference": "d5b01a39b3415c2cd581d3bd3a3575c1ebbd8e77" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/58c3f47f650c94ec05a151692652a868995d2938", - "reference": "58c3f47f650c94ec05a151692652a868995d2938", + "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/d5b01a39b3415c2cd581d3bd3a3575c1ebbd8e77", + "reference": "d5b01a39b3415c2cd581d3bd3a3575c1ebbd8e77", "shasum": "" }, "require": { - "php": "^7|^8" + "php": "^8" }, "require-dev": { - "phpunit/phpunit": "^6|^7|^8|^9", - "vimeo/psalm": "^1|^2|^3|^4" + "infection/infection": "^0", + "nikic/php-fuzzer": "^0", + "phpunit/phpunit": "^9|^10|^11", + "vimeo/psalm": "^4|^5|^6" }, - "time": "2022-06-14T06:56:20+00:00", + "time": "2025-09-24T15:06:41+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -4111,47 +4113,35 @@ }, { "name": "spomky-labs/cbor-php", - "version": "3.0.4", - "version_normalized": "3.0.4.0", + "version": "3.2.2", + "version_normalized": "3.2.2.0", "source": { "type": "git", "url": "https://github.com/Spomky-Labs/cbor-php.git", - "reference": "658ed12a85a6b31fa312b89cd92f3a4ce6df4c6b" + "reference": "2a5fb86aacfe1004611370ead6caa2bfc88435d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Spomky-Labs/cbor-php/zipball/658ed12a85a6b31fa312b89cd92f3a4ce6df4c6b", - "reference": "658ed12a85a6b31fa312b89cd92f3a4ce6df4c6b", + "url": "https://api.github.com/repos/Spomky-Labs/cbor-php/zipball/2a5fb86aacfe1004611370ead6caa2bfc88435d0", + "reference": "2a5fb86aacfe1004611370ead6caa2bfc88435d0", "shasum": "" }, "require": { - "brick/math": "^0.9|^0.10|^0.11|^0.12", + "brick/math": "^0.9|^0.10|^0.11|^0.12|^0.13|^0.14", "ext-mbstring": "*", "php": ">=8.0" }, "require-dev": { - "ekino/phpstan-banned-code": "^1.0", "ext-json": "*", - "infection/infection": "^0.27", - "php-parallel-lint/php-parallel-lint": "^1.3", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "^1.0", - "phpstan/phpstan-beberlei-assert": "^1.0", - "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", - "phpstan/phpstan-strict-rules": "^1.0", - "phpunit/phpunit": "^10.1", - "qossmic/deptrac-shim": "^1.0", - "rector/rector": "^0.19", "roave/security-advisories": "dev-latest", - "symfony/var-dumper": "^6.0|^7.0", - "symplify/easy-coding-standard": "^12.0" + "symfony/error-handler": "^6.4|^7.1|^8.0", + "symfony/var-dumper": "^6.4|^7.1|^8.0" }, "suggest": { "ext-bcmath": "GMP or BCMath extensions will drastically improve the library performance. BCMath extension needed to handle the Big Float and Decimal Fraction Tags", "ext-gmp": "GMP or BCMath extensions will drastically improve the library performance" }, - "time": "2024-01-29T20:33:48+00:00", + "time": "2025-11-13T13:00:34+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -4181,7 +4171,7 @@ ], "support": { "issues": "https://github.com/Spomky-Labs/cbor-php/issues", - "source": "https://github.com/Spomky-Labs/cbor-php/tree/3.0.4" + "source": "https://github.com/Spomky-Labs/cbor-php/tree/3.2.2" }, "funding": [ { @@ -4197,42 +4187,40 @@ }, { "name": "spomky-labs/pki-framework", - "version": "1.2.1", - "version_normalized": "1.2.1.0", + "version": "1.4.0", + "version_normalized": "1.4.0.0", "source": { "type": "git", "url": "https://github.com/Spomky-Labs/pki-framework.git", - "reference": "0b10c8b53366729417d6226ae89a665f9e2d61b6" + "reference": "bf6f55a9d9eb25b7781640221cb54f5c727850d7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Spomky-Labs/pki-framework/zipball/0b10c8b53366729417d6226ae89a665f9e2d61b6", - "reference": "0b10c8b53366729417d6226ae89a665f9e2d61b6", + "url": "https://api.github.com/repos/Spomky-Labs/pki-framework/zipball/bf6f55a9d9eb25b7781640221cb54f5c727850d7", + "reference": "bf6f55a9d9eb25b7781640221cb54f5c727850d7", "shasum": "" }, "require": { - "brick/math": "^0.10|^0.11|^0.12", + "brick/math": "^0.10|^0.11|^0.12|^0.13|^0.14", "ext-mbstring": "*", "php": ">=8.1" }, "require-dev": { - "ekino/phpstan-banned-code": "^1.0", + "ekino/phpstan-banned-code": "^1.0|^2.0|^3.0", "ext-gmp": "*", "ext-openssl": "*", - "infection/infection": "^0.28", + "infection/infection": "^0.28|^0.29|^0.31", "php-parallel-lint/php-parallel-lint": "^1.3", - "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^1.8", - "phpstan/phpstan-beberlei-assert": "^1.0", - "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.1", - "phpstan/phpstan-strict-rules": "^1.3", - "phpunit/phpunit": "^10.1|^11.0", - "rector/rector": "^1.0", + "phpstan/extension-installer": "^1.3|^2.0", + "phpstan/phpstan": "^1.8|^2.0", + "phpstan/phpstan-deprecation-rules": "^1.0|^2.0", + "phpstan/phpstan-phpunit": "^1.1|^2.0", + "phpstan/phpstan-strict-rules": "^1.3|^2.0", + "phpunit/phpunit": "^10.1|^11.0|^12.0", + "rector/rector": "^1.0|^2.0", "roave/security-advisories": "dev-latest", - "symfony/phpunit-bridge": "^6.4|^7.0", - "symfony/string": "^6.4|^7.0", - "symfony/var-dumper": "^6.4|^7.0", + "symfony/string": "^6.4|^7.0|^8.0", + "symfony/var-dumper": "^6.4|^7.0|^8.0", "symplify/easy-coding-standard": "^12.0" }, "suggest": { @@ -4240,7 +4228,7 @@ "ext-gmp": "For better performance (or BCMath)", "ext-openssl": "For OpenSSL based cyphering" }, - "time": "2024-03-30T18:03:49+00:00", + "time": "2025-10-22T08:24:34+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -4295,7 +4283,7 @@ ], "support": { "issues": "https://github.com/Spomky-Labs/pki-framework/issues", - "source": "https://github.com/Spomky-Labs/pki-framework/tree/1.2.1" + "source": "https://github.com/Spomky-Labs/pki-framework/tree/1.4.0" }, "funding": [ { @@ -5606,21 +5594,21 @@ }, { "name": "symfony/polyfill-uuid", - "version": "v1.29.0", - "version_normalized": "1.29.0.0", + "version": "v1.33.0", + "version_normalized": "1.33.0.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-uuid.git", - "reference": "3abdd21b0ceaa3000ee950097bc3cf9efc137853" + "reference": "21533be36c24be3f4b1669c4725c7d1d2bab4ae2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-uuid/zipball/3abdd21b0ceaa3000ee950097bc3cf9efc137853", - "reference": "3abdd21b0ceaa3000ee950097bc3cf9efc137853", + "url": "https://api.github.com/repos/symfony/polyfill-uuid/zipball/21533be36c24be3f4b1669c4725c7d1d2bab4ae2", + "reference": "21533be36c24be3f4b1669c4725c7d1d2bab4ae2", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "provide": { "ext-uuid": "*" @@ -5628,12 +5616,12 @@ "suggest": { "ext-uuid": "For best performance" }, - "time": "2024-01-29T20:11:03+00:00", + "time": "2024-09-09T11:45:10+00:00", "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "installation-source": "dist", @@ -5668,7 +5656,7 @@ "uuid" ], "support": { - "source": "https://github.com/symfony/polyfill-uuid/tree/v1.29.0" + "source": "https://github.com/symfony/polyfill-uuid/tree/v1.33.0" }, "funding": [ { @@ -5679,6 +5667,10 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" @@ -6215,17 +6207,17 @@ }, { "name": "symfony/uid", - "version": "v6.4.3", - "version_normalized": "6.4.3.0", + "version": "v6.4.24", + "version_normalized": "6.4.24.0", "source": { "type": "git", "url": "https://github.com/symfony/uid.git", - "reference": "1d31267211cc3a2fff32bcfc7c1818dac41b6fc0" + "reference": "17da16a750541a42cf2183935e0f6008316c23f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/uid/zipball/1d31267211cc3a2fff32bcfc7c1818dac41b6fc0", - "reference": "1d31267211cc3a2fff32bcfc7c1818dac41b6fc0", + "url": "https://api.github.com/repos/symfony/uid/zipball/17da16a750541a42cf2183935e0f6008316c23f7", + "reference": "17da16a750541a42cf2183935e0f6008316c23f7", "shasum": "" }, "require": { @@ -6235,7 +6227,7 @@ "require-dev": { "symfony/console": "^5.4|^6.0|^7.0" }, - "time": "2024-01-23T14:51:35+00:00", + "time": "2025-07-10T08:14:14+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -6272,7 +6264,7 @@ "uuid" ], "support": { - "source": "https://github.com/symfony/uid/tree/v6.4.3" + "source": "https://github.com/symfony/uid/tree/v6.4.24" }, "funding": [ { @@ -6283,6 +6275,10 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" @@ -6347,39 +6343,38 @@ }, { "name": "web-auth/cose-lib", - "version": "4.3.0", - "version_normalized": "4.3.0.0", + "version": "4.4.2", + "version_normalized": "4.4.2.0", "source": { "type": "git", "url": "https://github.com/web-auth/cose-lib.git", - "reference": "e5c417b3b90e06c84638a18d350e438d760cb955" + "reference": "a93b61c48fb587855f64a9ec11ad7b60e867cb15" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/web-auth/cose-lib/zipball/e5c417b3b90e06c84638a18d350e438d760cb955", - "reference": "e5c417b3b90e06c84638a18d350e438d760cb955", + "url": "https://api.github.com/repos/web-auth/cose-lib/zipball/a93b61c48fb587855f64a9ec11ad7b60e867cb15", + "reference": "a93b61c48fb587855f64a9ec11ad7b60e867cb15", "shasum": "" }, "require": { - "brick/math": "^0.9|^0.10|^0.11|^0.12", + "brick/math": "^0.9|^0.10|^0.11|^0.12|^0.13", "ext-json": "*", - "ext-mbstring": "*", "ext-openssl": "*", "php": ">=8.1", "spomky-labs/pki-framework": "^1.0" }, "require-dev": { - "ekino/phpstan-banned-code": "^1.0", - "infection/infection": "^0.27", + "deptrac/deptrac": "^3.0", + "ekino/phpstan-banned-code": "^1.0|^2.0|^3.0", + "infection/infection": "^0.29", "php-parallel-lint/php-parallel-lint": "^1.3", "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^1.7", - "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.1", - "phpstan/phpstan-strict-rules": "^1.2", - "phpunit/phpunit": "^10.1", - "qossmic/deptrac-shim": "^1.0", - "rector/rector": "^0.19", + "phpstan/phpstan": "^1.7|^2.0", + "phpstan/phpstan-deprecation-rules": "^1.0|^2.0", + "phpstan/phpstan-phpunit": "^1.1|^2.0", + "phpstan/phpstan-strict-rules": "^1.0|^2.0", + "phpunit/phpunit": "^10.1|^11.0|^12.0", + "rector/rector": "^2.0", "symfony/phpunit-bridge": "^6.4|^7.0", "symplify/easy-coding-standard": "^12.0" }, @@ -6387,7 +6382,7 @@ "ext-bcmath": "For better performance, please install either GMP (recommended) or BCMath extension", "ext-gmp": "For better performance, please install either GMP (recommended) or BCMath extension" }, - "time": "2024-02-05T21:00:39+00:00", + "time": "2025-08-14T20:33:29+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -6417,7 +6412,7 @@ ], "support": { "issues": "https://github.com/web-auth/cose-lib/issues", - "source": "https://github.com/web-auth/cose-lib/tree/4.3.0" + "source": "https://github.com/web-auth/cose-lib/tree/4.4.2" }, "funding": [ { @@ -6433,17 +6428,17 @@ }, { "name": "web-auth/webauthn-lib", - "version": "4.9.1", - "version_normalized": "4.9.1.0", + "version": "4.9.2", + "version_normalized": "4.9.2.0", "source": { "type": "git", "url": "https://github.com/web-auth/webauthn-lib.git", - "reference": "fd7a0943c663b325e92ad562c2bcc943e77beeac" + "reference": "008b25171c27cf4813420d0de31cc059bcc71f1a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/web-auth/webauthn-lib/zipball/fd7a0943c663b325e92ad562c2bcc943e77beeac", - "reference": "fd7a0943c663b325e92ad562c2bcc943e77beeac", + "url": "https://api.github.com/repos/web-auth/webauthn-lib/zipball/008b25171c27cf4813420d0de31cc059bcc71f1a", + "reference": "008b25171c27cf4813420d0de31cc059bcc71f1a", "shasum": "" }, "require": { @@ -6474,12 +6469,12 @@ "symfony/serializer": "As of 4.5.x, the symfony/serializer component will become mandatory for converting objects such as the Metadata Statement", "web-token/jwt-library": "Mandatory for fetching Metadata Statement from distant sources" }, - "time": "2024-07-16T18:36:36+00:00", + "time": "2025-01-04T09:47:58+00:00", "type": "library", "extra": { "thanks": { - "name": "web-auth/webauthn-framework", - "url": "https://github.com/web-auth/webauthn-framework" + "url": "https://github.com/web-auth/webauthn-framework", + "name": "web-auth/webauthn-framework" } }, "installation-source": "dist", @@ -6510,7 +6505,7 @@ "webauthn" ], "support": { - "source": "https://github.com/web-auth/webauthn-lib/tree/4.9.1" + "source": "https://github.com/web-auth/webauthn-lib/tree/4.9.2" }, "funding": [ { diff --git a/composer/installed.php b/composer/installed.php index 166e677ff..fe0c38087 100644 --- a/composer/installed.php +++ b/composer/installed.php @@ -38,9 +38,9 @@ 'dev_requirement' => false, ), 'brick/math' => array( - 'pretty_version' => '0.12.1', - 'version' => '0.12.1.0', - 'reference' => 'f510c0a40911935b77b86859eb5223d58d660df1', + 'pretty_version' => '0.13.1', + 'version' => '0.13.1.0', + 'reference' => 'fc7ed316430118cc7836bf45faff18d5dfc8de04', 'type' => 'library', 'install_path' => __DIR__ . '/../brick/math', 'aliases' => array(), @@ -317,9 +317,9 @@ 'dev_requirement' => false, ), 'paragonie/constant_time_encoding' => array( - 'pretty_version' => 'v2.6.3', - 'version' => '2.6.3.0', - 'reference' => '58c3f47f650c94ec05a151692652a868995d2938', + 'pretty_version' => 'v3.1.3', + 'version' => '3.1.3.0', + 'reference' => 'd5b01a39b3415c2cd581d3bd3a3575c1ebbd8e77', 'type' => 'library', 'install_path' => __DIR__ . '/../paragonie/constant_time_encoding', 'aliases' => array(), @@ -626,18 +626,18 @@ 'dev_requirement' => false, ), 'spomky-labs/cbor-php' => array( - 'pretty_version' => '3.0.4', - 'version' => '3.0.4.0', - 'reference' => '658ed12a85a6b31fa312b89cd92f3a4ce6df4c6b', + 'pretty_version' => '3.2.2', + 'version' => '3.2.2.0', + 'reference' => '2a5fb86aacfe1004611370ead6caa2bfc88435d0', 'type' => 'library', 'install_path' => __DIR__ . '/../spomky-labs/cbor-php', 'aliases' => array(), 'dev_requirement' => false, ), 'spomky-labs/pki-framework' => array( - 'pretty_version' => '1.2.1', - 'version' => '1.2.1.0', - 'reference' => '0b10c8b53366729417d6226ae89a665f9e2d61b6', + 'pretty_version' => '1.4.0', + 'version' => '1.4.0.0', + 'reference' => 'bf6f55a9d9eb25b7781640221cb54f5c727850d7', 'type' => 'library', 'install_path' => __DIR__ . '/../spomky-labs/pki-framework', 'aliases' => array(), @@ -818,9 +818,9 @@ 'dev_requirement' => false, ), 'symfony/polyfill-uuid' => array( - 'pretty_version' => 'v1.29.0', - 'version' => '1.29.0.0', - 'reference' => '3abdd21b0ceaa3000ee950097bc3cf9efc137853', + 'pretty_version' => 'v1.33.0', + 'version' => '1.33.0.0', + 'reference' => '21533be36c24be3f4b1669c4725c7d1d2bab4ae2', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/polyfill-uuid', 'aliases' => array(), @@ -887,9 +887,9 @@ ), ), 'symfony/uid' => array( - 'pretty_version' => 'v6.4.3', - 'version' => '6.4.3.0', - 'reference' => '1d31267211cc3a2fff32bcfc7c1818dac41b6fc0', + 'pretty_version' => 'v6.4.24', + 'version' => '6.4.24.0', + 'reference' => '17da16a750541a42cf2183935e0f6008316c23f7', 'type' => 'library', 'install_path' => __DIR__ . '/../symfony/uid', 'aliases' => array(), @@ -905,18 +905,18 @@ 'dev_requirement' => false, ), 'web-auth/cose-lib' => array( - 'pretty_version' => '4.3.0', - 'version' => '4.3.0.0', - 'reference' => 'e5c417b3b90e06c84638a18d350e438d760cb955', + 'pretty_version' => '4.4.2', + 'version' => '4.4.2.0', + 'reference' => 'a93b61c48fb587855f64a9ec11ad7b60e867cb15', 'type' => 'library', 'install_path' => __DIR__ . '/../web-auth/cose-lib', 'aliases' => array(), 'dev_requirement' => false, ), 'web-auth/webauthn-lib' => array( - 'pretty_version' => '4.9.1', - 'version' => '4.9.1.0', - 'reference' => 'fd7a0943c663b325e92ad562c2bcc943e77beeac', + 'pretty_version' => '4.9.2', + 'version' => '4.9.2.0', + 'reference' => '008b25171c27cf4813420d0de31cc059bcc71f1a', 'type' => 'library', 'install_path' => __DIR__ . '/../web-auth/webauthn-lib', 'aliases' => array(), diff --git a/paragonie/constant_time_encoding/src/Base32.php b/paragonie/constant_time_encoding/src/Base32.php index 7508b3df6..379552af5 100644 --- a/paragonie/constant_time_encoding/src/Base32.php +++ b/paragonie/constant_time_encoding/src/Base32.php @@ -3,8 +3,15 @@ namespace ParagonIE\ConstantTime; use InvalidArgumentException; +use Override; use RangeException; +use SensitiveParameter; use TypeError; +use function pack; +use function rtrim; +use function strlen; +use function substr; +use function unpack; /** * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises. @@ -44,8 +51,12 @@ abstract class Base32 implements EncoderInterface * @param bool $strictPadding * @return string */ - public static function decode(string $encodedString, bool $strictPadding = false): string - { + #[Override] + public static function decode( + #[SensitiveParameter] + string $encodedString, + bool $strictPadding = false + ): string { return static::doDecode($encodedString, false, $strictPadding); } @@ -56,8 +67,11 @@ public static function decode(string $encodedString, bool $strictPadding = false * @param bool $strictPadding * @return string */ - public static function decodeUpper(string $src, bool $strictPadding = false): string - { + public static function decodeUpper( + #[SensitiveParameter] + string $src, + bool $strictPadding = false + ): string { return static::doDecode($src, true, $strictPadding); } @@ -68,19 +82,26 @@ public static function decodeUpper(string $src, bool $strictPadding = false): st * @return string * @throws TypeError */ - public static function encode(string $binString): string - { + #[Override] + public static function encode( + #[SensitiveParameter] + string $binString + ): string { return static::doEncode($binString, false, true); } + /** * Encode into Base32 (RFC 4648) * * @param string $src * @return string * @throws TypeError + * @api */ - public static function encodeUnpadded(string $src): string - { + public static function encodeUnpadded( + #[SensitiveParameter] + string $src + ): string { return static::doEncode($src, false, false); } @@ -90,9 +111,12 @@ public static function encodeUnpadded(string $src): string * @param string $src * @return string * @throws TypeError + * @api */ - public static function encodeUpper(string $src): string - { + public static function encodeUpper( + #[SensitiveParameter] + string $src + ): string { return static::doEncode($src, true, true); } @@ -102,9 +126,12 @@ public static function encodeUpper(string $src): string * @param string $src * @return string * @throws TypeError + * @api */ - public static function encodeUpperUnpadded(string $src): string - { + public static function encodeUpperUnpadded( + #[SensitiveParameter] + string $src + ): string { return static::doEncode($src, true, false); } @@ -114,6 +141,7 @@ public static function encodeUpperUnpadded(string $src): string * * @param int $src * @return int + * @api */ protected static function decode5Bits(int $src): int { @@ -136,6 +164,7 @@ protected static function decode5Bits(int $src): int * * @param int $src * @return int + * @api */ protected static function decode5BitsUpper(int $src): int { @@ -156,6 +185,7 @@ protected static function decode5BitsUpper(int $src): int * * @param int $src * @return string + * @api */ protected static function encode5Bits(int $src): string { @@ -164,7 +194,7 @@ protected static function encode5Bits(int $src): string // if ($src > 25) $ret -= 72; $diff -= ((25 - $src) >> 8) & 73; - return \pack('C', $src + $diff); + return pack('C', $src + $diff); } /** @@ -175,6 +205,7 @@ protected static function encode5Bits(int $src): string * * @param int $src * @return string + * @api */ protected static function encode5BitsUpper(int $src): string { @@ -183,17 +214,21 @@ protected static function encode5BitsUpper(int $src): string // if ($src > 25) $ret -= 40; $diff -= ((25 - $src) >> 8) & 41; - return \pack('C', $src + $diff); + return pack('C', $src + $diff); } /** * @param string $encodedString * @param bool $upper * @return string + * @api */ - public static function decodeNoPadding(string $encodedString, bool $upper = false): string - { - $srcLen = Binary::safeStrlen($encodedString); + public static function decodeNoPadding( + #[SensitiveParameter] + string $encodedString, + bool $upper = false + ): string { + $srcLen = strlen($encodedString); if ($srcLen === 0) { return ''; } @@ -222,9 +257,9 @@ public static function decodeNoPadding(string $encodedString, bool $upper = fals * @return string * * @throws TypeError - * @psalm-suppress RedundantCondition */ protected static function doDecode( + #[SensitiveParameter] string $src, bool $upper = false, bool $strictPadding = false @@ -235,7 +270,7 @@ protected static function doDecode( : 'decode5Bits'; // Remove padding - $srcLen = Binary::safeStrlen($src); + $srcLen = strlen($src); if ($srcLen === 0) { return ''; } @@ -255,8 +290,8 @@ protected static function doDecode( ); } } else { - $src = \rtrim($src, '='); - $srcLen = Binary::safeStrlen($src); + $src = rtrim($src, '='); + $srcLen = strlen($src); } $err = 0; @@ -264,7 +299,7 @@ protected static function doDecode( // Main loop (no padding): for ($i = 0; $i + 8 <= $srcLen; $i += 8) { /** @var array $chunk */ - $chunk = \unpack('C*', Binary::safeSubstr($src, $i, 8)); + $chunk = unpack('C*', substr($src, $i, 8)); /** @var int $c0 */ $c0 = static::$method($chunk[1]); /** @var int $c1 */ @@ -282,7 +317,7 @@ protected static function doDecode( /** @var int $c7 */ $c7 = static::$method($chunk[8]); - $dest .= \pack( + $dest .= pack( 'CCCCC', (($c0 << 3) | ($c1 >> 2) ) & 0xff, (($c1 << 6) | ($c2 << 1) | ($c3 >> 4)) & 0xff, @@ -295,7 +330,7 @@ protected static function doDecode( // The last chunk, which may have padding: if ($i < $srcLen) { /** @var array $chunk */ - $chunk = \unpack('C*', Binary::safeSubstr($src, $i, $srcLen - $i)); + $chunk = unpack('C*', substr($src, $i, $srcLen - $i)); /** @var int $c0 */ $c0 = static::$method($chunk[1]); @@ -313,7 +348,7 @@ protected static function doDecode( /** @var int $c6 */ $c6 = static::$method($chunk[7]); - $dest .= \pack( + $dest .= pack( 'CCCC', (($c0 << 3) | ($c1 >> 2) ) & 0xff, (($c1 << 6) | ($c2 << 1) | ($c3 >> 4)) & 0xff, @@ -336,7 +371,7 @@ protected static function doDecode( /** @var int $c5 */ $c5 = static::$method($chunk[6]); - $dest .= \pack( + $dest .= pack( 'CCCC', (($c0 << 3) | ($c1 >> 2) ) & 0xff, (($c1 << 6) | ($c2 << 1) | ($c3 >> 4)) & 0xff, @@ -354,7 +389,7 @@ protected static function doDecode( /** @var int $c4 */ $c4 = static::$method($chunk[5]); - $dest .= \pack( + $dest .= pack( 'CCC', (($c0 << 3) | ($c1 >> 2) ) & 0xff, (($c1 << 6) | ($c2 << 1) | ($c3 >> 4)) & 0xff, @@ -372,7 +407,7 @@ protected static function doDecode( /** @var int $c3 */ $c3 = static::$method($chunk[4]); - $dest .= \pack( + $dest .= pack( 'CC', (($c0 << 3) | ($c1 >> 2) ) & 0xff, (($c1 << 6) | ($c2 << 1) | ($c3 >> 4)) & 0xff @@ -387,7 +422,7 @@ protected static function doDecode( /** @var int $c2 */ $c2 = static::$method($chunk[3]); - $dest .= \pack( + $dest .= pack( 'CC', (($c0 << 3) | ($c1 >> 2) ) & 0xff, (($c1 << 6) | ($c2 << 1) ) & 0xff @@ -400,7 +435,7 @@ protected static function doDecode( /** @var int $c1 */ $c1 = static::$method($chunk[2]); - $dest .= \pack( + $dest .= pack( 'C', (($c0 << 3) | ($c1 >> 2) ) & 0xff ); @@ -409,7 +444,7 @@ protected static function doDecode( $err |= ($c1 << 6) & 0xff; } } else { - $dest .= \pack( + $dest .= pack( 'C', (($c0 << 3) ) & 0xff ); @@ -434,20 +469,24 @@ protected static function doDecode( * @return string * @throws TypeError */ - protected static function doEncode(string $src, bool $upper = false, $pad = true): string - { + protected static function doEncode( + #[SensitiveParameter] + string $src, + bool $upper = false, + bool $pad = true + ): string { // We do this to reduce code duplication: $method = $upper ? 'encode5BitsUpper' : 'encode5Bits'; $dest = ''; - $srcLen = Binary::safeStrlen($src); + $srcLen = strlen($src); // Main loop (no padding): for ($i = 0; $i + 5 <= $srcLen; $i += 5) { /** @var array $chunk */ - $chunk = \unpack('C*', Binary::safeSubstr($src, $i, 5)); + $chunk = unpack('C*', substr($src, $i, 5)); $b0 = $chunk[1]; $b1 = $chunk[2]; $b2 = $chunk[3]; @@ -466,7 +505,7 @@ protected static function doEncode(string $src, bool $upper = false, $pad = true // The last chunk, which may have padding: if ($i < $srcLen) { /** @var array $chunk */ - $chunk = \unpack('C*', Binary::safeSubstr($src, $i, $srcLen - $i)); + $chunk = unpack('C*', substr($src, $i, $srcLen - $i)); $b0 = $chunk[1]; if ($i + 3 < $srcLen) { $b1 = $chunk[2]; diff --git a/paragonie/constant_time_encoding/src/Base32Hex.php b/paragonie/constant_time_encoding/src/Base32Hex.php index b868dd048..4323a573a 100644 --- a/paragonie/constant_time_encoding/src/Base32Hex.php +++ b/paragonie/constant_time_encoding/src/Base32Hex.php @@ -2,6 +2,9 @@ declare(strict_types=1); namespace ParagonIE\ConstantTime; +use Override; +use function pack; + /** * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises. * Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com) @@ -40,6 +43,7 @@ abstract class Base32Hex extends Base32 * @param int $src * @return int */ + #[Override] protected static function decode5Bits(int $src): int { $ret = -1; @@ -60,6 +64,7 @@ protected static function decode5Bits(int $src): int * @param int $src * @return int */ + #[Override] protected static function decode5BitsUpper(int $src): int { $ret = -1; @@ -80,6 +85,7 @@ protected static function decode5BitsUpper(int $src): int * @param int $src * @return string */ + #[Override] protected static function encode5Bits(int $src): string { $src += 0x30; @@ -87,7 +93,7 @@ protected static function encode5Bits(int $src): string // if ($src > 0x39) $src += 0x61 - 0x3a; // 39 $src += ((0x39 - $src) >> 8) & 39; - return \pack('C', $src); + return pack('C', $src); } /** @@ -99,6 +105,7 @@ protected static function encode5Bits(int $src): string * @param int $src * @return string */ + #[Override] protected static function encode5BitsUpper(int $src): string { $src += 0x30; @@ -106,6 +113,6 @@ protected static function encode5BitsUpper(int $src): string // if ($src > 0x39) $src += 0x41 - 0x3a; // 7 $src += ((0x39 - $src) >> 8) & 7; - return \pack('C', $src); + return pack('C', $src); } } \ No newline at end of file diff --git a/paragonie/constant_time_encoding/src/Base64.php b/paragonie/constant_time_encoding/src/Base64.php index f5716179f..9679748dc 100644 --- a/paragonie/constant_time_encoding/src/Base64.php +++ b/paragonie/constant_time_encoding/src/Base64.php @@ -3,8 +3,23 @@ namespace ParagonIE\ConstantTime; use InvalidArgumentException; +use Override; use RangeException; +use SensitiveParameter; +use SodiumException; use TypeError; +use function extension_loaded; +use function pack; +use function rtrim; +use function sodium_base642bin; +use function sodium_bin2base64; +use function strlen; +use function substr; +use function unpack; +use const SODIUM_BASE64_VARIANT_ORIGINAL; +use const SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING; +use const SODIUM_BASE64_VARIANT_URLSAFE; +use const SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING; /** * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises. @@ -47,8 +62,25 @@ abstract class Base64 implements EncoderInterface * * @throws TypeError */ - public static function encode(string $binString): string - { + #[Override] + public static function encode( + #[SensitiveParameter] + string $binString + ): string { + if (extension_loaded('sodium')) { + $variant = match(static::class) { + Base64::class => SODIUM_BASE64_VARIANT_ORIGINAL, + Base64UrlSafe::class => SODIUM_BASE64_VARIANT_URLSAFE, + default => 0, + }; + if ($variant > 0) { + try { + return sodium_bin2base64($binString, $variant); + } catch (SodiumException $ex) { + throw new RangeException($ex->getMessage(), $ex->getCode(), $ex); + } + } + } return static::doEncode($binString, true); } @@ -61,9 +93,26 @@ public static function encode(string $binString): string * @return string * * @throws TypeError + * @api */ - public static function encodeUnpadded(string $src): string - { + public static function encodeUnpadded( + #[SensitiveParameter] + string $src + ): string { + if (extension_loaded('sodium')) { + $variant = match(static::class) { + Base64::class => SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING, + Base64UrlSafe::class => SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING, + default => 0, + }; + if ($variant > 0) { + try { + return sodium_bin2base64($src, $variant); + } catch (SodiumException $ex) { + throw new RangeException($ex->getMessage(), $ex->getCode(), $ex); + } + } + } return static::doEncode($src, false); } @@ -74,14 +123,17 @@ public static function encodeUnpadded(string $src): string * * @throws TypeError */ - protected static function doEncode(string $src, bool $pad = true): string - { + protected static function doEncode( + #[SensitiveParameter] + string $src, + bool $pad = true + ): string { $dest = ''; - $srcLen = Binary::safeStrlen($src); + $srcLen = strlen($src); // Main loop (no padding): for ($i = 0; $i + 3 <= $srcLen; $i += 3) { /** @var array $chunk */ - $chunk = \unpack('C*', Binary::safeSubstr($src, $i, 3)); + $chunk = unpack('C*', substr($src, $i, 3)); $b0 = $chunk[1]; $b1 = $chunk[2]; $b2 = $chunk[3]; @@ -95,7 +147,7 @@ protected static function doEncode(string $src, bool $pad = true): string // The last chunk, which may have padding: if ($i < $srcLen) { /** @var array $chunk */ - $chunk = \unpack('C*', Binary::safeSubstr($src, $i, $srcLen - $i)); + $chunk = unpack('C*', substr($src, $i, $srcLen - $i)); $b0 = $chunk[1]; if ($i + 1 < $srcLen) { $b1 = $chunk[2]; @@ -129,12 +181,15 @@ protected static function doEncode(string $src, bool $pad = true): string * * @throws RangeException * @throws TypeError - * @psalm-suppress RedundantCondition */ - public static function decode(string $encodedString, bool $strictPadding = false): string - { + #[Override] + public static function decode( + #[SensitiveParameter] + string $encodedString, + bool $strictPadding = false + ): string { // Remove padding - $srcLen = Binary::safeStrlen($encodedString); + $srcLen = strlen($encodedString); if ($srcLen === 0) { return ''; } @@ -158,9 +213,24 @@ public static function decode(string $encodedString, bool $strictPadding = false 'Incorrect padding' ); } + if (extension_loaded('sodium')) { + $variant = match(static::class) { + Base64::class => SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING, + Base64UrlSafe::class => SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING, + default => 0, + }; + if ($variant > 0) { + try { + return sodium_base642bin(substr($encodedString, 0, $srcLen), $variant); + } catch (SodiumException $ex) { + throw new RangeException($ex->getMessage(), $ex->getCode(), $ex); + } + } + } } else { - $encodedString = \rtrim($encodedString, '='); - $srcLen = Binary::safeStrlen($encodedString); + // Just remove all padding. + $encodedString = rtrim($encodedString, '='); + $srcLen = strlen($encodedString); } $err = 0; @@ -168,13 +238,13 @@ public static function decode(string $encodedString, bool $strictPadding = false // Main loop (no padding): for ($i = 0; $i + 4 <= $srcLen; $i += 4) { /** @var array $chunk */ - $chunk = \unpack('C*', Binary::safeSubstr($encodedString, $i, 4)); + $chunk = unpack('C*', substr($encodedString, $i, 4)); $c0 = static::decode6Bits($chunk[1]); $c1 = static::decode6Bits($chunk[2]); $c2 = static::decode6Bits($chunk[3]); $c3 = static::decode6Bits($chunk[4]); - $dest .= \pack( + $dest .= pack( 'CCC', ((($c0 << 2) | ($c1 >> 4)) & 0xff), ((($c1 << 4) | ($c2 >> 2)) & 0xff), @@ -185,13 +255,13 @@ public static function decode(string $encodedString, bool $strictPadding = false // The last chunk, which may have padding: if ($i < $srcLen) { /** @var array $chunk */ - $chunk = \unpack('C*', Binary::safeSubstr($encodedString, $i, $srcLen - $i)); + $chunk = unpack('C*', substr($encodedString, $i, $srcLen - $i)); $c0 = static::decode6Bits($chunk[1]); if ($i + 2 < $srcLen) { $c1 = static::decode6Bits($chunk[2]); $c2 = static::decode6Bits($chunk[3]); - $dest .= \pack( + $dest .= pack( 'CC', ((($c0 << 2) | ($c1 >> 4)) & 0xff), ((($c1 << 4) | ($c2 >> 2)) & 0xff) @@ -202,7 +272,7 @@ public static function decode(string $encodedString, bool $strictPadding = false } } elseif ($i + 1 < $srcLen) { $c1 = static::decode6Bits($chunk[2]); - $dest .= \pack( + $dest .= pack( 'C', ((($c0 << 2) | ($c1 >> 4)) & 0xff) ); @@ -226,26 +296,23 @@ public static function decode(string $encodedString, bool $strictPadding = false /** * @param string $encodedString * @return string + * @api */ - public static function decodeNoPadding(string $encodedString): string - { - $srcLen = Binary::safeStrlen($encodedString); + public static function decodeNoPadding( + #[SensitiveParameter] + string $encodedString + ): string { + $srcLen = strlen($encodedString); if ($srcLen === 0) { return ''; } if (($srcLen & 3) === 0) { - if ($encodedString[$srcLen - 1] === '=') { + // If $strLen is not zero, and it is divisible by 4, then it's at least 4. + if ($encodedString[$srcLen - 1] === '=' || $encodedString[$srcLen - 2] === '=') { throw new InvalidArgumentException( "decodeNoPadding() doesn't tolerate padding" ); } - if (($srcLen & 3) > 1) { - if ($encodedString[$srcLen - 2] === '=') { - throw new InvalidArgumentException( - "decodeNoPadding() doesn't tolerate padding" - ); - } - } } return static::decode( $encodedString, @@ -309,6 +376,6 @@ protected static function encode6Bits(int $src): string // if ($src > 62) $diff += 0x2f - 0x2b - 1; // 3 $diff += ((62 - $src) >> 8) & 3; - return \pack('C', $src + $diff); + return pack('C', $src + $diff); } } diff --git a/paragonie/constant_time_encoding/src/Base64DotSlash.php b/paragonie/constant_time_encoding/src/Base64DotSlash.php index 5e98a8f79..847751767 100644 --- a/paragonie/constant_time_encoding/src/Base64DotSlash.php +++ b/paragonie/constant_time_encoding/src/Base64DotSlash.php @@ -2,6 +2,8 @@ declare(strict_types=1); namespace ParagonIE\ConstantTime; +use Override; + /** * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises. * Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com) @@ -44,6 +46,7 @@ abstract class Base64DotSlash extends Base64 * @param int $src * @return int */ + #[Override] protected static function decode6Bits(int $src): int { $ret = -1; @@ -70,6 +73,7 @@ protected static function decode6Bits(int $src): int * @param int $src * @return string */ + #[Override] protected static function encode6Bits(int $src): string { $src += 0x2e; diff --git a/paragonie/constant_time_encoding/src/Base64DotSlashOrdered.php b/paragonie/constant_time_encoding/src/Base64DotSlashOrdered.php index 9780b14bb..2c42db37f 100644 --- a/paragonie/constant_time_encoding/src/Base64DotSlashOrdered.php +++ b/paragonie/constant_time_encoding/src/Base64DotSlashOrdered.php @@ -2,6 +2,8 @@ declare(strict_types=1); namespace ParagonIE\ConstantTime; +use Override; + /** * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises. * Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com) @@ -44,6 +46,7 @@ abstract class Base64DotSlashOrdered extends Base64 * @param int $src * @return int */ + #[Override] protected static function decode6Bits(int $src): int { $ret = -1; @@ -67,6 +70,7 @@ protected static function decode6Bits(int $src): int * @param int $src * @return string */ + #[Override] protected static function encode6Bits(int $src): string { $src += 0x2e; diff --git a/paragonie/constant_time_encoding/src/Base64UrlSafe.php b/paragonie/constant_time_encoding/src/Base64UrlSafe.php index 8192c63d5..845aaf626 100644 --- a/paragonie/constant_time_encoding/src/Base64UrlSafe.php +++ b/paragonie/constant_time_encoding/src/Base64UrlSafe.php @@ -2,6 +2,8 @@ declare(strict_types=1); namespace ParagonIE\ConstantTime; +use Override; + /** * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises. * Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com) @@ -45,6 +47,7 @@ abstract class Base64UrlSafe extends Base64 * @param int $src * @return int */ + #[Override] protected static function decode6Bits(int $src): int { $ret = -1; @@ -74,6 +77,7 @@ protected static function decode6Bits(int $src): int * @param int $src * @return string */ + #[Override] protected static function encode6Bits(int $src): string { $diff = 0x41; diff --git a/paragonie/constant_time_encoding/src/Binary.php b/paragonie/constant_time_encoding/src/Binary.php index 828f3e0f6..369584407 100644 --- a/paragonie/constant_time_encoding/src/Binary.php +++ b/paragonie/constant_time_encoding/src/Binary.php @@ -2,7 +2,10 @@ declare(strict_types=1); namespace ParagonIE\ConstantTime; +use SensitiveParameter; use TypeError; +use function strlen; +use function substr; /** * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises. @@ -45,15 +48,11 @@ abstract class Binary * @param string $str * @return int */ - public static function safeStrlen(string $str): int - { - if (\function_exists('mb_strlen')) { - // mb_strlen in PHP 7.x can return false. - /** @psalm-suppress RedundantCast */ - return (int) \mb_strlen($str, '8bit'); - } else { - return \strlen($str); - } + public static function safeStrlen( + #[SensitiveParameter] + string $str + ): int { + return strlen($str); } /** @@ -70,21 +69,19 @@ public static function safeStrlen(string $str): int * @throws TypeError */ public static function safeSubstr( + #[SensitiveParameter] string $str, int $start = 0, - $length = null + ?int $length = null ): string { if ($length === 0) { return ''; } - if (\function_exists('mb_substr')) { - return \mb_substr($str, $start, $length, '8bit'); - } // Unlike mb_substr(), substr() doesn't accept NULL for length if ($length !== null) { - return \substr($str, $start, $length); + return substr($str, $start, $length); } else { - return \substr($str, $start); + return substr($str, $start); } } } diff --git a/paragonie/constant_time_encoding/src/EncoderInterface.php b/paragonie/constant_time_encoding/src/EncoderInterface.php index 9cafbf96c..cb358ea0d 100644 --- a/paragonie/constant_time_encoding/src/EncoderInterface.php +++ b/paragonie/constant_time_encoding/src/EncoderInterface.php @@ -2,6 +2,8 @@ declare(strict_types=1); namespace ParagonIE\ConstantTime; +use SensitiveParameter; + /** * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises. * Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com) @@ -38,7 +40,10 @@ interface EncoderInterface * @param string $binString (raw binary) * @return string */ - public static function encode(string $binString): string; + public static function encode( + #[SensitiveParameter] + string $binString + ): string; /** * Convert a binary string into a hexadecimal string without cache-timing @@ -48,5 +53,9 @@ public static function encode(string $binString): string; * @param bool $strictPadding Error on invalid padding * @return string (raw binary) */ - public static function decode(string $encodedString, bool $strictPadding = false): string; + public static function decode( + #[SensitiveParameter] + string $encodedString, + bool $strictPadding = false + ): string; } diff --git a/paragonie/constant_time_encoding/src/Encoding.php b/paragonie/constant_time_encoding/src/Encoding.php index 8649f31fc..b28a5014e 100644 --- a/paragonie/constant_time_encoding/src/Encoding.php +++ b/paragonie/constant_time_encoding/src/Encoding.php @@ -2,6 +2,8 @@ declare(strict_types=1); namespace ParagonIE\ConstantTime; +use RangeException; +use SensitiveParameter; use TypeError; /** @@ -30,6 +32,7 @@ /** * Class Encoding * @package ParagonIE\ConstantTime + * @api */ abstract class Encoding { @@ -40,8 +43,10 @@ abstract class Encoding * @return string * @throws TypeError */ - public static function base32Encode(string $str): string - { + public static function base32Encode( + #[SensitiveParameter] + string $str + ): string { return Base32::encode($str); } @@ -52,8 +57,10 @@ public static function base32Encode(string $str): string * @return string * @throws TypeError */ - public static function base32EncodeUpper(string $str): string - { + public static function base32EncodeUpper( + #[SensitiveParameter] + string $str + ): string { return Base32::encodeUpper($str); } @@ -64,8 +71,10 @@ public static function base32EncodeUpper(string $str): string * @return string * @throws TypeError */ - public static function base32Decode(string $str): string - { + public static function base32Decode( + #[SensitiveParameter] + string $str + ): string { return Base32::decode($str); } @@ -76,8 +85,10 @@ public static function base32Decode(string $str): string * @return string * @throws TypeError */ - public static function base32DecodeUpper(string $str): string - { + public static function base32DecodeUpper( + #[SensitiveParameter] + string $str + ): string { return Base32::decodeUpper($str); } @@ -88,8 +99,10 @@ public static function base32DecodeUpper(string $str): string * @return string * @throws TypeError */ - public static function base32HexEncode(string $str): string - { + public static function base32HexEncode( + #[SensitiveParameter] + string $str + ): string { return Base32Hex::encode($str); } @@ -100,8 +113,10 @@ public static function base32HexEncode(string $str): string * @return string * @throws TypeError */ - public static function base32HexEncodeUpper(string $str): string - { + public static function base32HexEncodeUpper( + #[SensitiveParameter] + string $str + ): string { return Base32Hex::encodeUpper($str); } @@ -112,8 +127,10 @@ public static function base32HexEncodeUpper(string $str): string * @return string * @throws TypeError */ - public static function base32HexDecode(string $str): string - { + public static function base32HexDecode( + #[SensitiveParameter] + string $str + ): string { return Base32Hex::decode($str); } @@ -124,8 +141,10 @@ public static function base32HexDecode(string $str): string * @return string * @throws TypeError */ - public static function base32HexDecodeUpper(string $str): string - { + public static function base32HexDecodeUpper( + #[SensitiveParameter] + string $str + ): string { return Base32Hex::decodeUpper($str); } @@ -136,8 +155,10 @@ public static function base32HexDecodeUpper(string $str): string * @return string * @throws TypeError */ - public static function base64Encode(string $str): string - { + public static function base64Encode( + #[SensitiveParameter] + string $str + ): string { return Base64::encode($str); } @@ -148,8 +169,10 @@ public static function base64Encode(string $str): string * @return string * @throws TypeError */ - public static function base64Decode(string $str): string - { + public static function base64Decode( + #[SensitiveParameter] + string $str + ): string { return Base64::decode($str); } @@ -161,8 +184,10 @@ public static function base64Decode(string $str): string * @return string * @throws TypeError */ - public static function base64EncodeDotSlash(string $str): string - { + public static function base64EncodeDotSlash( + #[SensitiveParameter] + string $str + ): string { return Base64DotSlash::encode($str); } @@ -173,11 +198,13 @@ public static function base64EncodeDotSlash(string $str): string * * @param string $str * @return string - * @throws \RangeException + * @throws RangeException * @throws TypeError */ - public static function base64DecodeDotSlash(string $str): string - { + public static function base64DecodeDotSlash( + #[SensitiveParameter] + string $str + ): string { return Base64DotSlash::decode($str); } @@ -189,8 +216,10 @@ public static function base64DecodeDotSlash(string $str): string * @return string * @throws TypeError */ - public static function base64EncodeDotSlashOrdered(string $str): string - { + public static function base64EncodeDotSlashOrdered( + #[SensitiveParameter] + string $str + ): string { return Base64DotSlashOrdered::encode($str); } @@ -201,11 +230,13 @@ public static function base64EncodeDotSlashOrdered(string $str): string * * @param string $str * @return string - * @throws \RangeException + * @throws RangeException * @throws TypeError */ - public static function base64DecodeDotSlashOrdered(string $str): string - { + public static function base64DecodeDotSlashOrdered( + #[SensitiveParameter] + string $str + ): string { return Base64DotSlashOrdered::decode($str); } @@ -217,8 +248,10 @@ public static function base64DecodeDotSlashOrdered(string $str): string * @return string * @throws TypeError */ - public static function hexEncode(string $bin_string): string - { + public static function hexEncode( + #[SensitiveParameter] + string $bin_string + ): string { return Hex::encode($bin_string); } @@ -228,10 +261,12 @@ public static function hexEncode(string $bin_string): string * * @param string $hex_string * @return string (raw binary) - * @throws \RangeException + * @throws RangeException */ - public static function hexDecode(string $hex_string): string - { + public static function hexDecode( + #[SensitiveParameter] + string $hex_string + ): string { return Hex::decode($hex_string); } @@ -243,8 +278,10 @@ public static function hexDecode(string $hex_string): string * @return string * @throws TypeError */ - public static function hexEncodeUpper(string $bin_string): string - { + public static function hexEncodeUpper( + #[SensitiveParameter] + string $bin_string + ): string { return Hex::encodeUpper($bin_string); } @@ -255,8 +292,10 @@ public static function hexEncodeUpper(string $bin_string): string * @param string $bin_string (raw binary) * @return string */ - public static function hexDecodeUpper(string $bin_string): string - { + public static function hexDecodeUpper( + #[SensitiveParameter] + string $bin_string + ): string { return Hex::decode($bin_string); } } diff --git a/paragonie/constant_time_encoding/src/Hex.php b/paragonie/constant_time_encoding/src/Hex.php index a9e058cd3..b515b9758 100644 --- a/paragonie/constant_time_encoding/src/Hex.php +++ b/paragonie/constant_time_encoding/src/Hex.php @@ -2,11 +2,20 @@ declare(strict_types=1); namespace ParagonIE\ConstantTime; +use Override; use RangeException; +use SensitiveParameter; +use SodiumException; use TypeError; +use function extension_loaded; +use function pack; +use function sodium_bin2hex; +use function sodium_hex2bin; +use function strlen; +use function unpack; /** - * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises. + * Copyright (c) 2016 - 2025 Paragon Initiative Enterprises. * Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com) * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -42,17 +51,27 @@ abstract class Hex implements EncoderInterface * @return string * @throws TypeError */ - public static function encode(string $binString): string - { + #[Override] + public static function encode( + #[SensitiveParameter] + string $binString + ): string { + if (extension_loaded('sodium')) { + try { + return sodium_bin2hex($binString); + } catch (SodiumException $ex) { + throw new RangeException($ex->getMessage(), $ex->getCode(), $ex); + } + } $hex = ''; - $len = Binary::safeStrlen($binString); + $len = strlen($binString); for ($i = 0; $i < $len; ++$i) { /** @var array $chunk */ - $chunk = \unpack('C', $binString[$i]); + $chunk = unpack('C', $binString[$i]); $c = $chunk[1] & 0xf; $b = $chunk[1] >> 4; - $hex .= \pack( + $hex .= pack( 'CC', (87 + $b + ((($b - 10) >> 8) & ~38)), (87 + $c + ((($c - 10) >> 8) & ~38)) @@ -69,18 +88,20 @@ public static function encode(string $binString): string * @return string * @throws TypeError */ - public static function encodeUpper(string $binString): string - { + public static function encodeUpper( + #[SensitiveParameter] + string $binString + ): string { $hex = ''; - $len = Binary::safeStrlen($binString); + $len = strlen($binString); for ($i = 0; $i < $len; ++$i) { /** @var array $chunk */ - $chunk = \unpack('C', $binString[$i]); + $chunk = unpack('C', $binString[$i]); $c = $chunk[1] & 0xf; $b = $chunk[1] >> 4; - $hex .= \pack( + $hex .= pack( 'CC', (55 + $b + ((($b - 10) >> 8) & ~6)), (55 + $c + ((($c - 10) >> 8) & ~6)) @@ -98,14 +119,23 @@ public static function encodeUpper(string $binString): string * @return string (raw binary) * @throws RangeException */ + #[Override] public static function decode( + #[SensitiveParameter] string $encodedString, bool $strictPadding = false ): string { + if (extension_loaded('sodium') && $strictPadding) { + try { + return sodium_hex2bin($encodedString); + } catch (SodiumException $ex) { + throw new RangeException($ex->getMessage(), $ex->getCode(), $ex); + } + } $hex_pos = 0; $bin = ''; $c_acc = 0; - $hex_len = Binary::safeStrlen($encodedString); + $hex_len = strlen($encodedString); $state = 0; if (($hex_len & 1) !== 0) { if ($strictPadding) { @@ -119,7 +149,7 @@ public static function decode( } /** @var array $chunk */ - $chunk = \unpack('C*', $encodedString); + $chunk = unpack('C*', $encodedString); while ($hex_pos < $hex_len) { ++$hex_pos; $c = $chunk[$hex_pos]; @@ -137,7 +167,7 @@ public static function decode( if ($state === 0) { $c_acc = $c_val * 16; } else { - $bin .= \pack('C', $c_acc | $c_val); + $bin .= pack('C', $c_acc | $c_val); } $state ^= 1; } diff --git a/paragonie/constant_time_encoding/src/RFC4648.php b/paragonie/constant_time_encoding/src/RFC4648.php index f124d65bf..fb66f73d7 100644 --- a/paragonie/constant_time_encoding/src/RFC4648.php +++ b/paragonie/constant_time_encoding/src/RFC4648.php @@ -2,6 +2,7 @@ declare(strict_types=1); namespace ParagonIE\ConstantTime; +use SensitiveParameter; use TypeError; /** @@ -33,6 +34,7 @@ * This class conforms strictly to the RFC * * @package ParagonIE\ConstantTime + * @api */ abstract class RFC4648 { @@ -46,8 +48,10 @@ abstract class RFC4648 * * @throws TypeError */ - public static function base64Encode(string $str): string - { + public static function base64Encode( + #[SensitiveParameter] + string $str + ): string { return Base64::encode($str); } @@ -61,8 +65,10 @@ public static function base64Encode(string $str): string * * @throws TypeError */ - public static function base64Decode(string $str): string - { + public static function base64Decode( + #[SensitiveParameter] + string $str + ): string { return Base64::decode($str, true); } @@ -76,8 +82,10 @@ public static function base64Decode(string $str): string * * @throws TypeError */ - public static function base64UrlSafeEncode(string $str): string - { + public static function base64UrlSafeEncode( + #[SensitiveParameter] + string $str + ): string { return Base64UrlSafe::encode($str); } @@ -91,8 +99,10 @@ public static function base64UrlSafeEncode(string $str): string * * @throws TypeError */ - public static function base64UrlSafeDecode(string $str): string - { + public static function base64UrlSafeDecode( + #[SensitiveParameter] + string $str + ): string { return Base64UrlSafe::decode($str, true); } @@ -106,8 +116,10 @@ public static function base64UrlSafeDecode(string $str): string * * @throws TypeError */ - public static function base32Encode(string $str): string - { + public static function base32Encode( + #[SensitiveParameter] + string $str + ): string { return Base32::encodeUpper($str); } @@ -121,8 +133,10 @@ public static function base32Encode(string $str): string * * @throws TypeError */ - public static function base32Decode(string $str): string - { + public static function base32Decode( + #[SensitiveParameter] + string $str + ): string { return Base32::decodeUpper($str, true); } @@ -136,8 +150,10 @@ public static function base32Decode(string $str): string * * @throws TypeError */ - public static function base32HexEncode(string $str): string - { + public static function base32HexEncode( + #[SensitiveParameter] + string $str + ): string { return Base32::encodeUpper($str); } @@ -151,8 +167,10 @@ public static function base32HexEncode(string $str): string * * @throws TypeError */ - public static function base32HexDecode(string $str): string - { + public static function base32HexDecode( + #[SensitiveParameter] + string $str + ): string { return Base32::decodeUpper($str, true); } @@ -166,8 +184,10 @@ public static function base32HexDecode(string $str): string * * @throws TypeError */ - public static function base16Encode(string $str): string - { + public static function base16Encode( + #[SensitiveParameter] + string $str + ): string { return Hex::encodeUpper($str); } @@ -179,8 +199,10 @@ public static function base16Encode(string $str): string * @param string $str * @return string */ - public static function base16Decode(string $str): string - { + public static function base16Decode( + #[SensitiveParameter] + string $str + ): string { return Hex::decode($str, true); } -} \ No newline at end of file +} diff --git a/spomky-labs/cbor-php/RELEASES.md b/spomky-labs/cbor-php/RELEASES.md new file mode 100644 index 000000000..b685c6b6f --- /dev/null +++ b/spomky-labs/cbor-php/RELEASES.md @@ -0,0 +1,18 @@ +# Versioning and Release + +This document describes the versioning and release process of the Webauthn Framework. +This document is a living document, contents will be updated according to each release. + +## Releases + +Webauthn Framework releases will be versioned using dotted triples, similar to [Semantic Version](http://semver.org/). +For this specific document, we will refer to the respective components of this triple as `..`. +The version number may have additional information, such as "-rc1,-rc2,-rc3" to mark release candidate builds for earlier access. +Such releases will be considered as "pre-releases". + +## Minor Release Support Matrix + +| Version | Supported | +|---------|--------------------| +| 3.2.x | :white_check_mark: | +| < 3.2.x | :x: | diff --git a/spomky-labs/cbor-php/src/AbstractCBORObject.php b/spomky-labs/cbor-php/src/AbstractCBORObject.php index 0e0351d64..2fbd96ddb 100644 --- a/spomky-labs/cbor-php/src/AbstractCBORObject.php +++ b/spomky-labs/cbor-php/src/AbstractCBORObject.php @@ -4,10 +4,9 @@ namespace CBOR; -use Stringable; use function chr; -abstract class AbstractCBORObject implements CBORObject, Stringable +abstract class AbstractCBORObject implements CBORObject { public function __construct( private int $majorType, diff --git a/spomky-labs/cbor-php/src/ByteStringObject.php b/spomky-labs/cbor-php/src/ByteStringObject.php index b7bb01fd9..ab271187d 100644 --- a/spomky-labs/cbor-php/src/ByteStringObject.php +++ b/spomky-labs/cbor-php/src/ByteStringObject.php @@ -4,6 +4,8 @@ namespace CBOR; +use function strlen; + /** * @see \CBOR\Test\ByteStringObjectTest */ @@ -13,7 +15,7 @@ final class ByteStringObject extends AbstractCBORObject implements Normalizable private string $value; - private ?string $length = null; + private ?string $length; public function __construct(string $data) { @@ -27,9 +29,7 @@ public function __construct(string $data) public function __toString(): string { $result = parent::__toString(); - if ($this->length !== null) { - $result .= $this->length; - } + $result .= $this->length ?? ''; return $result . $this->value; } @@ -46,7 +46,7 @@ public function getValue(): string public function getLength(): int { - return mb_strlen($this->value, '8bit'); + return strlen($this->value); } public function normalize(): string diff --git a/spomky-labs/cbor-php/src/CBORObject.php b/spomky-labs/cbor-php/src/CBORObject.php index 2da9f8ae1..816b86a60 100644 --- a/spomky-labs/cbor-php/src/CBORObject.php +++ b/spomky-labs/cbor-php/src/CBORObject.php @@ -4,7 +4,9 @@ namespace CBOR; -interface CBORObject +use Stringable; + +interface CBORObject extends Stringable { public const MAJOR_TYPE_UNSIGNED_INTEGER = 0b000; @@ -86,8 +88,6 @@ interface CBORObject public const TAG_CBOR = 55799; - public function __toString(): string; - public function getMajorType(): int; public function getAdditionalInformation(): int; diff --git a/spomky-labs/cbor-php/src/Decoder.php b/spomky-labs/cbor-php/src/Decoder.php index 67e98f7ec..c0c0de97a 100644 --- a/spomky-labs/cbor-php/src/Decoder.php +++ b/spomky-labs/cbor-php/src/Decoder.php @@ -35,6 +35,7 @@ use InvalidArgumentException; use RuntimeException; use function ord; +use function sprintf; use const STR_PAD_LEFT; final class Decoder implements DecoderInterface @@ -150,7 +151,7 @@ private function processInfinite(Stream $stream, int $mt, bool $breakable): CBOR } return $object; - case CBORObject::MAJOR_TYPE_TEXT_STRING : //3 + case CBORObject::MAJOR_TYPE_TEXT_STRING: //3 $object = IndefiniteLengthTextStringObject::create(); while (! ($it = $this->process($stream, true)) instanceof BreakObject) { if (! $it instanceof TextStringObject) { @@ -162,7 +163,7 @@ private function processInfinite(Stream $stream, int $mt, bool $breakable): CBOR } return $object; - case CBORObject::MAJOR_TYPE_LIST : //4 + case CBORObject::MAJOR_TYPE_LIST: //4 $object = IndefiniteLengthListObject::create(); $it = $this->process($stream, true); while (! $it instanceof BreakObject) { @@ -171,23 +172,23 @@ private function processInfinite(Stream $stream, int $mt, bool $breakable): CBOR } return $object; - case CBORObject::MAJOR_TYPE_MAP : //5 + case CBORObject::MAJOR_TYPE_MAP: //5 $object = IndefiniteLengthMapObject::create(); while (! ($it = $this->process($stream, true)) instanceof BreakObject) { $object->add($it, $this->process($stream, false)); } return $object; - case CBORObject::MAJOR_TYPE_OTHER_TYPE : //7 + case CBORObject::MAJOR_TYPE_OTHER_TYPE: //7 if (! $breakable) { throw new InvalidArgumentException('Cannot parse the data. No enclosing indefinite.'); } return BreakObject::create(); - case CBORObject::MAJOR_TYPE_UNSIGNED_INTEGER : //0 - case CBORObject::MAJOR_TYPE_NEGATIVE_INTEGER : //1 - case CBORObject::MAJOR_TYPE_TAG : //6 - default : + case CBORObject::MAJOR_TYPE_UNSIGNED_INTEGER: //0 + case CBORObject::MAJOR_TYPE_NEGATIVE_INTEGER: //1 + case CBORObject::MAJOR_TYPE_TAG: //6 + default: throw new InvalidArgumentException(sprintf( 'Cannot parse the data. Found infinite length for Major Type "%s" (%d).', str_pad(decbin($mt), 5, '0', STR_PAD_LEFT), @@ -198,28 +199,28 @@ private function processInfinite(Stream $stream, int $mt, bool $breakable): CBOR private function generateTagManager(): TagManagerInterface { - return TagManager::create() - ->add(DatetimeTag::class) - ->add(TimestampTag::class) + return TagManager::create([ + DatetimeTag::class, + TimestampTag::class, - ->add(UnsignedBigIntegerTag::class) - ->add(NegativeBigIntegerTag::class) + UnsignedBigIntegerTag::class, + NegativeBigIntegerTag::class, - ->add(DecimalFractionTag::class) - ->add(BigFloatTag::class) + DecimalFractionTag::class, + BigFloatTag::class, - ->add(Base64UrlEncodingTag::class) - ->add(Base64EncodingTag::class) - ->add(Base16EncodingTag::class) - ->add(CBOREncodingTag::class) + Base64UrlEncodingTag::class, + Base64EncodingTag::class, + Base16EncodingTag::class, + CBOREncodingTag::class, - ->add(UriTag::class) - ->add(Base64UrlTag::class) - ->add(Base64Tag::class) - ->add(MimeTag::class) + UriTag::class, + Base64UrlTag::class, + Base64Tag::class, + MimeTag::class, - ->add(CBORTag::class) - ; + CBORTag::class, + ]); } private function generateOtherObjectManager(): OtherObjectManagerInterface diff --git a/spomky-labs/cbor-php/src/Encoder.php b/spomky-labs/cbor-php/src/Encoder.php new file mode 100644 index 000000000..d8ed60eb2 --- /dev/null +++ b/spomky-labs/cbor-php/src/Encoder.php @@ -0,0 +1,117 @@ +processData($data, $options); + } + + private function processData(mixed $data, int $option): CBORObject + { + return match (true) { + $data instanceof CBORObject => $data, + is_string($data) => preg_match('//u', $data) === 1 ? $this->processTextString( + $data, + $option + ) : $this->processByteString($data, $option), + is_array($data) => array_is_list($data) ? $this->processList($data, $option) : $this->processMap( + $data, + $option + ), + is_int($data) => $data < 0 ? NegativeIntegerObject::create($data) : UnsignedIntegerObject::create($data), + is_float($data) => $this->processFloat($data, $option), + $data === null => NullObject::create(), + $data === false => FalseObject::create(), + $data === true => TrueObject::create(), + default => throw new InvalidArgumentException('Unsupported data type'), + }; + } + + /** + * @param array $data + */ + private function processList(array $data, int $option): ListObject|IndefiniteLengthListObject + { + $isIndefinite = 0 !== ($option & self::INDEFINITE_LIST_LENGTH); + $list = $isIndefinite ? IndefiniteLengthListObject::create() : ListObject::create(); + foreach ($data as $item) { + $list->add($this->processData($item, $option)); + } + + return $list; + } + + /** + * @param array $data + */ + private function processMap(array $data, int $option): MapObject|IndefiniteLengthMapObject + { + $isIndefinite = 0 !== ($option & self::INDEFINITE_MAP_LENGTH); + $map = $isIndefinite ? IndefiniteLengthMapObject::create() : MapObject::create(); + foreach ($data as $key => $value) { + $map->add($this->processData($key, $option), $this->processData($value, $option)); + } + + return $map; + } + + private function processFloat(float $data, int $option): SinglePrecisionFloatObject|DoublePrecisionFloatObject + { + $isSinglePrecisionFloat = 0 !== ($option & self::FLOAT_FORMAT_SINGLE_PRECISION); + + return match (true) { + $isSinglePrecisionFloat => SinglePrecisionFloatObject::createFromFloat($data), + default => DoublePrecisionFloatObject::createFromFloat($data), + }; + } + + private function processTextString(string $data, int $option): TextStringObject|IndefiniteLengthTextStringObject + { + $isIndefinite = 0 !== ($option & self::INDEFINITE_TEXT_STRING_LENGTH); + $cbor = TextStringObject::create($data); + + if (! $isIndefinite) { + return $cbor; + } + + return IndefiniteLengthTextStringObject::create()->add($cbor); + } + + private function processByteString(string $data, int $option): ByteStringObject|IndefiniteLengthByteStringObject + { + $isIndefinite = 0 !== ($option & self::INDEFINITE_BYTE_STRING_LENGTH); + $cbor = ByteStringObject::create($data); + + if (! $isIndefinite) { + return $cbor; + } + + return IndefiniteLengthByteStringObject::create()->add($cbor); + } +} diff --git a/spomky-labs/cbor-php/src/EncoderInterface.php b/spomky-labs/cbor-php/src/EncoderInterface.php new file mode 100644 index 000000000..f9c18ee9a --- /dev/null +++ b/spomky-labs/cbor-php/src/EncoderInterface.php @@ -0,0 +1,10 @@ +chunks as $chunk) { - $result .= $chunk->__toString(); + $result .= (string) $chunk; } return $result . "\xFF"; } - public static function create(): self + public static function create(string ...$chunks): self { - return new self(); + $object = new self(); + foreach ($chunks as $chunk) { + $object->append($chunk); + } + + return $object; } public function add(ByteStringObject $chunk): self diff --git a/spomky-labs/cbor-php/src/IndefiniteLengthListObject.php b/spomky-labs/cbor-php/src/IndefiniteLengthListObject.php index e1bef93e6..480d94a9d 100644 --- a/spomky-labs/cbor-php/src/IndefiniteLengthListObject.php +++ b/spomky-labs/cbor-php/src/IndefiniteLengthListObject.php @@ -42,9 +42,14 @@ public function __toString(): string return $result . "\xFF"; } - public static function create(): self + public static function create(CBORObject ...$items): self { - return new self(); + $object = new self(); + foreach ($items as $item) { + $object->add($item); + } + + return $object; } /** diff --git a/spomky-labs/cbor-php/src/IndefiniteLengthTextStringObject.php b/spomky-labs/cbor-php/src/IndefiniteLengthTextStringObject.php index bc3a15da9..ccb6d7830 100644 --- a/spomky-labs/cbor-php/src/IndefiniteLengthTextStringObject.php +++ b/spomky-labs/cbor-php/src/IndefiniteLengthTextStringObject.php @@ -33,9 +33,14 @@ public function __toString(): string return $result . "\xFF"; } - public static function create(): self + public static function create(string ...$chunks): self { - return new self(); + $object = new self(); + foreach ($chunks as $chunk) { + $object->append($chunk); + } + + return $object; } public function add(TextStringObject $chunk): self diff --git a/spomky-labs/cbor-php/src/LengthCalculator.php b/spomky-labs/cbor-php/src/LengthCalculator.php index ec8c678c5..da43ce8db 100644 --- a/spomky-labs/cbor-php/src/LengthCalculator.php +++ b/spomky-labs/cbor-php/src/LengthCalculator.php @@ -8,6 +8,7 @@ use InvalidArgumentException; use function chr; use function count; +use function strlen; use const STR_PAD_LEFT; final class LengthCalculator @@ -17,7 +18,7 @@ final class LengthCalculator */ public static function getLengthOfString(string $data): array { - $length = mb_strlen($data, '8bit'); + $length = strlen($data); return self::computeLength($length); } @@ -54,7 +55,7 @@ private static function computeLength(int $length): array private static function hex2bin(string $data): string { - $data = str_pad($data, (int) (2 ** ceil(log(mb_strlen($data, '8bit'), 2))), '0', STR_PAD_LEFT); + $data = str_pad($data, (int) (2 ** ceil(log(strlen($data), 2))), '0', STR_PAD_LEFT); $result = hex2bin($data); if ($result === false) { throw new InvalidArgumentException('Unable to convert the data'); diff --git a/spomky-labs/cbor-php/src/ListObject.php b/spomky-labs/cbor-php/src/ListObject.php index 4f8da7260..06f7f26e9 100644 --- a/spomky-labs/cbor-php/src/ListObject.php +++ b/spomky-labs/cbor-php/src/ListObject.php @@ -46,9 +46,7 @@ public function __construct(array $data = []) public function __toString(): string { $result = parent::__toString(); - if ($this->length !== null) { - $result .= $this->length; - } + $result .= $this->length ?? ''; foreach ($this->data as $object) { $result .= (string) $object; } diff --git a/spomky-labs/cbor-php/src/MapObject.php b/spomky-labs/cbor-php/src/MapObject.php index 72a7431fa..a7c11397c 100644 --- a/spomky-labs/cbor-php/src/MapObject.php +++ b/spomky-labs/cbor-php/src/MapObject.php @@ -26,7 +26,7 @@ final class MapObject extends AbstractCBORObject implements Countable, IteratorA */ private array $data; - private ?string $length = null; + private ?string $length; /** * @param MapItem[] $data @@ -34,12 +34,6 @@ final class MapObject extends AbstractCBORObject implements Countable, IteratorA public function __construct(array $data = []) { [$additionalInformation, $length] = LengthCalculator::getLengthOfArray($data); - array_map(static function ($item): void { - if (! $item instanceof MapItem) { - throw new InvalidArgumentException('The list must contain only MapItem objects.'); - } - }, $data); - parent::__construct(self::MAJOR_TYPE, $additionalInformation); $this->data = $data; $this->length = $length; @@ -48,16 +42,10 @@ public function __construct(array $data = []) public function __toString(): string { $result = parent::__toString(); - if ($this->length !== null) { - $result .= $this->length; - } + $result .= $this->length ?? ''; foreach ($this->data as $object) { - $result .= $object->getKey() - ->__toString() - ; - $result .= $object->getValue() - ->__toString() - ; + $result .= (string) $object->getKey(); + $result .= (string) $object->getValue(); } return $result; diff --git a/spomky-labs/cbor-php/src/NegativeIntegerObject.php b/spomky-labs/cbor-php/src/NegativeIntegerObject.php index 93c0ee708..26caecc8c 100644 --- a/spomky-labs/cbor-php/src/NegativeIntegerObject.php +++ b/spomky-labs/cbor-php/src/NegativeIntegerObject.php @@ -46,6 +46,9 @@ public static function createFromString(string $value): self return self::createBigInteger($integer); } + /** + * @return numeric-string + */ public function getValue(): string { if ($this->data === null) { @@ -60,6 +63,9 @@ public function getValue(): string ; } + /** + * @return numeric-string + */ public function normalize(): string { return $this->getValue(); diff --git a/spomky-labs/cbor-php/src/OtherObject/DoublePrecisionFloatObject.php b/spomky-labs/cbor-php/src/OtherObject/DoublePrecisionFloatObject.php index db3a1d2f6..230174628 100644 --- a/spomky-labs/cbor-php/src/OtherObject/DoublePrecisionFloatObject.php +++ b/spomky-labs/cbor-php/src/OtherObject/DoublePrecisionFloatObject.php @@ -9,6 +9,7 @@ use CBOR\OtherObject as Base; use CBOR\Utils; use InvalidArgumentException; +use function strlen; use const INF; use const NAN; @@ -19,6 +20,21 @@ public static function supportedAdditionalInformation(): array return [self::OBJECT_DOUBLE_PRECISION_FLOAT]; } + public static function createFromFloat(float $number): self + { + $value = match (true) { + is_nan($number) => hex2bin('7FF8000000000000'), + is_infinite($number) && $number > 0 => hex2bin('7FF0000000000000'), + is_infinite($number) && $number < 0 => hex2bin('FFF0000000000000'), + default => (fn (): string => unpack('S', "\x01\x00")[1] === 1 ? strrev(pack('d', $number)) : pack( + 'd', + $number + ))(), + }; + + return new self(self::OBJECT_DOUBLE_PRECISION_FLOAT, $value); + } + public static function createFromLoadedData(int $additionalInformation, ?string $data): Base { return new self($additionalInformation, $data); @@ -26,7 +42,7 @@ public static function createFromLoadedData(int $additionalInformation, ?string public static function create(string $value): self { - if (mb_strlen($value, '8bit') !== 8) { + if (strlen($value) !== 8) { throw new InvalidArgumentException('The value is not a valid double precision floating point'); } diff --git a/spomky-labs/cbor-php/src/OtherObject/HalfPrecisionFloatObject.php b/spomky-labs/cbor-php/src/OtherObject/HalfPrecisionFloatObject.php index 467e0c292..ba114b9d6 100644 --- a/spomky-labs/cbor-php/src/OtherObject/HalfPrecisionFloatObject.php +++ b/spomky-labs/cbor-php/src/OtherObject/HalfPrecisionFloatObject.php @@ -9,6 +9,7 @@ use CBOR\OtherObject as Base; use CBOR\Utils; use InvalidArgumentException; +use function strlen; use const INF; use const NAN; @@ -26,7 +27,7 @@ public static function createFromLoadedData(int $additionalInformation, ?string public static function create(string $value): self { - if (mb_strlen($value, '8bit') !== 2) { + if (strlen($value) !== 2) { throw new InvalidArgumentException('The value is not a valid half precision floating point'); } diff --git a/spomky-labs/cbor-php/src/OtherObject/OtherObjectManager.php b/spomky-labs/cbor-php/src/OtherObject/OtherObjectManager.php index e691c3dd2..ababcbbb7 100644 --- a/spomky-labs/cbor-php/src/OtherObject/OtherObjectManager.php +++ b/spomky-labs/cbor-php/src/OtherObject/OtherObjectManager.php @@ -4,22 +4,30 @@ namespace CBOR\OtherObject; -use CBOR\OtherObject; use InvalidArgumentException; use function array_key_exists; -class OtherObjectManager implements OtherObjectManagerInterface +final class OtherObjectManager implements OtherObjectManagerInterface { /** - * @var string[] + * @param class-string[] $classes */ - private array $classes = []; + public function __construct( + private array $classes = [], + ) { + } - public static function create(): self + /** + * @param class-string[] $classes + */ + public static function create(array $classes = []): self { - return new self(); + return new self($classes); } + /** + * @param class-string $class + */ public function add(string $class): self { foreach ($class::supportedAdditionalInformation() as $ai) { @@ -32,6 +40,9 @@ public function add(string $class): self return $this; } + /** + * @return class-string + */ public function getClassForValue(int $value): string { return array_key_exists($value, $this->classes) ? $this->classes[$value] : GenericObject::class; @@ -39,7 +50,6 @@ public function getClassForValue(int $value): string public function createObjectForValue(int $value, ?string $data): OtherObjectInterface { - /** @var OtherObject $class */ $class = $this->getClassForValue($value); return $class::createFromLoadedData($value, $data); diff --git a/spomky-labs/cbor-php/src/OtherObject/SimpleObject.php b/spomky-labs/cbor-php/src/OtherObject/SimpleObject.php index 702542f22..f43a6910a 100644 --- a/spomky-labs/cbor-php/src/OtherObject/SimpleObject.php +++ b/spomky-labs/cbor-php/src/OtherObject/SimpleObject.php @@ -10,12 +10,13 @@ use InvalidArgumentException; use function chr; use function ord; +use function strlen; final class SimpleObject extends Base implements Normalizable { public static function supportedAdditionalInformation(): array { - return array_merge(range(0, 19), [24]); + return [...range(0, 19), 24]; } public static function create(int $value): self|FalseObject|TrueObject|NullObject|UndefinedObject @@ -46,7 +47,7 @@ public static function createFromLoadedData(int $additionalInformation, ?string if ($data === null) { throw new InvalidArgumentException('Invalid simple value. Content data is missing.'); } - if (mb_strlen($data, '8bit') !== 1) { + if (strlen($data) !== 1) { throw new InvalidArgumentException('Invalid simple value. Content data is too long.'); } if (ord($data) < 32) { diff --git a/spomky-labs/cbor-php/src/OtherObject/SinglePrecisionFloatObject.php b/spomky-labs/cbor-php/src/OtherObject/SinglePrecisionFloatObject.php index d47cd3095..72e9da363 100644 --- a/spomky-labs/cbor-php/src/OtherObject/SinglePrecisionFloatObject.php +++ b/spomky-labs/cbor-php/src/OtherObject/SinglePrecisionFloatObject.php @@ -8,6 +8,7 @@ use CBOR\OtherObject as Base; use CBOR\Utils; use InvalidArgumentException; +use function strlen; use const INF; use const NAN; @@ -18,6 +19,21 @@ public static function supportedAdditionalInformation(): array return [self::OBJECT_SINGLE_PRECISION_FLOAT]; } + public static function createFromFloat(float $number): self + { + $value = match (true) { + is_nan($number) => hex2bin('7FC00000'), + is_infinite($number) && $number > 0 => hex2bin('7F800000'), + is_infinite($number) && $number < 0 => hex2bin('FF800000'), + default => (fn (): string => unpack('S', "\x01\x00")[1] === 1 ? strrev(pack('f', $number)) : pack( + 'f', + $number + ))(), + }; + + return new self(self::OBJECT_SINGLE_PRECISION_FLOAT, $value); + } + public static function createFromLoadedData(int $additionalInformation, ?string $data): Base { return new self($additionalInformation, $data); @@ -25,7 +41,7 @@ public static function createFromLoadedData(int $additionalInformation, ?string public static function create(string $value): self { - if (mb_strlen($value, '8bit') !== 4) { + if (strlen($value) !== 4) { throw new InvalidArgumentException('The value is not a valid single precision floating point'); } diff --git a/spomky-labs/cbor-php/src/StringStream.php b/spomky-labs/cbor-php/src/StringStream.php index d522813a2..a6858e099 100644 --- a/spomky-labs/cbor-php/src/StringStream.php +++ b/spomky-labs/cbor-php/src/StringStream.php @@ -6,6 +6,8 @@ use InvalidArgumentException; use RuntimeException; +use function sprintf; +use function strlen; final class StringStream implements Stream { @@ -53,21 +55,21 @@ public function read(int $length): string if ($newData === false) { throw new RuntimeException('Unable to read the memory'); } - if (mb_strlen($newData, '8bit') < $sizeToRead) { + if (strlen($newData) < $sizeToRead) { throw new InvalidArgumentException(sprintf( 'Out of range. Expected: %d, read: %d.', $length, - mb_strlen($data, '8bit') + strlen($data) )); } $data .= $newData; } - if (mb_strlen($data, '8bit') !== $length) { + if (strlen($data) !== $length) { throw new InvalidArgumentException(sprintf( 'Out of range. Expected: %d, read: %d.', $length, - mb_strlen($data, '8bit') + strlen($data) )); } diff --git a/spomky-labs/cbor-php/src/Tag/BigFloatTag.php b/spomky-labs/cbor-php/src/Tag/BigFloatTag.php index 1de2cbe76..088fba6f8 100644 --- a/spomky-labs/cbor-php/src/Tag/BigFloatTag.php +++ b/spomky-labs/cbor-php/src/Tag/BigFloatTag.php @@ -78,6 +78,6 @@ public function normalize() /** @var UnsignedIntegerObject|NegativeIntegerObject|NegativeBigIntegerTag|UnsignedBigIntegerTag $m */ $m = $object->get(1); - return rtrim(bcmul($m->normalize(), bcpow('2', $e->normalize(), 100), 100), '0'); + return rtrim(bcmul((string) $m->normalize(), bcpow('2', (string) $e->normalize(), 100), 100), '0'); } } diff --git a/spomky-labs/cbor-php/src/Tag/DecimalFractionTag.php b/spomky-labs/cbor-php/src/Tag/DecimalFractionTag.php index 9eafd2532..27980e9ab 100644 --- a/spomky-labs/cbor-php/src/Tag/DecimalFractionTag.php +++ b/spomky-labs/cbor-php/src/Tag/DecimalFractionTag.php @@ -77,6 +77,6 @@ public function normalize() /** @var UnsignedIntegerObject|NegativeIntegerObject|NegativeBigIntegerTag|UnsignedBigIntegerTag $m */ $m = $object->get(1); - return rtrim(bcmul($m->normalize(), bcpow('10', $e->normalize(), 100), 100), '0'); + return rtrim(bcmul((string) $m->normalize(), bcpow('10', (string) $e->normalize(), 100), 100), '0'); } } diff --git a/spomky-labs/cbor-php/src/Tag/TagManager.php b/spomky-labs/cbor-php/src/Tag/TagManager.php index 0d3eb6d8f..40c0a8c96 100644 --- a/spomky-labs/cbor-php/src/Tag/TagManager.php +++ b/spomky-labs/cbor-php/src/Tag/TagManager.php @@ -5,7 +5,6 @@ namespace CBOR\Tag; use CBOR\CBORObject; -use CBOR\Tag; use CBOR\Utils; use InvalidArgumentException; use function array_key_exists; @@ -13,15 +12,24 @@ final class TagManager implements TagManagerInterface { /** - * @var string[] + * @param class-string[] $classes */ - private array $classes = []; + public function __construct( + private array $classes = [] + ) { + } - public static function create(): self + /** + * @param array> $classes + */ + public static function create(array $classes = []): self { - return new self(); + return new self($classes); } + /** + * @param class-string $class + */ public function add(string $class): self { if ($class::getTagId() < 0) { @@ -32,6 +40,9 @@ public function add(string $class): self return $this; } + /** + * @return class-string + */ public function getClassForValue(int $value): string { return array_key_exists($value, $this->classes) ? $this->classes[$value] : GenericTag::class; @@ -44,7 +55,6 @@ public function createObjectForValue(int $additionalInformation, ?string $data, Utils::assertString($data, 'Invalid data'); $value = Utils::binToInt($data); } - /** @var Tag $class */ $class = $this->getClassForValue($value); return $class::createFromLoadedData($additionalInformation, $data, $object); diff --git a/spomky-labs/cbor-php/src/Tag/TimestampTag.php b/spomky-labs/cbor-php/src/Tag/TimestampTag.php index afdec9fdf..a3b457e9a 100644 --- a/spomky-labs/cbor-php/src/Tag/TimestampTag.php +++ b/spomky-labs/cbor-php/src/Tag/TimestampTag.php @@ -15,6 +15,7 @@ use DateTimeImmutable; use DateTimeInterface; use InvalidArgumentException; +use function strlen; use const STR_PAD_RIGHT; final class TimestampTag extends Tag implements Normalizable @@ -60,8 +61,8 @@ public function normalize(): DateTimeInterface $value = (string) $object->normalize(); $parts = explode('.', $value); if (isset($parts[1])) { - if (mb_strlen($parts[1], '8bit') > 6) { - $parts[1] = mb_substr($parts[1], 0, 6, '8bit'); + if (strlen($parts[1]) > 6) { + $parts[1] = substr($parts[1], 0, 6); } else { $parts[1] = str_pad($parts[1], 6, '0', STR_PAD_RIGHT); } diff --git a/spomky-labs/cbor-php/src/TextStringObject.php b/spomky-labs/cbor-php/src/TextStringObject.php index a0ca87a57..08f77e44b 100644 --- a/spomky-labs/cbor-php/src/TextStringObject.php +++ b/spomky-labs/cbor-php/src/TextStringObject.php @@ -27,9 +27,7 @@ public function __construct(string $data) public function __toString(): string { $result = parent::__toString(); - if ($this->length !== null) { - $result .= $this->length; - } + $result .= $this->length ?? ''; return $result . $this->data; } diff --git a/spomky-labs/cbor-php/src/UnsignedIntegerObject.php b/spomky-labs/cbor-php/src/UnsignedIntegerObject.php index 348333442..a7ef1577f 100644 --- a/spomky-labs/cbor-php/src/UnsignedIntegerObject.php +++ b/spomky-labs/cbor-php/src/UnsignedIntegerObject.php @@ -58,17 +58,21 @@ public function getMajorType(): int return self::MAJOR_TYPE; } + /** + * @return numeric-string + */ public function getValue(): string { if ($this->data === null) { return (string) $this->additionalInformation; } - $integer = BigInteger::fromBase(bin2hex($this->data), 16); - - return $integer->toBase(10); + return BigInteger::fromBase(bin2hex($this->data), 16)->toBase(10); } + /** + * @return numeric-string + */ public function normalize(): string { return $this->getValue(); diff --git a/spomky-labs/pki-framework/src/ASN1/Component/Identifier.php b/spomky-labs/pki-framework/src/ASN1/Component/Identifier.php index c2f15492d..dc21d7948 100644 --- a/spomky-labs/pki-framework/src/ASN1/Component/Identifier.php +++ b/spomky-labs/pki-framework/src/ASN1/Component/Identifier.php @@ -87,7 +87,7 @@ public static function create(int $class, int $pc, BigInteger|int $tag): self * Variable is updated to the offset next to the * parsed identifier. If null, start from offset 0. */ - public static function fromDER(string $data, int &$offset = null): self + public static function fromDER(string $data, ?int &$offset = null): self { $idx = $offset ?? 0; $datalen = mb_strlen($data, '8bit'); diff --git a/spomky-labs/pki-framework/src/ASN1/Component/Length.php b/spomky-labs/pki-framework/src/ASN1/Component/Length.php index feb5ab311..e69e92daa 100644 --- a/spomky-labs/pki-framework/src/ASN1/Component/Length.php +++ b/spomky-labs/pki-framework/src/ASN1/Component/Length.php @@ -13,6 +13,7 @@ use function count; use function mb_strlen; use function ord; +use function sprintf; /** * Class to represent BER/DER length octets. @@ -49,7 +50,7 @@ public static function create(BigInteger|int $length, bool $_indefinite = false) * Variable is updated to the offset next to the * parsed length component. If null, start from offset 0. */ - public static function fromDER(string $data, int &$offset = null): self + public static function fromDER(string $data, ?int &$offset = null): self { $idx = $offset ?? 0; $datalen = mb_strlen($data, '8bit'); @@ -89,7 +90,7 @@ public static function fromDER(string $data, int &$offset = null): self * @param null|int $expected Expected length, null to bypass checking * @see self::fromDER */ - public static function expectFromDER(string $data, int &$offset, int $expected = null): self + public static function expectFromDER(string $data, int &$offset, ?int $expected = null): self { $idx = $offset; $length = self::fromDER($data, $idx); diff --git a/spomky-labs/pki-framework/src/ASN1/Element.php b/spomky-labs/pki-framework/src/ASN1/Element.php index 3d05aaa88..fa7795c00 100644 --- a/spomky-labs/pki-framework/src/ASN1/Element.php +++ b/spomky-labs/pki-framework/src/ASN1/Element.php @@ -46,6 +46,7 @@ use UnexpectedValueException; use function array_key_exists; use function mb_strlen; +use function sprintf; /** * Base class for all ASN.1 type elements. @@ -240,7 +241,7 @@ abstract public function isConstructed(): bool; * Variable is updated to the offset next to the * parsed element. If null, start from offset 0. */ - public static function fromDER(string $data, int &$offset = null): static + public static function fromDER(string $data, ?int &$offset = null): static { $idx = $offset ?? 0; // decode identifier diff --git a/spomky-labs/pki-framework/src/ASN1/Type/BaseString.php b/spomky-labs/pki-framework/src/ASN1/Type/BaseString.php index 34cae98ba..b777e8a08 100644 --- a/spomky-labs/pki-framework/src/ASN1/Type/BaseString.php +++ b/spomky-labs/pki-framework/src/ASN1/Type/BaseString.php @@ -7,6 +7,7 @@ use InvalidArgumentException; use SpomkyLabs\Pki\ASN1\Element; use Stringable; +use function sprintf; /** * Base class for all string types. diff --git a/spomky-labs/pki-framework/src/ASN1/Type/Primitive/GeneralizedTime.php b/spomky-labs/pki-framework/src/ASN1/Type/Primitive/GeneralizedTime.php index 62de771da..07adb8174 100644 --- a/spomky-labs/pki-framework/src/ASN1/Type/Primitive/GeneralizedTime.php +++ b/spomky-labs/pki-framework/src/ASN1/Type/Primitive/GeneralizedTime.php @@ -34,15 +34,15 @@ final class GeneralizedTime extends BaseTime * @var string */ final public const REGEX = '#^' . - '(\d\d\d\d)' . // YYYY - '(\d\d)' . // MM - '(\d\d)' . // DD - '(\d\d)' . // hh - '(\d\d)' . // mm - '(\d\d)' . // ss - '(?:\.(\d+))?' . // frac - 'Z' . // TZ - '$#'; + '(\d\d\d\d)' . // YYYY + '(\d\d)' . // MM + '(\d\d)' . // DD + '(\d\d)' . // hh + '(\d\d)' . // mm + '(\d\d)' . // ss + '(?:\.(\d+))?' . // frac + 'Z' . // TZ + '$#'; /** * Cached formatted date. diff --git a/spomky-labs/pki-framework/src/ASN1/Type/Primitive/Number.php b/spomky-labs/pki-framework/src/ASN1/Type/Primitive/Number.php index bbf5ed2d8..8fe2afc7a 100644 --- a/spomky-labs/pki-framework/src/ASN1/Type/Primitive/Number.php +++ b/spomky-labs/pki-framework/src/ASN1/Type/Primitive/Number.php @@ -14,6 +14,7 @@ use function is_int; use function is_scalar; use function is_string; +use function sprintf; use function strval; abstract class Number extends Element diff --git a/spomky-labs/pki-framework/src/ASN1/Type/Primitive/ObjectIdentifier.php b/spomky-labs/pki-framework/src/ASN1/Type/Primitive/ObjectIdentifier.php index 207842a61..3a4c003f0 100644 --- a/spomky-labs/pki-framework/src/ASN1/Type/Primitive/ObjectIdentifier.php +++ b/spomky-labs/pki-framework/src/ASN1/Type/Primitive/ObjectIdentifier.php @@ -20,6 +20,7 @@ use function is_int; use function mb_strlen; use function ord; +use function sprintf; /** * Implements *OBJECT IDENTIFIER* type. diff --git a/spomky-labs/pki-framework/src/ASN1/Type/Primitive/Real.php b/spomky-labs/pki-framework/src/ASN1/Type/Primitive/Real.php index 725692aaf..cbc7c4356 100644 --- a/spomky-labs/pki-framework/src/ASN1/Type/Primitive/Real.php +++ b/spomky-labs/pki-framework/src/ASN1/Type/Primitive/Real.php @@ -22,6 +22,7 @@ use function in_array; use function mb_strlen; use function ord; +use function sprintf; use const INF; /** @@ -38,9 +39,9 @@ final class Real extends Element implements Stringable * @var string */ final public const NR1_REGEX = '/^\s*' . - '(?[+\-])?' . // sign - '(?\d+)' . // integer - '$/'; + '(?[+\-])?' . // sign + '(?\d+)' . // integer + '$/'; /** * Regex pattern to parse NR2 form number. @@ -48,9 +49,9 @@ final class Real extends Element implements Stringable * @var string */ final public const NR2_REGEX = '/^\s*' . - '(?[+\-])?' . // sign - '(?(?:\d+[\.,]\d*)|(?:\d*[\.,]\d+))' . // decimal number - '$/'; + '(?[+\-])?' . // sign + '(?(?:\d+[\.,]\d*)|(?:\d*[\.,]\d+))' . // decimal number + '$/'; /** * Regex pattern to parse NR3 form number. @@ -58,11 +59,11 @@ final class Real extends Element implements Stringable * @var string */ final public const NR3_REGEX = '/^\s*' . - '(?[+\-])?' . // mantissa sign - '(?(?:\d+[\.,]\d*)|(?:\d*[\.,]\d+))' . // mantissa - '[Ee](?[+\-])?' . // exponent sign - '(?\d+)' . // exponent - '$/'; + '(?[+\-])?' . // mantissa sign + '(?(?:\d+[\.,]\d*)|(?:\d*[\.,]\d+))' . // mantissa + '[Ee](?[+\-])?' . // exponent sign + '(?\d+)' . // exponent + '$/'; /** * Regex pattern to parse PHP exponent number format. @@ -72,14 +73,14 @@ final class Real extends Element implements Stringable * @var string */ final public const PHP_EXPONENT_DNUM = '/^' . - '(?[+\-])?' . // sign - '(?' . - '\d+' . // LNUM - '|' . - '(?:\d*\.\d+|\d+\.\d*)' . // DNUM - ')[eE]' . - '(?[+\-])?(?\d+)' . // exponent - '$/'; + '(?[+\-])?' . // sign + '(?' . + '\d+' . // LNUM + '|' . + '(?:\d*\.\d+|\d+\.\d*)' . // DNUM + ')[eE]' . + '(?[+\-])?(?\d+)' . // exponent + '$/'; /** * Exponent when value is positive or negative infinite. diff --git a/spomky-labs/pki-framework/src/ASN1/Type/Primitive/RelativeOID.php b/spomky-labs/pki-framework/src/ASN1/Type/Primitive/RelativeOID.php index f09ac6b82..5f308817f 100644 --- a/spomky-labs/pki-framework/src/ASN1/Type/Primitive/RelativeOID.php +++ b/spomky-labs/pki-framework/src/ASN1/Type/Primitive/RelativeOID.php @@ -18,6 +18,7 @@ use function chr; use function is_int; use function ord; +use function sprintf; /** * Implements *RELATIVE-OID* type. diff --git a/spomky-labs/pki-framework/src/ASN1/Type/Primitive/UTCTime.php b/spomky-labs/pki-framework/src/ASN1/Type/Primitive/UTCTime.php index 87e18facf..dd31ba9e3 100644 --- a/spomky-labs/pki-framework/src/ASN1/Type/Primitive/UTCTime.php +++ b/spomky-labs/pki-framework/src/ASN1/Type/Primitive/UTCTime.php @@ -30,14 +30,14 @@ final class UTCTime extends BaseTime * @var string */ final public const REGEX = '#^' . - '(\d\d)' . // YY - '(\d\d)' . // MM - '(\d\d)' . // DD - '(\d\d)' . // hh - '(\d\d)' . // mm - '(\d\d)' . // ss - 'Z' . // TZ - '$#'; + '(\d\d)' . // YY + '(\d\d)' . // MM + '(\d\d)' . // DD + '(\d\d)' . // hh + '(\d\d)' . // mm + '(\d\d)' . // ss + 'Z' . // TZ + '$#'; private function __construct(DateTimeImmutable $dt) { diff --git a/spomky-labs/pki-framework/src/ASN1/Type/Structure.php b/spomky-labs/pki-framework/src/ASN1/Type/Structure.php index e7d5bf374..903899c90 100644 --- a/spomky-labs/pki-framework/src/ASN1/Type/Structure.php +++ b/spomky-labs/pki-framework/src/ASN1/Type/Structure.php @@ -182,10 +182,7 @@ public function withoutElement(int $idx): self public function elements(): array { if (! isset($this->unspecifiedTypes)) { - $this->unspecifiedTypes = array_map( - static fn (Element $el) => UnspecifiedType::create($el), - $this->elements - ); + $this->unspecifiedTypes = array_map(UnspecifiedType::create(...), $this->elements); } return $this->unspecifiedTypes; } diff --git a/spomky-labs/pki-framework/src/ASN1/Type/Tagged/ImplicitlyTaggedType.php b/spomky-labs/pki-framework/src/ASN1/Type/Tagged/ImplicitlyTaggedType.php index 359b6d1b4..38369aa1f 100644 --- a/spomky-labs/pki-framework/src/ASN1/Type/Tagged/ImplicitlyTaggedType.php +++ b/spomky-labs/pki-framework/src/ASN1/Type/Tagged/ImplicitlyTaggedType.php @@ -10,6 +10,7 @@ use SpomkyLabs\Pki\ASN1\Feature\ElementBase; use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType; use UnexpectedValueException; +use function sprintf; /** * Implements implicit tagging mode. diff --git a/spomky-labs/pki-framework/src/ASN1/Type/UnspecifiedType.php b/spomky-labs/pki-framework/src/ASN1/Type/UnspecifiedType.php index 9d7aa18df..3fd310c8d 100644 --- a/spomky-labs/pki-framework/src/ASN1/Type/UnspecifiedType.php +++ b/spomky-labs/pki-framework/src/ASN1/Type/UnspecifiedType.php @@ -37,6 +37,7 @@ use SpomkyLabs\Pki\ASN1\Type\Tagged\ApplicationType; use SpomkyLabs\Pki\ASN1\Type\Tagged\PrivateType; use UnexpectedValueException; +use function sprintf; /** * Decorator class to wrap an element without already knowing the specific underlying type. diff --git a/spomky-labs/pki-framework/src/CryptoBridge/Crypto/OpenSSLCrypto.php b/spomky-labs/pki-framework/src/CryptoBridge/Crypto/OpenSSLCrypto.php index fe47b8f6a..65a5e872d 100644 --- a/spomky-labs/pki-framework/src/CryptoBridge/Crypto/OpenSSLCrypto.php +++ b/spomky-labs/pki-framework/src/CryptoBridge/Crypto/OpenSSLCrypto.php @@ -17,6 +17,7 @@ use UnexpectedValueException; use function array_key_exists; use function mb_strlen; +use function sprintf; use const OPENSSL_ALGO_MD4; use const OPENSSL_ALGO_MD5; use const OPENSSL_ALGO_SHA1; diff --git a/spomky-labs/pki-framework/src/CryptoEncoding/PEM.php b/spomky-labs/pki-framework/src/CryptoEncoding/PEM.php index 3618a01c2..30ff39274 100644 --- a/spomky-labs/pki-framework/src/CryptoEncoding/PEM.php +++ b/spomky-labs/pki-framework/src/CryptoEncoding/PEM.php @@ -47,15 +47,15 @@ final class PEM implements Stringable * @var string */ final public const PEM_REGEX = '/' . - /* line start */ - '(?:^|[\r\n])' . - /* header */ - '-----BEGIN (.+?)-----[\r\n]+' . - /* payload */ - '(.+?)' . - /* trailer */ - '[\r\n]+-----END \\1-----' . - '/ms'; + /* line start */ + '(?:^|[\r\n])' . + /* header */ + '-----BEGIN (.+?)-----[\r\n]+' . + /* payload */ + '(.+?)' . + /* trailer */ + '[\r\n]+-----END \\1-----' . + '/ms'; /** * @param string $type Content type diff --git a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/ECPublicKeyAlgorithmIdentifier.php b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/ECPublicKeyAlgorithmIdentifier.php index 5571f6110..13ae1e3eb 100644 --- a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/ECPublicKeyAlgorithmIdentifier.php +++ b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/ECPublicKeyAlgorithmIdentifier.php @@ -12,16 +12,14 @@ use UnexpectedValueException; /* -From RFC 5480 - 2.1.1. Unrestricted Algorithm Identifier and Parameters: - -The parameter for id-ecPublicKey is as follows and MUST always be -present: - -ECParameters ::= CHOICE { - namedCurve OBJECT IDENTIFIER - -- implicitCurve NULL - -- specifiedCurve SpecifiedECDomain -} + * From RFC 5480 - 2.1.1. Unrestricted Algorithm Identifier and Parameters: + * The parameter for id-ecPublicKey is as follows and MUST always be + * present: + * ECParameters ::= CHOICE { + * namedCurve OBJECT IDENTIFIER + * -- implicitCurve NULL + * -- specifiedCurve SpecifiedECDomain + * } */ /** @@ -284,7 +282,7 @@ public function namedCurve(): string /** * @return ObjectIdentifier */ - protected function paramsASN1(): ?Element + protected function paramsASN1(): Element { return ObjectIdentifier::create($this->namedCurve); } diff --git a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/RFC8410EdAlgorithmIdentifier.php b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/RFC8410EdAlgorithmIdentifier.php index 133f6b99d..3821feab5 100644 --- a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/RFC8410EdAlgorithmIdentifier.php +++ b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/RFC8410EdAlgorithmIdentifier.php @@ -10,16 +10,14 @@ use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\SpecificAlgorithmIdentifier; /* -From RFC 8410: - - For all of the OIDs, the parameters MUST be absent. - - It is possible to find systems that require the parameters to be - present. This can be due to either a defect in the original 1997 - syntax or a programming error where developers never got input where - this was not true. The optimal solution is to fix these systems; - where this is not possible, the problem needs to be restricted to - that subsystem and not propagated to the Internet. + * From RFC 8410: + * For all of the OIDs, the parameters MUST be absent. + * It is possible to find systems that require the parameters to be + * present. This can be due to either a defect in the original 1997 + * syntax or a programming error where developers never got input where + * this was not true. The optimal solution is to fix these systems; + * where this is not possible, the problem needs to be restricted to + * that subsystem and not propagated to the Internet. */ /** diff --git a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/RFC8410XAlgorithmIdentifier.php b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/RFC8410XAlgorithmIdentifier.php index f41bb4583..a3f2a8406 100644 --- a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/RFC8410XAlgorithmIdentifier.php +++ b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/RFC8410XAlgorithmIdentifier.php @@ -9,16 +9,14 @@ use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\SpecificAlgorithmIdentifier; /* -From RFC 8410: - - For all of the OIDs, the parameters MUST be absent. - - It is possible to find systems that require the parameters to be - present. This can be due to either a defect in the original 1997 - syntax or a programming error where developers never got input where - this was not true. The optimal solution is to fix these systems; - where this is not possible, the problem needs to be restricted to - that subsystem and not propagated to the Internet. + * From RFC 8410: + * For all of the OIDs, the parameters MUST be absent. + * It is possible to find systems that require the parameters to be + * present. This can be due to either a defect in the original 1997 + * syntax or a programming error where developers never got input where + * this was not true. The optimal solution is to fix these systems; + * where this is not possible, the problem needs to be restricted to + * that subsystem and not propagated to the Internet. */ /** diff --git a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/RSAEncryptionAlgorithmIdentifier.php b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/RSAEncryptionAlgorithmIdentifier.php index 3e87e889c..9b5eb0fd3 100644 --- a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/RSAEncryptionAlgorithmIdentifier.php +++ b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/RSAEncryptionAlgorithmIdentifier.php @@ -12,10 +12,9 @@ use UnexpectedValueException; /* -From RFC 3447: - - When rsaEncryption is used in an AlgorithmIdentifier the - parameters MUST be present and MUST be NULL. + * From RFC 3447: + * When rsaEncryption is used in an AlgorithmIdentifier the + * parameters MUST be present and MUST be NULL. */ /** @@ -56,7 +55,7 @@ public static function fromASN1Params(?UnspecifiedType $params = null): Specific /** * @return NullType */ - protected function paramsASN1(): ?Element + protected function paramsASN1(): Element { return NullType::create(); } diff --git a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/RSAPSSSSAEncryptionAlgorithmIdentifier.php b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/RSAPSSSSAEncryptionAlgorithmIdentifier.php index 34aebd080..11794dd5b 100644 --- a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/RSAPSSSSAEncryptionAlgorithmIdentifier.php +++ b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/RSAPSSSSAEncryptionAlgorithmIdentifier.php @@ -12,10 +12,9 @@ use UnexpectedValueException; /* -From RFC 3447: - - When rsaEncryption is used in an AlgorithmIdentifier the - parameters MUST be present and MUST be NULL. + * From RFC 3447: + * When rsaEncryption is used in an AlgorithmIdentifier the + * parameters MUST be present and MUST be NULL. */ /** @@ -56,7 +55,7 @@ public static function fromASN1Params(?UnspecifiedType $params = null): Specific /** * @return NullType */ - protected function paramsASN1(): ?Element + protected function paramsASN1(): Element { return NullType::create(); } diff --git a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Cipher/AESCBCAlgorithmIdentifier.php b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Cipher/AESCBCAlgorithmIdentifier.php index f1e9f5ad3..b14322d14 100644 --- a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Cipher/AESCBCAlgorithmIdentifier.php +++ b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Cipher/AESCBCAlgorithmIdentifier.php @@ -8,11 +8,9 @@ use SpomkyLabs\Pki\ASN1\Type\Primitive\OctetString; /* -From RFC 3565 - 4.1. AES Algorithm Identifiers and Parameters: - -The AlgorithmIdentifier parameters field MUST be present, and the parameter field MUST contain a AES-IV: - - AES-IV ::= OCTET STRING (SIZE(16)) + * From RFC 3565 - 4.1. AES Algorithm Identifiers and Parameters: + * The AlgorithmIdentifier parameters field MUST be present, and the parameter field MUST contain a AES-IV: + * AES-IV ::= OCTET STRING (SIZE(16)) */ /** diff --git a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Cipher/DESCBCAlgorithmIdentifier.php b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Cipher/DESCBCAlgorithmIdentifier.php index efd7fbfe1..8dff7fe96 100644 --- a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Cipher/DESCBCAlgorithmIdentifier.php +++ b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Cipher/DESCBCAlgorithmIdentifier.php @@ -12,9 +12,8 @@ use UnexpectedValueException; /* -RFC 2898 defines parameters as follows: - -{OCTET STRING (SIZE(8)) IDENTIFIED BY desCBC} + * RFC 2898 defines parameters as follows: + * {OCTET STRING (SIZE(8)) IDENTIFIED BY desCBC} */ /** @@ -76,7 +75,7 @@ public function ivSize(): int /** * @return OctetString */ - protected function paramsASN1(): ?Element + protected function paramsASN1(): Element { if (! isset($this->initializationVector)) { throw new LogicException('IV not set.'); diff --git a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Cipher/DESEDE3CBCAlgorithmIdentifier.php b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Cipher/DESEDE3CBCAlgorithmIdentifier.php index 705475d7c..ddcb4adfa 100644 --- a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Cipher/DESEDE3CBCAlgorithmIdentifier.php +++ b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Cipher/DESEDE3CBCAlgorithmIdentifier.php @@ -12,9 +12,8 @@ use UnexpectedValueException; /* -RFC 2898 defines parameters as follows: - -{OCTET STRING (SIZE(8)) IDENTIFIED BY des-EDE3-CBC} + * RFC 2898 defines parameters as follows: + * {OCTET STRING (SIZE(8)) IDENTIFIED BY des-EDE3-CBC} */ /** @@ -77,7 +76,7 @@ public function ivSize(): int /** * @return OctetString */ - protected function paramsASN1(): ?Element + protected function paramsASN1(): Element { if (! isset($this->initializationVector)) { throw new LogicException('IV not set.'); diff --git a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Cipher/RC2CBCAlgorithmIdentifier.php b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Cipher/RC2CBCAlgorithmIdentifier.php index d8d1043de..da79cc66f 100644 --- a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Cipher/RC2CBCAlgorithmIdentifier.php +++ b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Cipher/RC2CBCAlgorithmIdentifier.php @@ -14,28 +14,25 @@ use UnexpectedValueException; /* -Parameters may be seen in various forms. This implementation attemts -to take them all into consideration. - -# RFC 2268 - A Description of the RC2(r) Encryption Algorithm -RC2-CBCParameter ::= CHOICE { - iv IV, - params SEQUENCE { - version RC2Version, - iv IV - } -} - -# RFC 2898 - PKCS #5: Password-Based Cryptography Specification Version 2.0 -RC2-CBC-Parameter ::= SEQUENCE { - rc2ParameterVersion INTEGER OPTIONAL, - iv OCTET STRING (SIZE(8)) -} - -# RFC 3370 - Cryptographic Message Syntax (CMS) Algorithms -RC2CBCParameter ::= SEQUENCE { - rc2ParameterVersion INTEGER, - iv OCTET STRING } -- exactly 8 octets + * Parameters may be seen in various forms. This implementation attemts + * to take them all into consideration. + * # RFC 2268 - A Description of the RC2(r) Encryption Algorithm + * RC2-CBCParameter ::= CHOICE { + * iv IV, + * params SEQUENCE { + * version RC2Version, + * iv IV + * } + * } + * # RFC 2898 - PKCS #5: Password-Based Cryptography Specification Version 2.0 + * RC2-CBC-Parameter ::= SEQUENCE { + * rc2ParameterVersion INTEGER OPTIONAL, + * iv OCTET STRING (SIZE(8)) + * } + * # RFC 3370 - Cryptographic Message Syntax (CMS) Algorithms + * RC2CBCParameter ::= SEQUENCE { + * rc2ParameterVersion INTEGER, + * iv OCTET STRING } -- exactly 8 octets */ /** @@ -170,7 +167,7 @@ public function ivSize(): int /** * @return Sequence */ - protected function paramsASN1(): ?Element + protected function paramsASN1(): Element { if ($this->effectiveKeyBits >= 256) { $version = $this->effectiveKeyBits; diff --git a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Hash/HMACWithSHA1AlgorithmIdentifier.php b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Hash/HMACWithSHA1AlgorithmIdentifier.php index 4abf7901f..74a28a022 100644 --- a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Hash/HMACWithSHA1AlgorithmIdentifier.php +++ b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Hash/HMACWithSHA1AlgorithmIdentifier.php @@ -12,10 +12,9 @@ use UnexpectedValueException; /* -Per RFC 2898 this algorithm identifier has no parameters: - -algid-hmacWithSHA1 AlgorithmIdentifier {{PBKDF2-PRFs}} ::= - {algorithm id-hmacWithSHA1, parameters NULL : NULL} + * Per RFC 2898 this algorithm identifier has no parameters: + * algid-hmacWithSHA1 AlgorithmIdentifier {{PBKDF2-PRFs}} ::= + * {algorithm id-hmacWithSHA1, parameters NULL : NULL} */ /** diff --git a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Hash/MD5AlgorithmIdentifier.php b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Hash/MD5AlgorithmIdentifier.php index 94345cf5b..4fae45dd7 100644 --- a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Hash/MD5AlgorithmIdentifier.php +++ b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Hash/MD5AlgorithmIdentifier.php @@ -11,17 +11,14 @@ use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\SpecificAlgorithmIdentifier; /* -From RFC 1321 - 1. Executive Summary - - In the X.509 type AlgorithmIdentifier, the parameters for MD5 - should have type NULL. - -From RFC 3370 - 2.2 MD5 - - The AlgorithmIdentifier parameters field MUST be present, and the - parameters field MUST contain NULL. Implementations MAY accept the - MD5 AlgorithmIdentifiers with absent parameters as well as NULL - parameters. + * From RFC 1321 - 1. Executive Summary + * In the X.509 type AlgorithmIdentifier, the parameters for MD5 + * should have type NULL. + * From RFC 3370 - 2.2 MD5 + * The AlgorithmIdentifier parameters field MUST be present, and the + * parameters field MUST contain NULL. Implementations MAY accept the + * MD5 AlgorithmIdentifiers with absent parameters as well as NULL + * parameters. */ /** diff --git a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Hash/SHA1AlgorithmIdentifier.php b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Hash/SHA1AlgorithmIdentifier.php index 2eec340fc..a079f34a2 100644 --- a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Hash/SHA1AlgorithmIdentifier.php +++ b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Hash/SHA1AlgorithmIdentifier.php @@ -11,14 +11,13 @@ use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\SpecificAlgorithmIdentifier; /* -From RFC 3370 - 2.1 SHA-1 - - The AlgorithmIdentifier parameters field is OPTIONAL. If present, - the parameters field MUST contain a NULL. Implementations MUST - accept SHA-1 AlgorithmIdentifiers with absent parameters. - Implementations MUST accept SHA-1 AlgorithmIdentifiers with NULL - parameters. Implementations SHOULD generate SHA-1 - AlgorithmIdentifiers with absent parameters. + * From RFC 3370 - 2.1 SHA-1 + * The AlgorithmIdentifier parameters field is OPTIONAL. If present, + * the parameters field MUST contain a NULL. Implementations MUST + * accept SHA-1 AlgorithmIdentifiers with absent parameters. + * Implementations MUST accept SHA-1 AlgorithmIdentifiers with NULL + * parameters. Implementations SHOULD generate SHA-1 + * AlgorithmIdentifiers with absent parameters. */ /** diff --git a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Hash/SHA2AlgorithmIdentifier.php b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Hash/SHA2AlgorithmIdentifier.php index 97921416b..679cefb74 100644 --- a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Hash/SHA2AlgorithmIdentifier.php +++ b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Hash/SHA2AlgorithmIdentifier.php @@ -10,13 +10,12 @@ use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\SpecificAlgorithmIdentifier; /* -From RFC 5754 - 2. Message Digest Algorithms - - The AlgorithmIdentifier parameters field is OPTIONAL. - Implementations MUST accept SHA2 AlgorithmIdentifiers with absent - parameters. Implementations MUST accept SHA2 AlgorithmIdentifiers - with NULL parameters. Implementations MUST generate SHA2 - AlgorithmIdentifiers with absent parameters. + * From RFC 5754 - 2. Message Digest Algorithms + * The AlgorithmIdentifier parameters field is OPTIONAL. + * Implementations MUST accept SHA2 AlgorithmIdentifiers with absent + * parameters. Implementations MUST accept SHA2 AlgorithmIdentifiers + * with NULL parameters. Implementations MUST generate SHA2 + * AlgorithmIdentifiers with absent parameters. */ /** diff --git a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Signature/ECSignatureAlgorithmIdentifier.php b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Signature/ECSignatureAlgorithmIdentifier.php index da2ca03c3..6ffe33b46 100644 --- a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Signature/ECSignatureAlgorithmIdentifier.php +++ b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Signature/ECSignatureAlgorithmIdentifier.php @@ -10,12 +10,11 @@ use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\SpecificAlgorithmIdentifier; /* -From RFC 5758 - 3.2. ECDSA Signature Algorithm - - When the ecdsa-with-SHA224, ecdsa-with-SHA256, ecdsa-with-SHA384, or - ecdsa-with-SHA512 algorithm identifier appears in the algorithm field - as an AlgorithmIdentifier, the encoding MUST omit the parameters - field. + * From RFC 5758 - 3.2. ECDSA Signature Algorithm + * When the ecdsa-with-SHA224, ecdsa-with-SHA256, ecdsa-with-SHA384, or + * ecdsa-with-SHA512 algorithm identifier appears in the algorithm field + * as an AlgorithmIdentifier, the encoding MUST omit the parameters + * field. */ /** diff --git a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Signature/RFC3279RSASignatureAlgorithmIdentifier.php b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Signature/RFC3279RSASignatureAlgorithmIdentifier.php index 9200889a4..d717d8c8f 100644 --- a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Signature/RFC3279RSASignatureAlgorithmIdentifier.php +++ b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Signature/RFC3279RSASignatureAlgorithmIdentifier.php @@ -8,11 +8,10 @@ use SpomkyLabs\Pki\ASN1\Type\Primitive\NullType; /* -From RFC 3279 - 2.2.1 RSA Signature Algorithm: - - When any of these three OIDs appears within the ASN.1 type - AlgorithmIdentifier, the parameters component of that type SHALL be - the ASN.1 type NULL. + * From RFC 3279 - 2.2.1 RSA Signature Algorithm: + * When any of these three OIDs appears within the ASN.1 type + * AlgorithmIdentifier, the parameters component of that type SHALL be + * the ASN.1 type NULL. */ /** diff --git a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Signature/RFC4055RSASignatureAlgorithmIdentifier.php b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Signature/RFC4055RSASignatureAlgorithmIdentifier.php index e9ae13bdc..de8abaf7f 100644 --- a/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Signature/RFC4055RSASignatureAlgorithmIdentifier.php +++ b/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Signature/RFC4055RSASignatureAlgorithmIdentifier.php @@ -7,11 +7,10 @@ use SpomkyLabs\Pki\ASN1\Element; /* -From RFC 4055 - 5. PKCS #1 Version 1.5 Signature Algorithm - - When any of these four object identifiers appears within an - AlgorithmIdentifier, the parameters MUST be NULL. Implementations - MUST accept the parameters being absent as well as present. + * From RFC 4055 - 5. PKCS #1 Version 1.5 Signature Algorithm + * When any of these four object identifiers appears within an + * AlgorithmIdentifier, the parameters MUST be NULL. Implementations + * MUST accept the parameters being absent as well as present. */ /** diff --git a/spomky-labs/pki-framework/src/CryptoTypes/Asymmetric/EC/ECPublicKey.php b/spomky-labs/pki-framework/src/CryptoTypes/Asymmetric/EC/ECPublicKey.php index 5ff88773b..e1e4c569a 100644 --- a/spomky-labs/pki-framework/src/CryptoTypes/Asymmetric/EC/ECPublicKey.php +++ b/spomky-labs/pki-framework/src/CryptoTypes/Asymmetric/EC/ECPublicKey.php @@ -116,7 +116,7 @@ public function ECPoint(): string */ public function curvePoint(): array { - return array_map(static fn ($str) => ECConversion::octetsToNumber($str), $this->curvePointOctets()); + return array_map(ECConversion::octetsToNumber(...), $this->curvePointOctets()); } /** diff --git a/spomky-labs/pki-framework/src/CryptoTypes/Signature/RSASignature.php b/spomky-labs/pki-framework/src/CryptoTypes/Signature/RSASignature.php index 61c08c596..dc186df28 100644 --- a/spomky-labs/pki-framework/src/CryptoTypes/Signature/RSASignature.php +++ b/spomky-labs/pki-framework/src/CryptoTypes/Signature/RSASignature.php @@ -21,10 +21,6 @@ final class RSASignature extends Signature */ private ?string $_signature = null; - protected function __construct() - { - } - /** * Initialize from RSA signature *S*. * diff --git a/spomky-labs/pki-framework/src/X501/ASN1/Attribute.php b/spomky-labs/pki-framework/src/X501/ASN1/Attribute.php index 093d43b1b..8e27b754a 100644 --- a/spomky-labs/pki-framework/src/X501/ASN1/Attribute.php +++ b/spomky-labs/pki-framework/src/X501/ASN1/Attribute.php @@ -13,6 +13,7 @@ use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType; use SpomkyLabs\Pki\X501\ASN1\AttributeValue\AttributeValue; use function count; +use function sprintf; /** * Implements *Attribute* ASN.1 type. diff --git a/spomky-labs/pki-framework/src/X501/ASN1/AttributeType.php b/spomky-labs/pki-framework/src/X501/ASN1/AttributeType.php index adde42782..2e53fe877 100644 --- a/spomky-labs/pki-framework/src/X501/ASN1/AttributeType.php +++ b/spomky-labs/pki-framework/src/X501/ASN1/AttributeType.php @@ -412,7 +412,7 @@ final class AttributeType * @param string $_oid OID in dotted format */ private function __construct( - protected string $_oid + private readonly string $_oid ) { } diff --git a/spomky-labs/pki-framework/src/X501/ASN1/AttributeValue/Feature/DirectoryString.php b/spomky-labs/pki-framework/src/X501/ASN1/AttributeValue/Feature/DirectoryString.php index d07891b12..c7b8bf3ad 100644 --- a/spomky-labs/pki-framework/src/X501/ASN1/AttributeValue/Feature/DirectoryString.php +++ b/spomky-labs/pki-framework/src/X501/ASN1/AttributeValue/Feature/DirectoryString.php @@ -18,6 +18,7 @@ use SpomkyLabs\Pki\X501\StringPrep\TranscodeStep; use UnexpectedValueException; use function array_key_exists; +use function sprintf; /** * Base class for attribute values having *(Unbounded)DirectoryString* as a syntax. diff --git a/spomky-labs/pki-framework/src/X501/DN/DNParser.php b/spomky-labs/pki-framework/src/X501/DN/DNParser.php index 1e464125e..d57f4528e 100644 --- a/spomky-labs/pki-framework/src/X501/DN/DNParser.php +++ b/spomky-labs/pki-framework/src/X501/DN/DNParser.php @@ -9,6 +9,7 @@ use SpomkyLabs\Pki\ASN1\Feature\ElementBase; use UnexpectedValueException; use function mb_strlen; +use function sprintf; /** * Distinguished Name parsing conforming to RFC 2253 and RFC 1779. diff --git a/spomky-labs/pki-framework/src/X501/MatchingRule/BinaryMatch.php b/spomky-labs/pki-framework/src/X501/MatchingRule/BinaryMatch.php index 0bb6ab31d..71d8956af 100644 --- a/spomky-labs/pki-framework/src/X501/MatchingRule/BinaryMatch.php +++ b/spomky-labs/pki-framework/src/X501/MatchingRule/BinaryMatch.php @@ -11,7 +11,7 @@ */ final class BinaryMatch extends MatchingRule { - public function compare(string $assertion, string $value): ?bool + public function compare(string $assertion, string $value): bool { return strcmp($assertion, $value) === 0; } diff --git a/spomky-labs/pki-framework/src/X501/StringPrep/MapStep.php b/spomky-labs/pki-framework/src/X501/StringPrep/MapStep.php index 6855d9e26..c5160abd8 100644 --- a/spomky-labs/pki-framework/src/X501/StringPrep/MapStep.php +++ b/spomky-labs/pki-framework/src/X501/StringPrep/MapStep.php @@ -17,7 +17,7 @@ final class MapStep implements PrepareStep * @param bool $fold Whether to apply case folding */ private function __construct( - protected bool $fold + private readonly bool $fold ) { } diff --git a/spomky-labs/pki-framework/src/X501/StringPrep/StringPreparer.php b/spomky-labs/pki-framework/src/X501/StringPrep/StringPreparer.php index 9d7b0623f..497bedd36 100644 --- a/spomky-labs/pki-framework/src/X501/StringPrep/StringPreparer.php +++ b/spomky-labs/pki-framework/src/X501/StringPrep/StringPreparer.php @@ -30,7 +30,7 @@ private function __construct( /** * Preparation steps. */ - protected array $_steps + private array $_steps ) { } diff --git a/spomky-labs/pki-framework/src/X501/StringPrep/TranscodeStep.php b/spomky-labs/pki-framework/src/X501/StringPrep/TranscodeStep.php index ff58611bc..0a744641a 100644 --- a/spomky-labs/pki-framework/src/X501/StringPrep/TranscodeStep.php +++ b/spomky-labs/pki-framework/src/X501/StringPrep/TranscodeStep.php @@ -8,6 +8,7 @@ use SpomkyLabs\Pki\ASN1\Element; use SpomkyLabs\Pki\ASN1\Type\Primitive\T61String; use function in_array; +use function sprintf; /** * Implements 'Transcode' step of the Internationalized String Preparation as specified by RFC 4518. diff --git a/spomky-labs/pki-framework/src/X509/AttributeCertificate/Attribute/IetfAttrSyntax.php b/spomky-labs/pki-framework/src/X509/AttributeCertificate/Attribute/IetfAttrSyntax.php index 559fed4cb..5a0720c65 100644 --- a/spomky-labs/pki-framework/src/X509/AttributeCertificate/Attribute/IetfAttrSyntax.php +++ b/spomky-labs/pki-framework/src/X509/AttributeCertificate/Attribute/IetfAttrSyntax.php @@ -62,12 +62,7 @@ public static function fromASN1(UnspecifiedType $el): AttributeValue ); ++$idx; } - $values = array_map( - static fn (UnspecifiedType $el) => IetfAttrValue::fromASN1($el), - $seq->at($idx) - ->asSequence() - ->elements() - ); + $values = array_map(IetfAttrValue::fromASN1(...), $seq->at($idx) ->asSequence() ->elements()); $obj = static::create(...$values); $obj->_policyAuthority = $authority; return $obj; diff --git a/spomky-labs/pki-framework/src/X509/Certificate/CertificateBundle.php b/spomky-labs/pki-framework/src/X509/Certificate/CertificateBundle.php index 9429cdc59..c007bc37e 100644 --- a/spomky-labs/pki-framework/src/X509/Certificate/CertificateBundle.php +++ b/spomky-labs/pki-framework/src/X509/Certificate/CertificateBundle.php @@ -58,7 +58,7 @@ public static function create(Certificate ...$certs): self */ public static function fromPEMs(PEM ...$pems): self { - $certs = array_map(static fn ($pem) => Certificate::fromPEM($pem), $pems); + $certs = array_map(Certificate::fromPEM(...), $pems); return self::create(...$certs); } diff --git a/spomky-labs/pki-framework/src/X509/Certificate/CertificateChain.php b/spomky-labs/pki-framework/src/X509/Certificate/CertificateChain.php index d4ef84cef..ffb596306 100644 --- a/spomky-labs/pki-framework/src/X509/Certificate/CertificateChain.php +++ b/spomky-labs/pki-framework/src/X509/Certificate/CertificateChain.php @@ -43,7 +43,7 @@ public static function create(Certificate ...$certs): self */ public static function fromPEMs(PEM ...$pems): self { - $certs = array_map(static fn (PEM $pem) => Certificate::fromPEM($pem), $pems); + $certs = array_map(Certificate::fromPEM(...), $pems); return self::create(...$certs); } diff --git a/spomky-labs/pki-framework/src/X509/Certificate/Extension/AAControlsExtension.php b/spomky-labs/pki-framework/src/X509/Certificate/Extension/AAControlsExtension.php index d576e4ec5..c09a284a1 100644 --- a/spomky-labs/pki-framework/src/X509/Certificate/Extension/AAControlsExtension.php +++ b/spomky-labs/pki-framework/src/X509/Certificate/Extension/AAControlsExtension.php @@ -169,11 +169,11 @@ protected function valueASN1(): Element $elements[] = Integer::create($this->pathLenConstraint); } if (isset($this->permittedAttrs)) { - $oids = array_map(static fn ($oid) => ObjectIdentifier::create($oid), $this->permittedAttrs); + $oids = array_map(ObjectIdentifier::create(...), $this->permittedAttrs); $elements[] = ImplicitlyTaggedType::create(0, Sequence::create(...$oids)); } if (isset($this->excludedAttrs)) { - $oids = array_map(static fn ($oid) => ObjectIdentifier::create($oid), $this->excludedAttrs); + $oids = array_map(ObjectIdentifier::create(...), $this->excludedAttrs); $elements[] = ImplicitlyTaggedType::create(1, Sequence::create(...$oids)); } if ($this->permitUnSpecified !== true) { diff --git a/spomky-labs/pki-framework/src/X509/Certificate/Extension/CertificatePolicy/NoticeReference.php b/spomky-labs/pki-framework/src/X509/Certificate/Extension/CertificatePolicy/NoticeReference.php index 1a58962c2..c51d84c71 100644 --- a/spomky-labs/pki-framework/src/X509/Certificate/Extension/CertificatePolicy/NoticeReference.php +++ b/spomky-labs/pki-framework/src/X509/Certificate/Extension/CertificatePolicy/NoticeReference.php @@ -74,7 +74,7 @@ public function numbers(): array public function toASN1(): Sequence { $org = $this->organization->toASN1(); - $nums = array_map(static fn ($number) => Integer::create($number), $this->numbers); + $nums = array_map(Integer::create(...), $this->numbers); return Sequence::create($org, Sequence::create(...$nums)); } } diff --git a/spomky-labs/pki-framework/src/X509/Certificate/Extension/ExtendedKeyUsageExtension.php b/spomky-labs/pki-framework/src/X509/Certificate/Extension/ExtendedKeyUsageExtension.php index f77cd0695..fdffbb7d4 100644 --- a/spomky-labs/pki-framework/src/X509/Certificate/Extension/ExtendedKeyUsageExtension.php +++ b/spomky-labs/pki-framework/src/X509/Certificate/Extension/ExtendedKeyUsageExtension.php @@ -154,7 +154,7 @@ protected static function fromDER(string $data, bool $critical): static protected function valueASN1(): Element { - $elements = array_map(static fn ($oid) => ObjectIdentifier::create($oid), $this->purposes); + $elements = array_map(ObjectIdentifier::create(...), $this->purposes); return Sequence::create(...$elements); } } diff --git a/spomky-labs/pki-framework/src/X509/Certificate/Extension/NameConstraints/GeneralSubtree.php b/spomky-labs/pki-framework/src/X509/Certificate/Extension/NameConstraints/GeneralSubtree.php index e0117a48b..1cd1ba1d6 100644 --- a/spomky-labs/pki-framework/src/X509/Certificate/Extension/NameConstraints/GeneralSubtree.php +++ b/spomky-labs/pki-framework/src/X509/Certificate/Extension/NameConstraints/GeneralSubtree.php @@ -57,7 +57,8 @@ public static function fromASN1(Sequence $seq): self // or rfc822Name [1]. As minimum and maximum are also implicitly tagged, // we have to iterate the remaining elements instead of just checking // for tagged types. - for ($i = 1; $i < count($seq); ++$i) { + $count = count($seq); + for ($i = 1; $i < $count; ++$i) { $el = $seq->at($i) ->expectTagged(); switch ($el->tag()) { @@ -87,7 +88,7 @@ public function base(): GeneralName public function toASN1(): Sequence { $elements = [$this->base->toASN1()]; - if (isset($this->min) && $this->min !== 0) { + if ($this->min !== 0) { $elements[] = ImplicitlyTaggedType::create(0, Integer::create($this->min)); } if (isset($this->max)) { diff --git a/spomky-labs/pki-framework/src/X509/Certificate/Time.php b/spomky-labs/pki-framework/src/X509/Certificate/Time.php index cd6d0eef6..8e2ec909c 100644 --- a/spomky-labs/pki-framework/src/X509/Certificate/Time.php +++ b/spomky-labs/pki-framework/src/X509/Certificate/Time.php @@ -33,9 +33,9 @@ private function __construct( $this->type = $type ?? self::determineType($dt); } - public static function create(DateTimeImmutable $dt): self + public static function create(DateTimeImmutable $dt, ?int $time = null): self { - return new self($dt, null); + return new self($dt, $time); } /** @@ -43,7 +43,15 @@ public static function create(DateTimeImmutable $dt): self */ public static function fromASN1(TimeType $el): self { - return self::create($el->dateTime()); + // Pass the type of the original ASN.1 primitive + if ($el instanceof UTCTime) { + return self::create($el->dateTime(), Element::TYPE_UTC_TIME); + } + if ($el instanceof GeneralizedTime) { + return self::create($el->dateTime(), Element::TYPE_GENERALIZED_TIME); + } + + return self::create($el->dateTime()); // TODO: should never happen? } /** diff --git a/spomky-labs/pki-framework/src/X509/CertificationPath/PathValidation/PathValidator.php b/spomky-labs/pki-framework/src/X509/CertificationPath/PathValidation/PathValidator.php index 8a64596c2..946220ae5 100644 --- a/spomky-labs/pki-framework/src/X509/CertificationPath/PathValidation/PathValidator.php +++ b/spomky-labs/pki-framework/src/X509/CertificationPath/PathValidation/PathValidator.php @@ -40,8 +40,8 @@ final class PathValidator * the end-entity certificate */ private function __construct( - protected Crypto $crypto, - protected PathValidationConfig $config, + private readonly Crypto $crypto, + private readonly PathValidationConfig $config, Certificate ...$certificates ) { if (count($certificates) === 0) { diff --git a/spomky-labs/pki-framework/src/X509/GeneralName/IPv6Address.php b/spomky-labs/pki-framework/src/X509/GeneralName/IPv6Address.php index a79983a72..74194e22e 100644 --- a/spomky-labs/pki-framework/src/X509/GeneralName/IPv6Address.php +++ b/spomky-labs/pki-framework/src/X509/GeneralName/IPv6Address.php @@ -7,6 +7,7 @@ use UnexpectedValueException; use function array_slice; use function count; +use function sprintf; final class IPv6Address extends IPAddress { diff --git a/symfony/uid/AbstractUid.php b/symfony/uid/AbstractUid.php index c67e67e85..7eb7f1468 100644 --- a/symfony/uid/AbstractUid.php +++ b/symfony/uid/AbstractUid.php @@ -70,6 +70,8 @@ public static function fromBase32(string $uid): static } /** + * @param string $uid A valid RFC 9562/4122 uid + * * @throws \InvalidArgumentException When the passed value is not valid */ public static function fromRfc4122(string $uid): static @@ -93,7 +95,7 @@ abstract public function toBinary(): string; */ public function toBase58(): string { - return strtr(sprintf('%022s', BinaryUtil::toBase($this->toBinary(), BinaryUtil::BASE58)), '0', '1'); + return strtr(\sprintf('%022s', BinaryUtil::toBase($this->toBinary(), BinaryUtil::BASE58)), '0', '1'); } /** @@ -106,7 +108,7 @@ public function toBase58(): string public function toBase32(): string { $uid = bin2hex($this->toBinary()); - $uid = sprintf('%02s%04s%04s%04s%04s%04s%04s', + $uid = \sprintf('%02s%04s%04s%04s%04s%04s%04s', base_convert(substr($uid, 0, 2), 16, 32), base_convert(substr($uid, 2, 5), 16, 32), base_convert(substr($uid, 7, 5), 16, 32), @@ -120,9 +122,9 @@ public function toBase32(): string } /** - * Returns the identifier as a RFC4122 case insensitive string. + * Returns the identifier as a RFC 9562/4122 case insensitive string. * - * @see https://tools.ietf.org/html/rfc4122#section-3 + * @see https://datatracker.ietf.org/doc/html/rfc9562/#section-4 * * @example 09748193-048a-4bfb-b825-8528cf74fdc1 (len=36) */ diff --git a/symfony/uid/BinaryUtil.php b/symfony/uid/BinaryUtil.php index 8fd19d867..203e31357 100644 --- a/symfony/uid/BinaryUtil.php +++ b/symfony/uid/BinaryUtil.php @@ -36,7 +36,7 @@ class BinaryUtil 'u' => 52, 'v' => 53, 'w' => 54, 'x' => 55, 'y' => 56, 'z' => 57, ]; - // https://tools.ietf.org/html/rfc4122#section-4.1.4 + // https://datatracker.ietf.org/doc/html/rfc9562#section-5.1 // 0x01b21dd213814000 is the number of 100-ns intervals between the // UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00. private const TIME_OFFSET_INT = 0x01B21DD213814000; diff --git a/symfony/uid/Command/GenerateUlidCommand.php b/symfony/uid/Command/GenerateUlidCommand.php index 6c8d16387..a41cf2840 100644 --- a/symfony/uid/Command/GenerateUlidCommand.php +++ b/symfony/uid/Command/GenerateUlidCommand.php @@ -40,7 +40,7 @@ protected function configure(): void ->setDefinition([ new InputOption('time', null, InputOption::VALUE_REQUIRED, 'The ULID timestamp: a parsable date/time string'), new InputOption('count', 'c', InputOption::VALUE_REQUIRED, 'The number of ULID to generate', 1), - new InputOption('format', 'f', InputOption::VALUE_REQUIRED, sprintf('The ULID output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'base32'), + new InputOption('format', 'f', InputOption::VALUE_REQUIRED, \sprintf('The ULID output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'base32'), ]) ->setHelp(<<<'EOF' The %command.name% command generates a ULID. @@ -71,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int try { $time = new \DateTimeImmutable($time); } catch (\Exception $e) { - $io->error(sprintf('Invalid timestamp "%s": %s', $time, str_replace('DateTimeImmutable::__construct(): ', '', $e->getMessage()))); + $io->error(\sprintf('Invalid timestamp "%s": %s', $time, str_replace('DateTimeImmutable::__construct(): ', '', $e->getMessage()))); return 1; } @@ -82,7 +82,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (\in_array($formatOption, $this->getAvailableFormatOptions())) { $format = 'to'.ucfirst($formatOption); } else { - $io->error(sprintf('Invalid format "%s", supported formats are "%s".', $formatOption, implode('", "', $this->getAvailableFormatOptions()))); + $io->error(\sprintf('Invalid format "%s", supported formats are "%s".', $formatOption, implode('", "', $this->getAvailableFormatOptions()))); return 1; } diff --git a/symfony/uid/Command/GenerateUuidCommand.php b/symfony/uid/Command/GenerateUuidCommand.php index 6dad923c4..858f44990 100644 --- a/symfony/uid/Command/GenerateUuidCommand.php +++ b/symfony/uid/Command/GenerateUuidCommand.php @@ -45,7 +45,7 @@ protected function configure(): void new InputOption('namespace', null, InputOption::VALUE_REQUIRED, 'The UUID to use at the namespace for named-based UUIDs, predefined namespaces keywords "dns", "url", "oid" and "x500" are accepted'), new InputOption('random-based', null, InputOption::VALUE_NONE, 'To generate a random-based UUID'), new InputOption('count', 'c', InputOption::VALUE_REQUIRED, 'The number of UUID to generate', 1), - new InputOption('format', 'f', InputOption::VALUE_REQUIRED, sprintf('The UUID output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'rfc4122'), + new InputOption('format', 'f', InputOption::VALUE_REQUIRED, \sprintf('The UUID output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'rfc4122'), ]) ->setHelp(<<<'EOF' The %command.name% generates a UUID. @@ -118,7 +118,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int try { $node = Uuid::fromString($node); } catch (\InvalidArgumentException $e) { - $io->error(sprintf('Invalid node "%s": %s', $node, $e->getMessage())); + $io->error(\sprintf('Invalid node "%s": %s', $node, $e->getMessage())); return 1; } @@ -127,7 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int try { new \DateTimeImmutable($time); } catch (\Exception $e) { - $io->error(sprintf('Invalid timestamp "%s": %s', $time, str_replace('DateTimeImmutable::__construct(): ', '', $e->getMessage()))); + $io->error(\sprintf('Invalid timestamp "%s": %s', $time, str_replace('DateTimeImmutable::__construct(): ', '', $e->getMessage()))); return 1; } @@ -140,7 +140,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int try { $namespace = Uuid::fromString($namespace); } catch (\InvalidArgumentException $e) { - $io->error(sprintf('Invalid namespace "%s": %s', $namespace, $e->getMessage())); + $io->error(\sprintf('Invalid namespace "%s": %s', $namespace, $e->getMessage())); return 1; } @@ -171,7 +171,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (\in_array($formatOption, $this->getAvailableFormatOptions())) { $format = 'to'.ucfirst($formatOption); } else { - $io->error(sprintf('Invalid format "%s", supported formats are "%s".', $formatOption, implode('", "', $this->getAvailableFormatOptions()))); + $io->error(\sprintf('Invalid format "%s", supported formats are "%s".', $formatOption, implode('", "', $this->getAvailableFormatOptions()))); return 1; } diff --git a/symfony/uid/Factory/UuidFactory.php b/symfony/uid/Factory/UuidFactory.php index d1935c4ba..f95082d2c 100644 --- a/symfony/uid/Factory/UuidFactory.php +++ b/symfony/uid/Factory/UuidFactory.php @@ -72,7 +72,7 @@ public function nameBased(Uuid|string|null $namespace = null): NameBasedUuidFact $namespace ??= $this->nameBasedNamespace; if (null === $namespace) { - throw new \LogicException(sprintf('A namespace should be defined when using "%s()".', __METHOD__)); + throw new \LogicException(\sprintf('A namespace should be defined when using "%s()".', __METHOD__)); } return new NameBasedUuidFactory($this->nameBasedClass, $this->getNamespace($namespace)); diff --git a/symfony/uid/Ulid.php b/symfony/uid/Ulid.php index 5359067af..87f604a11 100644 --- a/symfony/uid/Ulid.php +++ b/symfony/uid/Ulid.php @@ -36,7 +36,7 @@ public function __construct(?string $ulid = null) $this->uid = $ulid; } else { if (!self::isValid($ulid)) { - throw new \InvalidArgumentException(sprintf('Invalid ULID: "%s".', $ulid)); + throw new \InvalidArgumentException(\sprintf('Invalid ULID: "%s".', $ulid)); } $this->uid = strtoupper($ulid); @@ -73,7 +73,7 @@ public static function fromString(string $ulid): static } $ulid = bin2hex($ulid); - $ulid = sprintf('%02s%04s%04s%04s%04s%04s%04s', + $ulid = \sprintf('%02s%04s%04s%04s%04s%04s%04s', base_convert(substr($ulid, 0, 2), 16, 32), base_convert(substr($ulid, 2, 5), 16, 32), base_convert(substr($ulid, 7, 5), 16, 32), @@ -101,7 +101,7 @@ public function toBinary(): string { $ulid = strtr($this->uid, 'ABCDEFGHJKMNPQRSTVWXYZ', 'abcdefghijklmnopqrstuv'); - $ulid = sprintf('%02s%05s%05s%05s%05s%05s%05s', + $ulid = \sprintf('%02s%05s%05s%05s%05s%05s%05s', base_convert(substr($ulid, 0, 2), 32, 16), base_convert(substr($ulid, 2, 4), 32, 16), base_convert(substr($ulid, 6, 4), 32, 16), @@ -133,7 +133,7 @@ public function getDateTime(): \DateTimeImmutable if (\PHP_INT_SIZE >= 8) { $time = (string) hexdec(base_convert($time, 32, 16)); } else { - $time = sprintf('%02s%05s%05s', + $time = \sprintf('%02s%05s%05s', base_convert(substr($time, 0, 2), 32, 16), base_convert(substr($time, 2, 4), 32, 16), base_convert(substr($time, 6, 4), 32, 16) @@ -190,14 +190,14 @@ public static function generate(?\DateTimeInterface $time = null): string $time = base_convert($time, 10, 32); } else { $time = str_pad(bin2hex(BinaryUtil::fromBase($time, BinaryUtil::BASE10)), 12, '0', \STR_PAD_LEFT); - $time = sprintf('%s%04s%04s', + $time = \sprintf('%s%04s%04s', base_convert(substr($time, 0, 2), 16, 32), base_convert(substr($time, 2, 5), 16, 32), base_convert(substr($time, 7, 5), 16, 32) ); } - return strtr(sprintf('%010s%04s%04s%04s%04s', + return strtr(\sprintf('%010s%04s%04s%04s%04s', $time, base_convert(self::$rand[1], 10, 32), base_convert(self::$rand[2], 10, 32), diff --git a/symfony/uid/Uuid.php b/symfony/uid/Uuid.php index 85d366c18..85968993d 100644 --- a/symfony/uid/Uuid.php +++ b/symfony/uid/Uuid.php @@ -14,7 +14,7 @@ /** * @author Grégoire Pineau * - * @see https://tools.ietf.org/html/rfc4122#appendix-C for details about namespaces + * @see https://datatracker.ietf.org/doc/html/rfc9562/#section-6.6 for details about namespaces */ class Uuid extends AbstractUid { @@ -32,13 +32,13 @@ public function __construct(string $uuid, bool $checkVariant = false) $type = preg_match('{^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$}Di', $uuid) ? (int) $uuid[14] : false; if (false === $type || (static::TYPE ?: $type) !== $type) { - throw new \InvalidArgumentException(sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid)); + throw new \InvalidArgumentException(\sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid)); } $this->uid = strtolower($uuid); if ($checkVariant && !\in_array($this->uid[19], ['8', '9', 'a', 'b'], true)) { - throw new \InvalidArgumentException(sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid)); + throw new \InvalidArgumentException(\sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid)); } } @@ -153,9 +153,9 @@ public function toBinary(): string } /** - * Returns the identifier as a RFC4122 case insensitive string. + * Returns the identifier as a RFC 9562/4122 case insensitive string. * - * @see https://tools.ietf.org/html/rfc4122#section-3 + * @see https://datatracker.ietf.org/doc/html/rfc9562/#section-4 * * @example 09748193-048a-4bfb-b825-8528cf74fdc1 (len=36) */ diff --git a/symfony/uid/UuidV1.php b/symfony/uid/UuidV1.php index 1ec004168..ae21f92bf 100644 --- a/symfony/uid/UuidV1.php +++ b/symfony/uid/UuidV1.php @@ -25,7 +25,7 @@ class UuidV1 extends Uuid implements TimeBasedUidInterface public function __construct(?string $uuid = null) { if (null === $uuid) { - $this->uid = uuid_create(static::TYPE); + $this->uid = strtolower(uuid_create(static::TYPE)); } else { parent::__construct($uuid, true); } @@ -54,7 +54,7 @@ public static function generate(?\DateTimeInterface $time = null, ?Uuid $node = $seq = substr($uuid, 19, 4); do { - self::$clockSeq = sprintf('%04x', random_int(0, 0x3FFF) | 0x8000); + self::$clockSeq = \sprintf('%04x', random_int(0, 0x3FFF) | 0x8000); } while ($seq === self::$clockSeq); $seq = self::$clockSeq; diff --git a/symfony/uid/UuidV6.php b/symfony/uid/UuidV6.php index b3492083c..cd30082e2 100644 --- a/symfony/uid/UuidV6.php +++ b/symfony/uid/UuidV6.php @@ -58,7 +58,7 @@ public static function generate(?\DateTimeInterface $time = null, ?Uuid $node = if (!isset(self::$node)) { $seed = [random_int(0, 0xFFFFFF), random_int(0, 0xFFFFFF)]; $node = unpack('N2', hex2bin('00'.substr($uuidV1, 24, 6)).hex2bin('00'.substr($uuidV1, 30))); - self::$node = sprintf('%06x%06x', ($seed[0] ^ $node[1]) | 0x010000, $seed[1] ^ $node[2]); + self::$node = \sprintf('%06x%06x', ($seed[0] ^ $node[1]) | 0x010000, $seed[1] ^ $node[2]); } return $uuid.self::$node; diff --git a/symfony/uid/UuidV7.php b/symfony/uid/UuidV7.php index 43740b67e..12c752095 100644 --- a/symfony/uid/UuidV7.php +++ b/symfony/uid/UuidV7.php @@ -60,7 +60,7 @@ public static function generate(?\DateTimeInterface $time = null): string if ($time > self::$time || (null !== $mtime && $time !== self::$time)) { randomize: - self::$rand = unpack('n*', isset(self::$seed) ? random_bytes(10) : self::$seed = random_bytes(16)); + self::$rand = unpack('S*', isset(self::$seed) ? random_bytes(10) : self::$seed = random_bytes(16)); self::$rand[1] &= 0x03FF; self::$time = $time; } else { @@ -76,7 +76,7 @@ public static function generate(?\DateTimeInterface $time = null): string // 24-bit number in the self::$seedParts list and decrement self::$seedIndex. if (!self::$seedIndex) { - $s = unpack('l*', self::$seed = hash('sha512', self::$seed, true)); + $s = unpack(\PHP_INT_SIZE >= 8 ? 'L*' : 'l*', self::$seed = hash('sha512', self::$seed, true)); $s[] = ($s[1] >> 8 & 0xFF0000) | ($s[2] >> 16 & 0xFF00) | ($s[3] >> 24 & 0xFF); $s[] = ($s[4] >> 8 & 0xFF0000) | ($s[5] >> 16 & 0xFF00) | ($s[6] >> 24 & 0xFF); $s[] = ($s[7] >> 8 & 0xFF0000) | ($s[8] >> 16 & 0xFF00) | ($s[9] >> 24 & 0xFF); @@ -113,7 +113,7 @@ public static function generate(?\DateTimeInterface $time = null): string $time = bin2hex(BinaryUtil::fromBase($time, BinaryUtil::BASE10)); } - return substr_replace(sprintf('%012s-%04x-%04x-%04x%04x%04x', + return substr_replace(\sprintf('%012s-%04x-%04x-%04x%04x%04x', $time, 0x7000 | (self::$rand[1] << 2) | (self::$rand[2] >> 14), 0x8000 | (self::$rand[2] & 0x3FFF), diff --git a/web-auth/cose-lib/src/Algorithm/Mac/Hmac.php b/web-auth/cose-lib/src/Algorithm/Mac/Hmac.php index 7ad80808e..54ef46076 100644 --- a/web-auth/cose-lib/src/Algorithm/Mac/Hmac.php +++ b/web-auth/cose-lib/src/Algorithm/Mac/Hmac.php @@ -18,7 +18,7 @@ public function hash(string $data, Key $key): string $this->checKey($key); $signature = hash_hmac($this->getHashAlgorithm(), $data, (string) $key->get(SymmetricKey::DATA_K), true); - return mb_substr($signature, 0, intdiv($this->getSignatureLength(), 8), '8bit'); + return substr($signature, 0, intdiv($this->getSignatureLength(), 8)); } public function verify(string $data, Key $key, string $signature): bool diff --git a/web-auth/cose-lib/src/Algorithm/ManagerFactory.php b/web-auth/cose-lib/src/Algorithm/ManagerFactory.php index 548e0a72d..380d1e0c7 100644 --- a/web-auth/cose-lib/src/Algorithm/ManagerFactory.php +++ b/web-auth/cose-lib/src/Algorithm/ManagerFactory.php @@ -6,6 +6,7 @@ use InvalidArgumentException; use function array_key_exists; +use function sprintf; final class ManagerFactory { diff --git a/web-auth/cose-lib/src/Algorithm/Signature/ECDSA/ECSignature.php b/web-auth/cose-lib/src/Algorithm/Signature/ECDSA/ECSignature.php index 43547001c..5995131a1 100644 --- a/web-auth/cose-lib/src/Algorithm/Signature/ECDSA/ECSignature.php +++ b/web-auth/cose-lib/src/Algorithm/Signature/ECDSA/ECSignature.php @@ -9,9 +9,9 @@ use function dechex; use function hex2bin; use function hexdec; -use function mb_strlen; -use function mb_substr; use function str_pad; +use function strlen; +use function substr; use const STR_PAD_LEFT; /** @@ -41,8 +41,8 @@ public static function toAsn1(string $signature, int $length): string throw new InvalidArgumentException('Invalid signature length.'); } - $pointR = self::preparePositiveInteger(mb_substr($signature, 0, $length, '8bit')); - $pointS = self::preparePositiveInteger(mb_substr($signature, $length, null, '8bit')); + $pointR = self::preparePositiveInteger(substr($signature, 0, $length)); + $pointS = self::preparePositiveInteger(substr($signature, $length, null)); $lengthR = self::octetLength($pointR); $lengthS = self::octetLength($pointS); @@ -80,20 +80,20 @@ public static function fromAsn1(string $signature, int $length): string private static function octetLength(string $data): int { - return intdiv(mb_strlen($data, '8bit'), self::BYTE_SIZE); + return intdiv(strlen($data), self::BYTE_SIZE); } private static function preparePositiveInteger(string $data): string { - if (mb_substr($data, 0, self::BYTE_SIZE, '8bit') > self::ASN1_BIG_INTEGER_LIMIT) { + if (substr($data, 0, self::BYTE_SIZE) > self::ASN1_BIG_INTEGER_LIMIT) { return self::ASN1_NEGATIVE_INTEGER . $data; } while ( - mb_strpos($data, self::ASN1_NEGATIVE_INTEGER, 0, '8bit') === 0 - && mb_substr($data, 2, self::BYTE_SIZE, '8bit') <= self::ASN1_BIG_INTEGER_LIMIT + str_starts_with($data, self::ASN1_NEGATIVE_INTEGER) + && substr($data, 2, self::BYTE_SIZE) <= self::ASN1_BIG_INTEGER_LIMIT ) { - $data = mb_substr($data, 2, null, '8bit'); + $data = substr($data, 2, null); } return $data; @@ -101,7 +101,7 @@ private static function preparePositiveInteger(string $data): string private static function readAsn1Content(string $message, int &$position, int $length): string { - $content = mb_substr($message, $position, $length, '8bit'); + $content = substr($message, $position, $length); $position += $length; return $content; @@ -121,10 +121,10 @@ private static function readAsn1Integer(string $message, int &$position): string private static function retrievePositiveInteger(string $data): string { while ( - mb_strpos($data, self::ASN1_NEGATIVE_INTEGER, 0, '8bit') === 0 - && mb_substr($data, 2, self::BYTE_SIZE, '8bit') > self::ASN1_BIG_INTEGER_LIMIT + str_starts_with($data, self::ASN1_NEGATIVE_INTEGER) + && substr($data, 2, self::BYTE_SIZE) > self::ASN1_BIG_INTEGER_LIMIT ) { - $data = mb_substr($data, 2, null, '8bit'); + $data = substr($data, 2, null); } return $data; diff --git a/web-auth/cose-lib/src/Algorithm/Signature/EdDSA/EdDSA.php b/web-auth/cose-lib/src/Algorithm/Signature/EdDSA/EdDSA.php index 7a0278b3e..37426e9fd 100644 --- a/web-auth/cose-lib/src/Algorithm/Signature/EdDSA/EdDSA.php +++ b/web-auth/cose-lib/src/Algorithm/Signature/EdDSA/EdDSA.php @@ -43,12 +43,10 @@ public function verify(string $data, Key $key, string $signature): bool throw new InvalidArgumentException('Unsupported curve'); } try { - sodium_crypto_sign_verify_detached($signature, $data, $key->x()); + return sodium_crypto_sign_verify_detached($signature, $data, $key->x()); } catch (Throwable) { return false; } - - return true; } public static function identifier(): int diff --git a/web-auth/cose-lib/src/Algorithm/Signature/RSA/PSSRSA.php b/web-auth/cose-lib/src/Algorithm/Signature/RSA/PSSRSA.php index e2fa31963..d383dce62 100644 --- a/web-auth/cose-lib/src/Algorithm/Signature/RSA/PSSRSA.php +++ b/web-auth/cose-lib/src/Algorithm/Signature/RSA/PSSRSA.php @@ -14,13 +14,12 @@ use function ceil; use function chr; use function hash_equals; -use function mb_strlen; -use function mb_substr; use function ord; use function pack; use function random_bytes; use function str_pad; use function str_repeat; +use function strlen; use const STR_PAD_LEFT; /** @@ -31,7 +30,7 @@ abstract class PSSRSA implements Signature public function sign(string $data, Key $key): string { $key = $this->handleKey($key); - $modulusLength = mb_strlen($key->n(), '8bit'); + $modulusLength = strlen($key->n()); $em = $this->encodeEMSAPSS($data, 8 * $modulusLength - 1, $this->getHashAlgorithm()); $message = BigInteger::createFromBinaryString($em); @@ -43,8 +42,8 @@ public function sign(string $data, Key $key): string public function verify(string $data, Key $key, string $signature): bool { $key = $this->handleKey($key); - $modulusLength = mb_strlen($key->n(), '8bit'); - if (mb_strlen($signature, '8bit') !== $modulusLength) { + $modulusLength = strlen($key->n()); + if (strlen($signature) !== $modulusLength) { throw new InvalidArgumentException('Invalid modulus length'); } $s2 = BigInteger::createFromBinaryString($signature); @@ -99,7 +98,7 @@ private function handleKey(Key $key): RsaKey private function convertIntegerToOctetString(BigInteger $x, int $xLen): string { $xB = $x->toBytes(); - if (mb_strlen($xB, '8bit') > $xLen) { + if (strlen($xB) > $xLen) { throw new RuntimeException('Unable to convert the integer'); } @@ -118,7 +117,7 @@ private function getMGF1(string $mgfSeed, int $maskLen, Hash $mgfHash): string $t .= $mgfHash->hash($mgfSeed . $c); } - return mb_substr($t, 0, $maskLen, '8bit'); + return substr($t, 0, $maskLen); } /** @@ -155,11 +154,11 @@ private function verifyEMSAPSS(string $m, string $em, int $emBits, Hash $hash): if ($emLen < $hash->getLength() + $sLen + 2) { throw new InvalidArgumentException(); } - if ($em[mb_strlen($em, '8bit') - 1] !== chr(0xBC)) { + if ($em[strlen($em) - 1] !== chr(0xBC)) { throw new InvalidArgumentException(); } - $maskedDB = mb_substr($em, 0, -$hash->getLength() - 1, '8bit'); - $h = mb_substr($em, -$hash->getLength() - 1, $hash->getLength(), '8bit'); + $maskedDB = substr($em, 0, -$hash->getLength() - 1); + $h = substr($em, -$hash->getLength() - 1, $hash->getLength()); $temp = chr(0xFF << ($emBits & 7)); if ((~$maskedDB[0] & $temp) !== $temp) { throw new InvalidArgumentException(); @@ -168,13 +167,13 @@ private function verifyEMSAPSS(string $m, string $em, int $emBits, Hash $hash): $db = $maskedDB ^ $dbMask; $db[0] = ~chr(0xFF << ($emBits & 7)) & $db[0]; $temp = $emLen - $hash->getLength() - $sLen - 2; - if (mb_strpos($db, str_repeat(chr(0), $temp), 0, '8bit') !== 0) { + if (! str_starts_with($db, str_repeat(chr(0), $temp))) { throw new InvalidArgumentException(); } if (ord($db[$temp]) !== 1) { throw new InvalidArgumentException(); } - $salt = mb_substr($db, $temp + 1, null, '8bit'); // should be $sLen long + $salt = substr($db, $temp + 1, null); // should be $sLen long $m2 = "\0\0\0\0\0\0\0\0" . $mHash . $salt; $h2 = $hash->hash($m2); diff --git a/web-auth/cose-lib/src/BigInteger.php b/web-auth/cose-lib/src/BigInteger.php index e0ef082fa..d45fd39b6 100644 --- a/web-auth/cose-lib/src/BigInteger.php +++ b/web-auth/cose-lib/src/BigInteger.php @@ -7,6 +7,7 @@ use Brick\Math\BigInteger as BrickBigInteger; use function chr; use function hex2bin; +use function strlen; use function unpack; /** @@ -42,7 +43,7 @@ public function toBytes(): string } $temp = $this->value->toBase(16); - $temp = 0 !== (mb_strlen($temp, '8bit') & 1) ? '0' . $temp : $temp; + $temp = 0 !== (strlen($temp) & 1) ? '0' . $temp : $temp; $temp = hex2bin($temp); return ltrim($temp, chr(0)); diff --git a/web-auth/cose-lib/src/Key/Ec2Key.php b/web-auth/cose-lib/src/Key/Ec2Key.php index e0fa7e19f..38b916d29 100644 --- a/web-auth/cose-lib/src/Key/Ec2Key.php +++ b/web-auth/cose-lib/src/Key/Ec2Key.php @@ -14,6 +14,8 @@ use function array_key_exists; use function in_array; use function is_int; +use function sprintf; +use function strlen; /** * @final @@ -93,10 +95,10 @@ public function __construct(array $data) if (! isset($data[self::DATA_CURVE], $data[self::DATA_X], $data[self::DATA_Y])) { throw new InvalidArgumentException('Invalid EC2 key. The curve or the "x/y" coordinates are missing'); } - if (mb_strlen((string) $data[self::DATA_X], '8bit') !== self::CURVE_KEY_LENGTH[$data[self::DATA_CURVE]]) { + if (strlen((string) $data[self::DATA_X]) !== self::CURVE_KEY_LENGTH[$data[self::DATA_CURVE]]) { throw new InvalidArgumentException('Invalid length for x coordinate'); } - if (mb_strlen((string) $data[self::DATA_Y], '8bit') !== self::CURVE_KEY_LENGTH[$data[self::DATA_CURVE]]) { + if (strlen((string) $data[self::DATA_Y]) !== self::CURVE_KEY_LENGTH[$data[self::DATA_CURVE]]) { throw new InvalidArgumentException('Invalid length for y coordinate'); } if (is_int($data[self::DATA_CURVE])) { @@ -188,8 +190,8 @@ private function getCurveOid(): string private function pem(string $type, string $der): string { - return sprintf("-----BEGIN %s-----\n", mb_strtoupper($type)) . + return sprintf("-----BEGIN %s-----\n", strtoupper($type)) . chunk_split(base64_encode($der), 64, "\n") . - sprintf("-----END %s-----\n", mb_strtoupper($type)); + sprintf("-----END %s-----\n", strtoupper($type)); } } diff --git a/web-auth/cose-lib/src/Key/Key.php b/web-auth/cose-lib/src/Key/Key.php index 7b28f7b91..b35010ceb 100644 --- a/web-auth/cose-lib/src/Key/Key.php +++ b/web-auth/cose-lib/src/Key/Key.php @@ -6,6 +6,7 @@ use InvalidArgumentException; use function array_key_exists; +use function sprintf; class Key { diff --git a/web-auth/webauthn-lib/src/AttestationStatement/AndroidKeyAttestationStatementSupport.php b/web-auth/webauthn-lib/src/AttestationStatement/AndroidKeyAttestationStatementSupport.php index eb54b7b40..002423545 100644 --- a/web-auth/webauthn-lib/src/AttestationStatement/AndroidKeyAttestationStatementSupport.php +++ b/web-auth/webauthn-lib/src/AttestationStatement/AndroidKeyAttestationStatementSupport.php @@ -29,6 +29,7 @@ use function is_array; use function openssl_pkey_get_public; use function openssl_verify; +use function sprintf; final class AndroidKeyAttestationStatementSupport implements AttestationStatementSupport, CanDispatchEvents { diff --git a/web-auth/webauthn-lib/src/AttestationStatement/AndroidSafetyNetAttestationStatementSupport.php b/web-auth/webauthn-lib/src/AttestationStatement/AndroidSafetyNetAttestationStatementSupport.php index cd87757c3..d852ce517 100644 --- a/web-auth/webauthn-lib/src/AttestationStatement/AndroidSafetyNetAttestationStatementSupport.php +++ b/web-auth/webauthn-lib/src/AttestationStatement/AndroidSafetyNetAttestationStatementSupport.php @@ -41,6 +41,7 @@ use function is_array; use function is_int; use function is_string; +use function sprintf; use const JSON_THROW_ON_ERROR; /** diff --git a/web-auth/webauthn-lib/src/AttestationStatement/AttestationStatement.php b/web-auth/webauthn-lib/src/AttestationStatement/AttestationStatement.php index 5285de2eb..8f45491c0 100644 --- a/web-auth/webauthn-lib/src/AttestationStatement/AttestationStatement.php +++ b/web-auth/webauthn-lib/src/AttestationStatement/AttestationStatement.php @@ -9,6 +9,7 @@ use Webauthn\TrustPath\TrustPath; use Webauthn\TrustPath\TrustPathLoader; use function array_key_exists; +use function sprintf; class AttestationStatement implements JsonSerializable { diff --git a/web-auth/webauthn-lib/src/AttestationStatement/AttestationStatementSupportManager.php b/web-auth/webauthn-lib/src/AttestationStatement/AttestationStatementSupportManager.php index 089028810..7687d8d35 100644 --- a/web-auth/webauthn-lib/src/AttestationStatement/AttestationStatementSupportManager.php +++ b/web-auth/webauthn-lib/src/AttestationStatement/AttestationStatementSupportManager.php @@ -6,6 +6,7 @@ use Webauthn\Exception\InvalidDataException; use function array_key_exists; +use function sprintf; class AttestationStatementSupportManager { diff --git a/web-auth/webauthn-lib/src/AttestationStatement/FidoU2FAttestationStatementSupport.php b/web-auth/webauthn-lib/src/AttestationStatement/FidoU2FAttestationStatementSupport.php index db4bf3a12..c0d812b2f 100644 --- a/web-auth/webauthn-lib/src/AttestationStatement/FidoU2FAttestationStatementSupport.php +++ b/web-auth/webauthn-lib/src/AttestationStatement/FidoU2FAttestationStatementSupport.php @@ -24,6 +24,7 @@ use function is_array; use function openssl_pkey_get_public; use function openssl_verify; +use function sprintf; use const OPENSSL_ALGO_SHA256; final class FidoU2FAttestationStatementSupport implements AttestationStatementSupport, CanDispatchEvents diff --git a/web-auth/webauthn-lib/src/AttestationStatement/TPMAttestationStatementSupport.php b/web-auth/webauthn-lib/src/AttestationStatement/TPMAttestationStatementSupport.php index 71a60ca61..7f027ef83 100644 --- a/web-auth/webauthn-lib/src/AttestationStatement/TPMAttestationStatementSupport.php +++ b/web-auth/webauthn-lib/src/AttestationStatement/TPMAttestationStatementSupport.php @@ -36,6 +36,7 @@ use function is_array; use function is_int; use function openssl_verify; +use function sprintf; use function unpack; final class TPMAttestationStatementSupport implements AttestationStatementSupport, CanDispatchEvents diff --git a/web-auth/webauthn-lib/src/AuthenticationExtensions/AuthenticationExtensions.php b/web-auth/webauthn-lib/src/AuthenticationExtensions/AuthenticationExtensions.php index 2ef2bc65e..5315524e9 100644 --- a/web-auth/webauthn-lib/src/AuthenticationExtensions/AuthenticationExtensions.php +++ b/web-auth/webauthn-lib/src/AuthenticationExtensions/AuthenticationExtensions.php @@ -14,6 +14,7 @@ use function array_key_exists; use function count; use function is_string; +use function sprintf; use const COUNT_NORMAL; /** diff --git a/web-auth/webauthn-lib/src/AuthenticationExtensions/ExtensionOutputError.php b/web-auth/webauthn-lib/src/AuthenticationExtensions/ExtensionOutputError.php index 9adcc706f..9310befa5 100644 --- a/web-auth/webauthn-lib/src/AuthenticationExtensions/ExtensionOutputError.php +++ b/web-auth/webauthn-lib/src/AuthenticationExtensions/ExtensionOutputError.php @@ -13,7 +13,7 @@ public function __construct( public readonly AuthenticationExtension $authenticationExtension, string $message = '', int $code = 0, - Throwable $previous = null + ?Throwable $previous = null ) { parent::__construct($message, $code, $previous); } diff --git a/web-auth/webauthn-lib/src/AuthenticatorAssertionResponseValidator.php b/web-auth/webauthn-lib/src/AuthenticatorAssertionResponseValidator.php index fa433b211..d6923b724 100644 --- a/web-auth/webauthn-lib/src/AuthenticatorAssertionResponseValidator.php +++ b/web-auth/webauthn-lib/src/AuthenticatorAssertionResponseValidator.php @@ -22,6 +22,7 @@ use Webauthn\MetadataService\CanLogData; use Webauthn\TokenBinding\TokenBindingHandler; use function is_string; +use function sprintf; class AuthenticatorAssertionResponseValidator implements CanLogData, CanDispatchEvents { diff --git a/web-auth/webauthn-lib/src/AuthenticatorAttestationResponseValidator.php b/web-auth/webauthn-lib/src/AuthenticatorAttestationResponseValidator.php index 97d43402e..71fc82f6b 100644 --- a/web-auth/webauthn-lib/src/AuthenticatorAttestationResponseValidator.php +++ b/web-auth/webauthn-lib/src/AuthenticatorAttestationResponseValidator.php @@ -24,6 +24,7 @@ use Webauthn\MetadataService\StatusReportRepository; use Webauthn\TokenBinding\TokenBindingHandler; use function is_string; +use function sprintf; class AuthenticatorAttestationResponseValidator implements CanLogData, CanDispatchEvents { diff --git a/web-auth/webauthn-lib/src/CeremonyStep/CheckAlgorithm.php b/web-auth/webauthn-lib/src/CeremonyStep/CheckAlgorithm.php index 9b5e39b22..74a221e14 100644 --- a/web-auth/webauthn-lib/src/CeremonyStep/CheckAlgorithm.php +++ b/web-auth/webauthn-lib/src/CeremonyStep/CheckAlgorithm.php @@ -19,6 +19,7 @@ use function count; use function in_array; use function is_array; +use function sprintf; class CheckAlgorithm implements CeremonyStep { @@ -33,7 +34,7 @@ public function process( return; } $credentialPublicKey = $publicKeyCredentialSource->getAttestedCredentialData() -->credentialPublicKey; + ->credentialPublicKey; $credentialPublicKey !== null || throw AuthenticatorResponseVerificationException::create( 'No public key available.' ); diff --git a/web-auth/webauthn-lib/src/CeremonyStep/CheckMetadataStatement.php b/web-auth/webauthn-lib/src/CeremonyStep/CheckMetadataStatement.php index ce482a4a7..59c23c754 100644 --- a/web-auth/webauthn-lib/src/CeremonyStep/CheckMetadataStatement.php +++ b/web-auth/webauthn-lib/src/CeremonyStep/CheckMetadataStatement.php @@ -22,6 +22,7 @@ use Webauthn\TrustPath\CertificateTrustPath; use function count; use function in_array; +use function sprintf; final class CheckMetadataStatement implements CeremonyStep, CanLogData { diff --git a/web-auth/webauthn-lib/src/CeremonyStep/CheckSignature.php b/web-auth/webauthn-lib/src/CeremonyStep/CheckSignature.php index a89fef324..20454dc83 100644 --- a/web-auth/webauthn-lib/src/CeremonyStep/CheckSignature.php +++ b/web-auth/webauthn-lib/src/CeremonyStep/CheckSignature.php @@ -43,7 +43,7 @@ public function process( return; } $credentialPublicKey = $publicKeyCredentialSource->getAttestedCredentialData() -->credentialPublicKey; + ->credentialPublicKey; $credentialPublicKey !== null || throw AuthenticatorResponseVerificationException::create( 'No public key available.' ); diff --git a/web-auth/webauthn-lib/src/ClientDataCollector/WebauthnAuthenticationCollector.php b/web-auth/webauthn-lib/src/ClientDataCollector/WebauthnAuthenticationCollector.php index 1a316e258..ea97fdf1e 100644 --- a/web-auth/webauthn-lib/src/ClientDataCollector/WebauthnAuthenticationCollector.php +++ b/web-auth/webauthn-lib/src/ClientDataCollector/WebauthnAuthenticationCollector.php @@ -9,6 +9,7 @@ use Webauthn\Exception\AuthenticatorResponseVerificationException; use Webauthn\PublicKeyCredentialOptions; use function in_array; +use function sprintf; final class WebauthnAuthenticationCollector implements ClientDataCollector { diff --git a/web-auth/webauthn-lib/src/CollectedClientData.php b/web-auth/webauthn-lib/src/CollectedClientData.php index 3731207bb..f7c14b531 100644 --- a/web-auth/webauthn-lib/src/CollectedClientData.php +++ b/web-auth/webauthn-lib/src/CollectedClientData.php @@ -10,6 +10,7 @@ use function array_key_exists; use function is_array; use function is_string; +use function sprintf; use const JSON_THROW_ON_ERROR; class CollectedClientData diff --git a/web-auth/webauthn-lib/src/Denormalizer/AttestationObjectDenormalizer.php b/web-auth/webauthn-lib/src/Denormalizer/AttestationObjectDenormalizer.php index dfd4519b7..eae463088 100644 --- a/web-auth/webauthn-lib/src/Denormalizer/AttestationObjectDenormalizer.php +++ b/web-auth/webauthn-lib/src/Denormalizer/AttestationObjectDenormalizer.php @@ -19,7 +19,7 @@ final class AttestationObjectDenormalizer implements DenormalizerInterface, Deno { use DenormalizerAwareTrait; - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { $stream = new StringStream($data); $parsed = Decoder::create()->decode($stream); @@ -46,8 +46,12 @@ public function denormalize(mixed $data, string $type, string $format = null, ar ); } - public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool - { + public function supportsDenormalization( + mixed $data, + string $type, + ?string $format = null, + array $context = [] + ): bool { return $type === AttestationObject::class; } diff --git a/web-auth/webauthn-lib/src/Denormalizer/AttestationStatementDenormalizer.php b/web-auth/webauthn-lib/src/Denormalizer/AttestationStatementDenormalizer.php index fea020bce..fc3d0be0a 100644 --- a/web-auth/webauthn-lib/src/Denormalizer/AttestationStatementDenormalizer.php +++ b/web-auth/webauthn-lib/src/Denormalizer/AttestationStatementDenormalizer.php @@ -15,15 +15,19 @@ public function __construct( ) { } - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { $attestationStatementSupport = $this->attestationStatementSupportManager->get($data['fmt']); return $attestationStatementSupport->load($data); } - public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool - { + public function supportsDenormalization( + mixed $data, + string $type, + ?string $format = null, + array $context = [] + ): bool { return $type === AttestationStatement::class; } diff --git a/web-auth/webauthn-lib/src/Denormalizer/AuthenticationExtensionsDenormalizer.php b/web-auth/webauthn-lib/src/Denormalizer/AuthenticationExtensionsDenormalizer.php index e5bacefda..9c2e80a5d 100644 --- a/web-auth/webauthn-lib/src/Denormalizer/AuthenticationExtensionsDenormalizer.php +++ b/web-auth/webauthn-lib/src/Denormalizer/AuthenticationExtensionsDenormalizer.php @@ -17,7 +17,7 @@ final class AuthenticationExtensionsDenormalizer implements DenormalizerInterface, NormalizerInterface { - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { if ($data instanceof AuthenticationExtensions) { return AuthenticationExtensions::create($data->extensions); @@ -33,8 +33,12 @@ public function denormalize(mixed $data, string $type, string $format = null, ar return AuthenticationExtensions::create($data); } - public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool - { + public function supportsDenormalization( + mixed $data, + string $type, + ?string $format = null, + array $context = [] + ): bool { return in_array( $type, [ diff --git a/web-auth/webauthn-lib/src/Denormalizer/AuthenticatorAssertionResponseDenormalizer.php b/web-auth/webauthn-lib/src/Denormalizer/AuthenticatorAssertionResponseDenormalizer.php index 613331c7a..fd8927ff2 100644 --- a/web-auth/webauthn-lib/src/Denormalizer/AuthenticatorAssertionResponseDenormalizer.php +++ b/web-auth/webauthn-lib/src/Denormalizer/AuthenticatorAssertionResponseDenormalizer.php @@ -18,7 +18,7 @@ final class AuthenticatorAssertionResponseDenormalizer implements DenormalizerIn { use DenormalizerAwareTrait; - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { $data['authenticatorData'] = Base64::decode($data['authenticatorData']); $data['signature'] = Base64::decode($data['signature']); @@ -42,8 +42,12 @@ public function denormalize(mixed $data, string $type, string $format = null, ar ); } - public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool - { + public function supportsDenormalization( + mixed $data, + string $type, + ?string $format = null, + array $context = [] + ): bool { return $type === AuthenticatorAssertionResponse::class; } diff --git a/web-auth/webauthn-lib/src/Denormalizer/AuthenticatorAttestationResponseDenormalizer.php b/web-auth/webauthn-lib/src/Denormalizer/AuthenticatorAttestationResponseDenormalizer.php index 5f6569dc7..a634fb6a9 100644 --- a/web-auth/webauthn-lib/src/Denormalizer/AuthenticatorAttestationResponseDenormalizer.php +++ b/web-auth/webauthn-lib/src/Denormalizer/AuthenticatorAttestationResponseDenormalizer.php @@ -17,7 +17,7 @@ final class AuthenticatorAttestationResponseDenormalizer implements Denormalizer { use DenormalizerAwareTrait; - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { $data['clientDataJSON'] = Base64UrlSafe::decodeNoPadding($data['clientDataJSON']); $data['attestationObject'] = Base64::decode($data['attestationObject']); @@ -42,8 +42,12 @@ public function denormalize(mixed $data, string $type, string $format = null, ar ); } - public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool - { + public function supportsDenormalization( + mixed $data, + string $type, + ?string $format = null, + array $context = [] + ): bool { return $type === AuthenticatorAttestationResponse::class; } diff --git a/web-auth/webauthn-lib/src/Denormalizer/AuthenticatorDataDenormalizer.php b/web-auth/webauthn-lib/src/Denormalizer/AuthenticatorDataDenormalizer.php index f13450d0d..12aa21e06 100644 --- a/web-auth/webauthn-lib/src/Denormalizer/AuthenticatorDataDenormalizer.php +++ b/web-auth/webauthn-lib/src/Denormalizer/AuthenticatorDataDenormalizer.php @@ -35,7 +35,7 @@ public function __construct() $this->decoder = Decoder::create(); } - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { $authData = $this->fixIncorrectEdDSAKey($data); $authDataStream = new StringStream($authData); @@ -87,8 +87,12 @@ public function denormalize(mixed $data, string $type, string $format = null, ar ); } - public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool - { + public function supportsDenormalization( + mixed $data, + string $type, + ?string $format = null, + array $context = [] + ): bool { return $type === AuthenticatorData::class; } diff --git a/web-auth/webauthn-lib/src/Denormalizer/AuthenticatorResponseDenormalizer.php b/web-auth/webauthn-lib/src/Denormalizer/AuthenticatorResponseDenormalizer.php index 6a47309d5..63d152def 100644 --- a/web-auth/webauthn-lib/src/Denormalizer/AuthenticatorResponseDenormalizer.php +++ b/web-auth/webauthn-lib/src/Denormalizer/AuthenticatorResponseDenormalizer.php @@ -17,7 +17,7 @@ final class AuthenticatorResponseDenormalizer implements DenormalizerInterface, { use DenormalizerAwareTrait; - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { $realType = match (true) { array_key_exists('attestationObject', $data) => AuthenticatorAttestationResponse::class, @@ -28,8 +28,12 @@ public function denormalize(mixed $data, string $type, string $format = null, ar return $this->denormalizer->denormalize($data, $realType, $format, $context); } - public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool - { + public function supportsDenormalization( + mixed $data, + string $type, + ?string $format = null, + array $context = [] + ): bool { return $type === AuthenticatorResponse::class; } diff --git a/web-auth/webauthn-lib/src/Denormalizer/CollectedClientDataDenormalizer.php b/web-auth/webauthn-lib/src/Denormalizer/CollectedClientDataDenormalizer.php index e9e5264cd..fec3a7481 100644 --- a/web-auth/webauthn-lib/src/Denormalizer/CollectedClientDataDenormalizer.php +++ b/web-auth/webauthn-lib/src/Denormalizer/CollectedClientDataDenormalizer.php @@ -14,13 +14,17 @@ final class CollectedClientDataDenormalizer implements DenormalizerInterface, De { use DenormalizerAwareTrait; - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { return CollectedClientData::create($data, json_decode($data, true, flags: JSON_THROW_ON_ERROR)); } - public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool - { + public function supportsDenormalization( + mixed $data, + string $type, + ?string $format = null, + array $context = [] + ): bool { return $type === CollectedClientData::class; } diff --git a/web-auth/webauthn-lib/src/Denormalizer/ExtensionDescriptorDenormalizer.php b/web-auth/webauthn-lib/src/Denormalizer/ExtensionDescriptorDenormalizer.php index 4109ffb44..d67afd910 100644 --- a/web-auth/webauthn-lib/src/Denormalizer/ExtensionDescriptorDenormalizer.php +++ b/web-auth/webauthn-lib/src/Denormalizer/ExtensionDescriptorDenormalizer.php @@ -19,7 +19,7 @@ class ExtensionDescriptorDenormalizer implements DenormalizerInterface, Denormal private const ALREADY_CALLED = 'EXTENSION_DESCRIPTOR_PREPROCESS_ALREADY_CALLED'; - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { if (array_key_exists('fail_if_unknown', $data)) { $data['failIfUnknown'] = $data['fail_if_unknown']; @@ -31,8 +31,12 @@ public function denormalize(mixed $data, string $type, string $format = null, ar return $this->denormalizer->denormalize($data, $type, $format, $context); } - public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool - { + public function supportsDenormalization( + mixed $data, + string $type, + ?string $format = null, + array $context = [] + ): bool { if ($context[self::ALREADY_CALLED] ?? false) { return false; } diff --git a/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialDenormalizer.php b/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialDenormalizer.php index 33899b707..ba5508927 100644 --- a/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialDenormalizer.php +++ b/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialDenormalizer.php @@ -18,7 +18,7 @@ final class PublicKeyCredentialDenormalizer implements DenormalizerInterface, De { use DenormalizerAwareTrait; - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { if (! array_key_exists('id', $data)) { return $data; @@ -36,8 +36,12 @@ public function denormalize(mixed $data, string $type, string $format = null, ar ); } - public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool - { + public function supportsDenormalization( + mixed $data, + string $type, + ?string $format = null, + array $context = [] + ): bool { return $type === PublicKeyCredential::class; } diff --git a/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialOptionsDenormalizer.php b/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialOptionsDenormalizer.php index 1b59091d5..326a37378 100644 --- a/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialOptionsDenormalizer.php +++ b/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialOptionsDenormalizer.php @@ -29,7 +29,7 @@ final class PublicKeyCredentialOptionsDenormalizer implements DenormalizerInterf use DenormalizerAwareTrait; use NormalizerAwareTrait; - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { if (array_key_exists('challenge', $data)) { $data['challenge'] = Base64UrlSafe::decodeNoPadding($data['challenge']); @@ -103,8 +103,12 @@ public function denormalize(mixed $data, string $type, string $format = null, ar throw new BadMethodCallException('Unsupported type'); } - public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool - { + public function supportsDenormalization( + mixed $data, + string $type, + ?string $format = null, + array $context = [] + ): bool { return in_array( $type, [PublicKeyCredentialCreationOptions::class, PublicKeyCredentialRequestOptions::class], diff --git a/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialParametersDenormalizer.php b/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialParametersDenormalizer.php index b5d640688..0114c3a6a 100644 --- a/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialParametersDenormalizer.php +++ b/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialParametersDenormalizer.php @@ -11,7 +11,7 @@ final class PublicKeyCredentialParametersDenormalizer implements DenormalizerInterface { - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { if (! array_key_exists('type', $data) || ! array_key_exists('alg', $data)) { throw new InvalidDataException($data, 'Missing type or alg'); @@ -20,8 +20,12 @@ public function denormalize(mixed $data, string $type, string $format = null, ar return PublicKeyCredentialParameters::create($data['type'], $data['alg']); } - public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool - { + public function supportsDenormalization( + mixed $data, + string $type, + ?string $format = null, + array $context = [] + ): bool { return $type === PublicKeyCredentialParameters::class; } diff --git a/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialSourceDenormalizer.php b/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialSourceDenormalizer.php index bf8a5ae3d..3a963afa6 100644 --- a/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialSourceDenormalizer.php +++ b/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialSourceDenormalizer.php @@ -24,7 +24,7 @@ final class PublicKeyCredentialSourceDenormalizer implements DenormalizerInterfa use NormalizerAwareTrait; use DenormalizerAwareTrait; - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { $keys = ['publicKeyCredentialId', 'credentialPublicKey', 'userHandle']; foreach ($keys as $key) { @@ -49,8 +49,12 @@ public function denormalize(mixed $data, string $type, string $format = null, ar ); } - public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool - { + public function supportsDenormalization( + mixed $data, + string $type, + ?string $format = null, + array $context = [] + ): bool { return $type === PublicKeyCredentialSource::class; } diff --git a/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialUserEntityDenormalizer.php b/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialUserEntityDenormalizer.php index 275b2548a..0ac7f5d12 100644 --- a/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialUserEntityDenormalizer.php +++ b/web-auth/webauthn-lib/src/Denormalizer/PublicKeyCredentialUserEntityDenormalizer.php @@ -14,7 +14,7 @@ final class PublicKeyCredentialUserEntityDenormalizer implements DenormalizerInterface, NormalizerInterface { - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { if (! array_key_exists('id', $data)) { return $data; @@ -29,8 +29,12 @@ public function denormalize(mixed $data, string $type, string $format = null, ar ); } - public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool - { + public function supportsDenormalization( + mixed $data, + string $type, + ?string $format = null, + array $context = [] + ): bool { return $type === PublicKeyCredentialUserEntity::class; } diff --git a/web-auth/webauthn-lib/src/Denormalizer/TrustPathDenormalizer.php b/web-auth/webauthn-lib/src/Denormalizer/TrustPathDenormalizer.php index 741dbcd83..4a565ed88 100644 --- a/web-auth/webauthn-lib/src/Denormalizer/TrustPathDenormalizer.php +++ b/web-auth/webauthn-lib/src/Denormalizer/TrustPathDenormalizer.php @@ -16,7 +16,7 @@ final class TrustPathDenormalizer implements DenormalizerInterface, NormalizerInterface { - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed { return match (true) { array_key_exists('ecdaaKeyId', $data) => new EcdaaKeyIdTrustPath($data), @@ -26,8 +26,12 @@ public function denormalize(mixed $data, string $type, string $format = null, ar }; } - public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool - { + public function supportsDenormalization( + mixed $data, + string $type, + ?string $format = null, + array $context = [] + ): bool { return $type === TrustPath::class; } diff --git a/web-auth/webauthn-lib/src/Denormalizer/WebauthnSerializerFactory.php b/web-auth/webauthn-lib/src/Denormalizer/WebauthnSerializerFactory.php index be9f7ce26..f7dc10915 100644 --- a/web-auth/webauthn-lib/src/Denormalizer/WebauthnSerializerFactory.php +++ b/web-auth/webauthn-lib/src/Denormalizer/WebauthnSerializerFactory.php @@ -15,6 +15,7 @@ use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\SerializerInterface; use Webauthn\AttestationStatement\AttestationStatementSupportManager; +use function sprintf; final class WebauthnSerializerFactory { diff --git a/web-auth/webauthn-lib/src/Event/AuthenticatorAssertionResponseValidationFailedEvent.php b/web-auth/webauthn-lib/src/Event/AuthenticatorAssertionResponseValidationFailedEvent.php index fb542c43a..f46b6d7de 100644 --- a/web-auth/webauthn-lib/src/Event/AuthenticatorAssertionResponseValidationFailedEvent.php +++ b/web-auth/webauthn-lib/src/Event/AuthenticatorAssertionResponseValidationFailedEvent.php @@ -9,6 +9,7 @@ use Webauthn\AuthenticatorAssertionResponse; use Webauthn\PublicKeyCredentialRequestOptions; use Webauthn\PublicKeyCredentialSource; +use function sprintf; class AuthenticatorAssertionResponseValidationFailedEvent { diff --git a/web-auth/webauthn-lib/src/Event/AuthenticatorAssertionResponseValidationSucceededEvent.php b/web-auth/webauthn-lib/src/Event/AuthenticatorAssertionResponseValidationSucceededEvent.php index 88442b171..75925582a 100644 --- a/web-auth/webauthn-lib/src/Event/AuthenticatorAssertionResponseValidationSucceededEvent.php +++ b/web-auth/webauthn-lib/src/Event/AuthenticatorAssertionResponseValidationSucceededEvent.php @@ -8,6 +8,7 @@ use Webauthn\AuthenticatorAssertionResponse; use Webauthn\PublicKeyCredentialRequestOptions; use Webauthn\PublicKeyCredentialSource; +use function sprintf; class AuthenticatorAssertionResponseValidationSucceededEvent { diff --git a/web-auth/webauthn-lib/src/Event/AuthenticatorAttestationResponseValidationFailedEvent.php b/web-auth/webauthn-lib/src/Event/AuthenticatorAttestationResponseValidationFailedEvent.php index 59f7403b9..3c8168d5c 100644 --- a/web-auth/webauthn-lib/src/Event/AuthenticatorAttestationResponseValidationFailedEvent.php +++ b/web-auth/webauthn-lib/src/Event/AuthenticatorAttestationResponseValidationFailedEvent.php @@ -8,6 +8,7 @@ use Throwable; use Webauthn\AuthenticatorAttestationResponse; use Webauthn\PublicKeyCredentialCreationOptions; +use function sprintf; class AuthenticatorAttestationResponseValidationFailedEvent { diff --git a/web-auth/webauthn-lib/src/Event/AuthenticatorAttestationResponseValidationSucceededEvent.php b/web-auth/webauthn-lib/src/Event/AuthenticatorAttestationResponseValidationSucceededEvent.php index 59cca9516..6145464ec 100644 --- a/web-auth/webauthn-lib/src/Event/AuthenticatorAttestationResponseValidationSucceededEvent.php +++ b/web-auth/webauthn-lib/src/Event/AuthenticatorAttestationResponseValidationSucceededEvent.php @@ -8,6 +8,7 @@ use Webauthn\AuthenticatorAttestationResponse; use Webauthn\PublicKeyCredentialCreationOptions; use Webauthn\PublicKeyCredentialSource; +use function sprintf; class AuthenticatorAttestationResponseValidationSucceededEvent { diff --git a/web-auth/webauthn-lib/src/MetadataService/CertificateChain/PhpCertificateChainValidator.php b/web-auth/webauthn-lib/src/MetadataService/CertificateChain/PhpCertificateChainValidator.php index b7a676d1b..ff50e7e7d 100644 --- a/web-auth/webauthn-lib/src/MetadataService/CertificateChain/PhpCertificateChainValidator.php +++ b/web-auth/webauthn-lib/src/MetadataService/CertificateChain/PhpCertificateChainValidator.php @@ -29,6 +29,7 @@ use function count; use function in_array; use function parse_url; +use function sprintf; use const PHP_EOL; use const PHP_URL_SCHEME; diff --git a/web-auth/webauthn-lib/src/MetadataService/Psr18HttpClient.php b/web-auth/webauthn-lib/src/MetadataService/Psr18HttpClient.php index 1f0b6f718..c296bb1f8 100644 --- a/web-auth/webauthn-lib/src/MetadataService/Psr18HttpClient.php +++ b/web-auth/webauthn-lib/src/MetadataService/Psr18HttpClient.php @@ -54,7 +54,7 @@ public function request(string $method, string $url, array $options = []): Respo /** * @param ResponseInterface|iterable $responses */ - public function stream(iterable|ResponseInterface $responses, float $timeout = null): ResponseStreamInterface + public function stream(iterable|ResponseInterface $responses, ?float $timeout = null): ResponseStreamInterface { throw new LogicException('Not implemented'); } @@ -119,7 +119,7 @@ public function cancel(): void // noop } - public function getInfo(string $type = null): mixed + public function getInfo(?string $type = null): mixed { return null; } diff --git a/web-auth/webauthn-lib/src/MetadataService/Service/MetadataBLOBPayload.php b/web-auth/webauthn-lib/src/MetadataService/Service/MetadataBLOBPayload.php index 0bd5df806..97df91c57 100644 --- a/web-auth/webauthn-lib/src/MetadataService/Service/MetadataBLOBPayload.php +++ b/web-auth/webauthn-lib/src/MetadataService/Service/MetadataBLOBPayload.php @@ -11,6 +11,7 @@ use function is_array; use function is_int; use function is_string; +use function sprintf; class MetadataBLOBPayload implements JsonSerializable { diff --git a/web-auth/webauthn-lib/src/MetadataService/Statement/DisplayPNGCharacteristicsDescriptor.php b/web-auth/webauthn-lib/src/MetadataService/Statement/DisplayPNGCharacteristicsDescriptor.php index f69703038..e0c8603b3 100644 --- a/web-auth/webauthn-lib/src/MetadataService/Statement/DisplayPNGCharacteristicsDescriptor.php +++ b/web-auth/webauthn-lib/src/MetadataService/Statement/DisplayPNGCharacteristicsDescriptor.php @@ -8,6 +8,7 @@ use Webauthn\Exception\MetadataStatementLoadingException; use Webauthn\MetadataService\ValueFilter; use function array_key_exists; +use function sprintf; class DisplayPNGCharacteristicsDescriptor implements JsonSerializable { diff --git a/web-auth/webauthn-lib/src/MetadataService/Statement/EcdaaTrustAnchor.php b/web-auth/webauthn-lib/src/MetadataService/Statement/EcdaaTrustAnchor.php index c55171b32..2d565d314 100644 --- a/web-auth/webauthn-lib/src/MetadataService/Statement/EcdaaTrustAnchor.php +++ b/web-auth/webauthn-lib/src/MetadataService/Statement/EcdaaTrustAnchor.php @@ -9,6 +9,7 @@ use Webauthn\Exception\MetadataStatementLoadingException; use Webauthn\MetadataService\ValueFilter; use function array_key_exists; +use function sprintf; /** * @deprecated since 4.2.0 and will be removed in 5.0.0. The ECDAA Trust Anchor does no longer exist in Webauthn specification. diff --git a/web-auth/webauthn-lib/src/MetadataService/Statement/MetadataStatement.php b/web-auth/webauthn-lib/src/MetadataService/Statement/MetadataStatement.php index 899430eaf..5f6afd509 100644 --- a/web-auth/webauthn-lib/src/MetadataService/Statement/MetadataStatement.php +++ b/web-auth/webauthn-lib/src/MetadataService/Statement/MetadataStatement.php @@ -11,6 +11,7 @@ use function array_key_exists; use function is_array; use function is_string; +use function sprintf; use const JSON_THROW_ON_ERROR; class MetadataStatement implements JsonSerializable diff --git a/web-auth/webauthn-lib/src/MetadataService/Statement/PatternAccuracyDescriptor.php b/web-auth/webauthn-lib/src/MetadataService/Statement/PatternAccuracyDescriptor.php index f065bbeec..8ceed8b8d 100644 --- a/web-auth/webauthn-lib/src/MetadataService/Statement/PatternAccuracyDescriptor.php +++ b/web-auth/webauthn-lib/src/MetadataService/Statement/PatternAccuracyDescriptor.php @@ -8,6 +8,7 @@ use Webauthn\MetadataService\ValueFilter; use function array_key_exists; use function is_int; +use function sprintf; class PatternAccuracyDescriptor extends AbstractDescriptor { diff --git a/web-auth/webauthn-lib/src/MetadataService/Statement/RgbPaletteEntry.php b/web-auth/webauthn-lib/src/MetadataService/Statement/RgbPaletteEntry.php index ca850789a..73061b44a 100644 --- a/web-auth/webauthn-lib/src/MetadataService/Statement/RgbPaletteEntry.php +++ b/web-auth/webauthn-lib/src/MetadataService/Statement/RgbPaletteEntry.php @@ -8,6 +8,7 @@ use Webauthn\Exception\MetadataStatementLoadingException; use function array_key_exists; use function is_int; +use function sprintf; class RgbPaletteEntry implements JsonSerializable { diff --git a/web-auth/webauthn-lib/src/MetadataService/Statement/StatusReport.php b/web-auth/webauthn-lib/src/MetadataService/Statement/StatusReport.php index c1fba596d..0ab13517a 100644 --- a/web-auth/webauthn-lib/src/MetadataService/Statement/StatusReport.php +++ b/web-auth/webauthn-lib/src/MetadataService/Statement/StatusReport.php @@ -10,6 +10,7 @@ use function array_key_exists; use function in_array; use function is_string; +use function sprintf; class StatusReport implements JsonSerializable { @@ -62,6 +63,7 @@ public function isCompromised(): bool AuthenticatorStatus::USER_KEY_PHYSICAL_COMPROMISE, AuthenticatorStatus::USER_KEY_REMOTE_COMPROMISE, AuthenticatorStatus::USER_VERIFICATION_BYPASS, + AuthenticatorStatus::REVOKED, ], true); } diff --git a/web-auth/webauthn-lib/src/MetadataService/Statement/VerificationMethodDescriptor.php b/web-auth/webauthn-lib/src/MetadataService/Statement/VerificationMethodDescriptor.php index fe700f833..89184644f 100644 --- a/web-auth/webauthn-lib/src/MetadataService/Statement/VerificationMethodDescriptor.php +++ b/web-auth/webauthn-lib/src/MetadataService/Statement/VerificationMethodDescriptor.php @@ -9,6 +9,7 @@ use Webauthn\MetadataService\ValueFilter; use function array_key_exists; use function is_array; +use function sprintf; class VerificationMethodDescriptor implements JsonSerializable { diff --git a/web-auth/webauthn-lib/src/MetadataService/Statement/Version.php b/web-auth/webauthn-lib/src/MetadataService/Statement/Version.php index 1a0f77153..56b7b0faf 100644 --- a/web-auth/webauthn-lib/src/MetadataService/Statement/Version.php +++ b/web-auth/webauthn-lib/src/MetadataService/Statement/Version.php @@ -9,6 +9,7 @@ use Webauthn\MetadataService\ValueFilter; use function array_key_exists; use function is_int; +use function sprintf; class Version implements JsonSerializable { diff --git a/web-auth/webauthn-lib/src/PublicKeyCredential.php b/web-auth/webauthn-lib/src/PublicKeyCredential.php index 8e09ad656..b4930f803 100644 --- a/web-auth/webauthn-lib/src/PublicKeyCredential.php +++ b/web-auth/webauthn-lib/src/PublicKeyCredential.php @@ -5,6 +5,7 @@ namespace Webauthn; use Stringable; +use function sprintf; use const E_USER_DEPRECATED; use const JSON_THROW_ON_ERROR; diff --git a/web-auth/webauthn-lib/src/PublicKeyCredentialLoader.php b/web-auth/webauthn-lib/src/PublicKeyCredentialLoader.php index 88b2a9c17..8c28d5389 100644 --- a/web-auth/webauthn-lib/src/PublicKeyCredentialLoader.php +++ b/web-auth/webauthn-lib/src/PublicKeyCredentialLoader.php @@ -17,6 +17,7 @@ use function array_key_exists; use function is_array; use function is_string; +use function sprintf; use const JSON_THROW_ON_ERROR; /** diff --git a/web-auth/webauthn-lib/src/PublicKeyCredentialSource.php b/web-auth/webauthn-lib/src/PublicKeyCredentialSource.php index 2aef84ef0..fe1ab1808 100644 --- a/web-auth/webauthn-lib/src/PublicKeyCredentialSource.php +++ b/web-auth/webauthn-lib/src/PublicKeyCredentialSource.php @@ -13,6 +13,7 @@ use Webauthn\TrustPath\TrustPathLoader; use function array_key_exists; use function in_array; +use function sprintf; /** * @see https://www.w3.org/TR/webauthn/#iface-pkcredential diff --git a/web-auth/webauthn-lib/src/StringStream.php b/web-auth/webauthn-lib/src/StringStream.php index 06784e7c8..44f718515 100644 --- a/web-auth/webauthn-lib/src/StringStream.php +++ b/web-auth/webauthn-lib/src/StringStream.php @@ -11,6 +11,7 @@ use function fread; use function fwrite; use function rewind; +use function sprintf; final class StringStream implements Stream { diff --git a/web-auth/webauthn-lib/src/TokenBinding/TokenBinding.php b/web-auth/webauthn-lib/src/TokenBinding/TokenBinding.php index cffc6ded5..26a2cb7b4 100644 --- a/web-auth/webauthn-lib/src/TokenBinding/TokenBinding.php +++ b/web-auth/webauthn-lib/src/TokenBinding/TokenBinding.php @@ -8,6 +8,7 @@ use Webauthn\Exception\InvalidDataException; use function array_key_exists; use function in_array; +use function sprintf; /** * @deprecated Since 4.3.0 and will be removed in 5.0.0