From 1cb3e5c36e3a0b24dfacb84ddb840ff11504c8f4 Mon Sep 17 00:00:00 2001 From: Paragon Initiative Enterprises Date: Tue, 23 Apr 2024 19:27:13 -0400 Subject: [PATCH] Add Psalm to workflows --- .github/workflows/psalm.yml | 30 +++++++ README.md | 1 + composer.json | 1 + psalm.xml | 23 +++++ src/Math/DebugDecorator.php | 2 + src/Math/GmpMath.php | 83 ++++++++++--------- src/Primitives/CurveFp.php | 8 +- src/Primitives/Point.php | 28 +++---- src/Random/HmacRandomNumberGenerator.php | 29 +++---- .../Point/CompressedPointSerializer.php | 8 +- .../Point/UncompressedPointSerializer.php | 14 ++-- .../PrivateKey/DerPrivateKeySerializer.php | 4 +- .../PublicKey/DerPublicKeySerializer.php | 4 +- src/Serializer/Util/CurveOidMapper.php | 3 + src/Util/NumberSize.php | 6 ++ 15 files changed, 156 insertions(+), 88 deletions(-) create mode 100644 .github/workflows/psalm.yml create mode 100644 psalm.xml diff --git a/.github/workflows/psalm.yml b/.github/workflows/psalm.yml new file mode 100644 index 00000000..0a503c43 --- /dev/null +++ b/.github/workflows/psalm.yml @@ -0,0 +1,30 @@ +name: Psalm + +on: [push] + +jobs: + psalm: + name: Psalm on PHP ${{ matrix.php-versions }} + runs-on: ${{ matrix.operating-system }} + strategy: + matrix: + operating-system: ['ubuntu-latest'] + php-versions: ['8.3'] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + tools: psalm:4 + coverage: none + + - name: Install Composer dependencies + uses: "ramsey/composer-install@v2" + with: + composer-options: --no-dev + + - name: Static Analysis + run: psalm diff --git a/README.md b/README.md index f056e8fa..c7ece585 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Pure PHP Elliptic Curve DSA and DH [![Build Status](https://github.com/paragonie/phpecc/actions/workflows/test.yml/badge.svg)](https://github.com/paragonie/phpecc/actions) +[![Type Safety](https://github.com/paragonie/phpecc/actions/workflows/psalm.yml/badge.svg)](https://github.com/paragonie/phpecc/actions) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/paragonie/phpecc/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/paragonie/phpecc?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/paragonie/phpecc/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/phpecc/phpecc/?branch=master) diff --git a/composer.json b/composer.json index 96cff220..9248b601 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,7 @@ "phpunit/phpunit": "^6.0||^8.0||^9.0", "squizlabs/php_codesniffer": "^2.0", "symfony/yaml": "^2.6|^3.0", + "vimeo/psalm": "^4|^5", "ext-json": "*" }, "autoload": { diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 00000000..bcf0e000 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + diff --git a/src/Math/DebugDecorator.php b/src/Math/DebugDecorator.php index a3d7aead..b5ef98c2 100644 --- a/src/Math/DebugDecorator.php +++ b/src/Math/DebugDecorator.php @@ -45,6 +45,8 @@ private function write($message) * @param string $func * @param array $args * @return mixed + * + * @psalm-suppress UnusedReturnValue */ private function call($func, $args) { diff --git a/src/Math/GmpMath.php b/src/Math/GmpMath.php index 250f7f04..da7afb82 100644 --- a/src/Math/GmpMath.php +++ b/src/Math/GmpMath.php @@ -2,6 +2,7 @@ namespace Mdanter\Ecc\Math; +use GMP; use Mdanter\Ecc\Util\BinaryString; use Mdanter\Ecc\Util\NumberSize; @@ -11,17 +12,17 @@ class GmpMath implements GmpMathInterface * {@inheritDoc} * @see GmpMathInterface::cmp() */ - public function cmp(\GMP $first, \GMP $other): int + public function cmp(GMP $first, GMP $other): int { return gmp_cmp($first, $other); } /** - * @param \GMP $first - * @param \GMP $other + * @param GMP $first + * @param GMP $other * @return bool */ - public function equals(\GMP $first, \GMP $other): bool + public function equals(GMP $first, GMP $other): bool { return gmp_cmp($first, $other) === 0; } @@ -30,7 +31,7 @@ public function equals(\GMP $first, \GMP $other): bool * {@inheritDoc} * @see GmpMathInterface::mod() */ - public function mod(\GMP $number, \GMP $modulus): \GMP + public function mod(GMP $number, GMP $modulus): GMP { return gmp_mod($number, $modulus); } @@ -39,7 +40,7 @@ public function mod(\GMP $number, \GMP $modulus): \GMP * {@inheritDoc} * @see GmpMathInterface::add() */ - public function add(\GMP $augend, \GMP $addend): \GMP + public function add(GMP $augend, GMP $addend): GMP { return gmp_add($augend, $addend); } @@ -48,7 +49,7 @@ public function add(\GMP $augend, \GMP $addend): \GMP * {@inheritDoc} * @see GmpMathInterface::sub() */ - public function sub(\GMP $minuend, \GMP $subtrahend): \GMP + public function sub(GMP $minuend, GMP $subtrahend): GMP { return gmp_sub($minuend, $subtrahend); } @@ -57,7 +58,7 @@ public function sub(\GMP $minuend, \GMP $subtrahend): \GMP * {@inheritDoc} * @see GmpMathInterface::mul() */ - public function mul(\GMP $multiplier, \GMP $multiplicand): \GMP + public function mul(GMP $multiplier, GMP $multiplicand): GMP { return gmp_mul($multiplier, $multiplicand); } @@ -66,7 +67,7 @@ public function mul(\GMP $multiplier, \GMP $multiplicand): \GMP * {@inheritDoc} * @see GmpMathInterface::div() */ - public function div(\GMP $dividend, \GMP $divisor): \GMP + public function div(GMP $dividend, GMP $divisor): GMP { return gmp_div($dividend, $divisor); } @@ -75,7 +76,7 @@ public function div(\GMP $dividend, \GMP $divisor): \GMP * {@inheritDoc} * @see GmpMathInterface::pow() */ - public function pow(\GMP $base, int $exponent): \GMP + public function pow(GMP $base, int $exponent): GMP { return gmp_pow($base, $exponent); } @@ -84,7 +85,7 @@ public function pow(\GMP $base, int $exponent): \GMP * {@inheritDoc} * @see GmpMathInterface::bitwiseAnd() */ - public function bitwiseAnd(\GMP $first, \GMP $other): \GMP + public function bitwiseAnd(GMP $first, GMP $other): GMP { return gmp_and($first, $other); } @@ -93,7 +94,7 @@ public function bitwiseAnd(\GMP $first, \GMP $other): \GMP * {@inheritDoc} * @see GmpMathInterface::rightShift() */ - public function rightShift(\GMP $number, int $positions): \GMP + public function rightShift(GMP $number, int $positions): GMP { // Shift 1 right = div / 2 return gmp_div($number, gmp_pow(gmp_init(2, 10), $positions)); @@ -103,7 +104,7 @@ public function rightShift(\GMP $number, int $positions): \GMP * {@inheritDoc} * @see GmpMathInterface::bitwiseXor() */ - public function bitwiseXor(\GMP $first, \GMP $other): \GMP + public function bitwiseXor(GMP $first, GMP $other): GMP { return gmp_xor($first, $other); } @@ -112,7 +113,7 @@ public function bitwiseXor(\GMP $first, \GMP $other): \GMP * {@inheritDoc} * @see GmpMathInterface::leftShift() */ - public function leftShift(\GMP $number, int $positions): \GMP + public function leftShift(GMP $number, int $positions): GMP { // Shift 1 left = mul by 2 return gmp_mul($number, gmp_pow(2, $positions)); @@ -122,7 +123,7 @@ public function leftShift(\GMP $number, int $positions): \GMP * {@inheritDoc} * @see GmpMathInterface::toString() */ - public function toString(\GMP $value): string + public function toString(GMP $value): string { return gmp_strval($value); } @@ -131,24 +132,24 @@ public function toString(\GMP $value): string * {@inheritDoc} * @see GmpMathInterface::hexDec() */ - public function hexDec(string $hex): string + public function hexDec(string $hexString): string { - return gmp_strval(gmp_init($hex, 16), 10); + return gmp_strval(gmp_init($hexString, 16), 10); } /** * {@inheritDoc} * @see GmpMathInterface::decHex() */ - public function decHex(string $dec): string + public function decHex(string $decString): string { - $dec = gmp_init($dec, 10); + $decString = gmp_init($decString, 10); - if (gmp_cmp($dec, 0) < 0) { + if (gmp_cmp($decString, 0) < 0) { throw new \InvalidArgumentException('Unable to convert negative integer to string'); } - $hex = gmp_strval($dec, 16); + $hex = gmp_strval($decString, 16); if (BinaryString::length($hex) % 2 != 0) { $hex = '0'.$hex; @@ -161,7 +162,7 @@ public function decHex(string $dec): string * {@inheritDoc} * @see GmpMathInterface::powmod() */ - public function powmod(\GMP $base, \GMP $exponent, \GMP $modulus): \GMP + public function powmod(GMP $base, GMP $exponent, GMP $modulus): GMP { if ($this->cmp($exponent, gmp_init(0, 10)) < 0) { throw new \InvalidArgumentException("Negative exponents (" . $this->toString($exponent) . ") not allowed."); @@ -174,7 +175,7 @@ public function powmod(\GMP $base, \GMP $exponent, \GMP $modulus): \GMP * {@inheritDoc} * @see GmpMathInterface::isPrime() */ - public function isPrime(\GMP $n): bool + public function isPrime(GMP $n): bool { $prob = gmp_prob_prime($n); @@ -189,16 +190,16 @@ public function isPrime(\GMP $n): bool * {@inheritDoc} * @see GmpMathInterface::nextPrime() */ - public function nextPrime(\GMP $starting_value): \GMP + public function nextPrime(GMP $currentPrime): GMP { - return gmp_nextprime($starting_value); + return gmp_nextprime($currentPrime); } /** * {@inheritDoc} * @see GmpMathInterface::inverseMod() */ - public function inverseMod(\GMP $a, \GMP $m): \GMP + public function inverseMod(GMP $a, GMP $m): GMP { return gmp_invert($a, $m); } @@ -207,17 +208,17 @@ public function inverseMod(\GMP $a, \GMP $m): \GMP * {@inheritDoc} * @see GmpMathInterface::jacobi() */ - public function jacobi(\GMP $a, \GMP $n): int + public function jacobi(GMP $a, GMP $p): int { - return gmp_jacobi($a, $n); + return gmp_jacobi($a, $p); } /** - * @param \GMP $x + * @param GMP $x * @param int $byteSize * @return string */ - public function intToFixedSizeString(\GMP $x, int $byteSize): string + public function intToFixedSizeString(GMP $x, int $byteSize): string { if ($byteSize < 0) { throw new \RuntimeException("Byte size cannot be negative"); @@ -249,7 +250,7 @@ public function intToFixedSizeString(\GMP $x, int $byteSize): string * {@inheritDoc} * @see GmpMathInterface::intToString() */ - public function intToString(\GMP $x): string + public function intToString(GMP $x): string { if (gmp_cmp($x, 0) < 0) { throw new \InvalidArgumentException('Unable to convert negative integer to string'); @@ -268,7 +269,7 @@ public function intToString(\GMP $x): string * {@inheritDoc} * @see GmpMathInterface::stringToInt() */ - public function stringToInt(string $s): \GMP + public function stringToInt(string $s): GMP { $result = gmp_init(0, 10); $sLen = BinaryString::length($s); @@ -284,7 +285,7 @@ public function stringToInt(string $s): \GMP * {@inheritDoc} * @see GmpMathInterface::digestInteger() */ - public function digestInteger(\GMP $m): \GMP + public function digestInteger(GMP $m): GMP { return $this->stringToInt(hash('sha1', $this->intToString($m), true)); } @@ -293,24 +294,24 @@ public function digestInteger(\GMP $m): \GMP * {@inheritDoc} * @see GmpMathInterface::gcd2() */ - public function gcd2(\GMP $a, \GMP $b): \GMP + public function gcd2(GMP $a, GMP $m): GMP { while ($this->cmp($a, gmp_init(0)) > 0) { $temp = $a; - $a = $this->mod($b, $a); - $b = $temp; + $a = $this->mod($m, $a); + $m = $temp; } - return $b; + return $m; } /** * {@inheritDoc} * @see GmpMathInterface::baseConvert() */ - public function baseConvert(string $number, int $from, int $to): string + public function baseConvert(string $value, int $fromBase, int $toBase): string { - return gmp_strval(gmp_init($number, $from), $to); + return gmp_strval(gmp_init($value, $fromBase), $toBase); } /** @@ -323,10 +324,10 @@ public function getNumberTheory(): NumberTheory } /** - * @param \GMP $modulus + * @param GMP $modulus * @return ModularArithmetic */ - public function getModularArithmetic(\GMP $modulus): ModularArithmetic + public function getModularArithmetic(GMP $modulus): ModularArithmetic { return new ModularArithmetic($this, $modulus); } diff --git a/src/Primitives/CurveFp.php b/src/Primitives/CurveFp.php index adbcf546..d9bbe256 100644 --- a/src/Primitives/CurveFp.php +++ b/src/Primitives/CurveFp.php @@ -109,10 +109,10 @@ public function getGenerator(GMP $x, GMP $y, GMP $order, ?RandomNumberGeneratorI /** * @param bool $wasOdd - * @param GMP $xCoord + * @param GMP $x * @return GMP */ - public function recoverYfromX(bool $wasOdd, GMP $xCoord): GMP + public function recoverYfromX(bool $wasOdd, GMP $x): GMP { $math = $this->adapter; $prime = $this->getPrime(); @@ -121,8 +121,8 @@ public function recoverYfromX(bool $wasOdd, GMP $xCoord): GMP $root = $this->adapter->getNumberTheory()->squareRootModP( $math->add( $math->add( - $this->modAdapter->pow($xCoord, gmp_init(3, 10)), - $math->mul($this->getA(), $xCoord) + $this->modAdapter->pow($x, gmp_init(3, 10)), + $math->mul($this->getA(), $x) ), $this->getB() ), diff --git a/src/Primitives/Point.php b/src/Primitives/Point.php index 68472da1..8eb79836 100644 --- a/src/Primitives/Point.php +++ b/src/Primitives/Point.php @@ -127,7 +127,7 @@ public function getAdapter(): GmpMathInterface /** * {@inheritDoc} - * @see \Mdanter\Ecc\Primitives\PointInterface::isInfinity() + * @see PointInterface::isInfinity() */ public function isInfinity(): bool { @@ -136,7 +136,7 @@ public function isInfinity(): bool /** * {@inheritDoc} - * @see \Mdanter\Ecc\Primitives\PointInterface::getCurve() + * @see PointInterface::getCurve() */ public function getCurve(): CurveFpInterface { @@ -145,7 +145,7 @@ public function getCurve(): CurveFpInterface /** * {@inheritDoc} - * @see \Mdanter\Ecc\Primitives\PointInterface::getOrder() + * @see PointInterface::getOrder() */ public function getOrder(): GMP { @@ -154,7 +154,7 @@ public function getOrder(): GMP /** * {@inheritDoc} - * @see \Mdanter\Ecc\Primitives\PointInterface::getX() + * @see PointInterface::getX() */ public function getX(): GMP { @@ -163,7 +163,7 @@ public function getX(): GMP /** * {@inheritDoc} - * @see \Mdanter\Ecc\Primitives\PointInterface::getY() + * @see PointInterface::getY() */ public function getY(): GMP { @@ -172,7 +172,7 @@ public function getY(): GMP /** * {@inheritDoc} - * @see \Mdanter\Ecc\Primitives\PointInterface::add() + * @see PointInterface::add() * @return self */ public function add(PointInterface $addend): PointInterface @@ -220,7 +220,7 @@ public function add(PointInterface $addend): PointInterface /** * {@inheritDoc} - * @see \Mdanter\Ecc\Primitives\PointInterface::cmp() + * @see PointInterface::cmp() */ public function cmp(PointInterface $other): int { @@ -247,7 +247,7 @@ public function cmp(PointInterface $other): int /** * {@inheritDoc} - * @see \Mdanter\Ecc\Primitives\PointInterface::equals() + * @see PointInterface::equals() */ public function equals(PointInterface $other): bool { @@ -256,9 +256,9 @@ public function equals(PointInterface $other): bool /** * {@inheritDoc} - * @see \Mdanter\Ecc\Primitives\PointInterface::mul() + * @see PointInterface::mul() */ - public function mul(GMP $n): PointInterface + public function mul(GMP $multiplier): PointInterface { if ($this->isInfinity()) { return $this->curve->getInfinity(); @@ -266,10 +266,10 @@ public function mul(GMP $n): PointInterface $zero = gmp_init(0, 10); if ($this->adapter->cmp($this->order, $zero) > 0) { - $n = $this->adapter->mod($n, $this->order); + $multiplier = $this->adapter->mod($multiplier, $this->order); } - if ($this->adapter->equals($n, $zero)) { + if ($this->adapter->equals($multiplier, $zero)) { return $this->curve->getInfinity(); } @@ -280,10 +280,10 @@ public function mul(GMP $n): PointInterface ]; $k = $this->curve->getSize(); - $n = str_pad($this->adapter->baseConvert($this->adapter->toString($n), 10, 2), $k, '0', STR_PAD_LEFT); + $multiplier = str_pad($this->adapter->baseConvert($this->adapter->toString($multiplier), 10, 2), $k, '0', STR_PAD_LEFT); for ($i = 0; $i < $k; $i++) { - $j = $n[$i]; + $j = $multiplier[$i]; $this->cswap($r[0], $r[1], $j ^ 1, $k); diff --git a/src/Random/HmacRandomNumberGenerator.php b/src/Random/HmacRandomNumberGenerator.php index 9af45544..75fae8fc 100644 --- a/src/Random/HmacRandomNumberGenerator.php +++ b/src/Random/HmacRandomNumberGenerator.php @@ -3,6 +3,7 @@ namespace Mdanter\Ecc\Random; +use GMP; use Mdanter\Ecc\Crypto\Key\PrivateKeyInterface; use Mdanter\Ecc\Math\GmpMathInterface; use Mdanter\Ecc\Util\BinaryString; @@ -26,7 +27,7 @@ class HmacRandomNumberGenerator implements RandomNumberGeneratorInterface private $privateKey; /** - * @var \GMP + * @var GMP */ private $messageHash; @@ -45,10 +46,10 @@ class HmacRandomNumberGenerator implements RandomNumberGeneratorInterface * Hmac constructor. * @param GmpMathInterface $math * @param PrivateKeyInterface $privateKey - * @param \GMP $messageHash - decimal hash of the message (*may* be truncated) + * @param GMP $messageHash - decimal hash of the message (*may* be truncated) * @param string $algorithm - hashing algorithm */ - public function __construct(GmpMathInterface $math, PrivateKeyInterface $privateKey, \GMP $messageHash, string $algorithm) + public function __construct(GmpMathInterface $math, PrivateKeyInterface $privateKey, GMP $messageHash, string $algorithm) { if (!isset($this->algSize[$algorithm])) { throw new \InvalidArgumentException('Unsupported hashing algorithm'); @@ -62,10 +63,10 @@ public function __construct(GmpMathInterface $math, PrivateKeyInterface $private /** * @param string $bits - binary string of bits - * @param \GMP $qlen - length of q in bits - * @return \GMP + * @param GMP $qlen - length of q in bits + * @return GMP */ - public function bits2int(string $bits, \GMP $qlen): \GMP + public function bits2int(string $bits, GMP $qlen): GMP { $vlen = gmp_init(BinaryString::length($bits) * 8, 10); $hex = bin2hex($bits); @@ -79,11 +80,11 @@ public function bits2int(string $bits, \GMP $qlen): \GMP } /** - * @param \GMP $int - * @param \GMP $rlen - rounded octet length + * @param GMP $int + * @param GMP $rlen - rounded octet length * @return string */ - public function int2octets(\GMP $int, \GMP $rlen): string + public function int2octets(GMP $int, GMP $rlen): string { $out = pack("H*", $this->math->decHex(gmp_strval($int, 10))); $length = gmp_init(BinaryString::length($out), 10); @@ -108,12 +109,12 @@ private function getHashLength(string $algorithm): int } /** - * @param \GMP $q - * @return \GMP + * @param GMP $max + * @return GMP */ - public function generate(\GMP $q): \GMP + public function generate(GMP $max): GMP { - $qlen = gmp_init(NumberSize::bnNumBits($this->math, $q), 10); + $qlen = gmp_init(NumberSize::bnNumBits($this->math, $max), 10); $rlen = $this->math->rightShift($this->math->add($qlen, gmp_init(7, 10)), 3); $hlen = $this->getHashLength($this->algorithm); $bx = $this->int2octets($this->privateKey->getSecret(), $rlen) . $this->int2octets($this->messageHash, $rlen); @@ -139,7 +140,7 @@ public function generate(\GMP $q): \GMP } $k = $this->bits2int($t, $qlen); - if ($this->math->cmp($k, gmp_init(0, 10)) > 0 && $this->math->cmp($k, $q) < 0) { + if ($this->math->cmp($k, gmp_init(0, 10)) > 0 && $this->math->cmp($k, $max) < 0) { return $k; } diff --git a/src/Serializer/Point/CompressedPointSerializer.php b/src/Serializer/Point/CompressedPointSerializer.php index cfc0440f..b1ac11b3 100644 --- a/src/Serializer/Point/CompressedPointSerializer.php +++ b/src/Serializer/Point/CompressedPointSerializer.php @@ -59,17 +59,17 @@ public function serialize(PointInterface $point): string /** * @param CurveFpInterface $curve - * @param string $data - hex serialized compressed point + * @param string $string - hex serialized compressed point * @return PointInterface */ - public function unserialize(CurveFpInterface $curve, string $data): PointInterface + public function unserialize(CurveFpInterface $curve, string $string): PointInterface { - $prefix = substr($data, 0, 2); + $prefix = substr($string, 0, 2); if ($prefix !== '03' && $prefix !== '02') { throw new \InvalidArgumentException('Invalid data: only compressed keys are supported.'); } - $x = gmp_init(substr($data, 2), 16); + $x = gmp_init(substr($string, 2), 16); $y = $curve->recoverYfromX($prefix === '03', $x); return $curve->getPoint($x, $y); diff --git a/src/Serializer/Point/UncompressedPointSerializer.php b/src/Serializer/Point/UncompressedPointSerializer.php index af0982e5..ae40f0eb 100644 --- a/src/Serializer/Point/UncompressedPointSerializer.php +++ b/src/Serializer/Point/UncompressedPointSerializer.php @@ -27,20 +27,20 @@ public function serialize(PointInterface $point): string /** * @param CurveFpInterface $curve - * @param string $data + * @param string $string * @return PointInterface */ - public function unserialize(CurveFpInterface $curve, string $data): PointInterface + public function unserialize(CurveFpInterface $curve, string $string): PointInterface { - if (BinaryString::substring($data, 0, 2) != '04') { + if (BinaryString::substring($string, 0, 2) != '04') { throw new \InvalidArgumentException('Invalid data: only uncompressed keys are supported.'); } - $data = BinaryString::substring($data, 2); - $dataLength = BinaryString::length($data); + $string = BinaryString::substring($string, 2); + $dataLength = BinaryString::length($string); - $x = gmp_init(BinaryString::substring($data, 0, $dataLength / 2), 16); - $y = gmp_init(BinaryString::substring($data, $dataLength / 2), 16); + $x = gmp_init(BinaryString::substring($string, 0, $dataLength / 2), 16); + $y = gmp_init(BinaryString::substring($string, $dataLength / 2), 16); return $curve->getPoint($x, $y); } diff --git a/src/Serializer/PrivateKey/DerPrivateKeySerializer.php b/src/Serializer/PrivateKey/DerPrivateKeySerializer.php index 41098126..70d41933 100644 --- a/src/Serializer/PrivateKey/DerPrivateKeySerializer.php +++ b/src/Serializer/PrivateKey/DerPrivateKeySerializer.php @@ -94,9 +94,9 @@ private function formatKey(PrivateKeyInterface $key): string * @see \Mdanter\Ecc\Serializer\PrivateKey\PrivateKeySerializerInterface::parse() * @throws \FG\ASN1\Exception\ParserException */ - public function parse(string $data): PrivateKeyInterface + public function parse(string $formattedKey): PrivateKeyInterface { - $asnObject = ASNObject::fromBinary($data); + $asnObject = ASNObject::fromBinary($formattedKey); if (! ($asnObject instanceof Sequence) || $asnObject->getNumberofChildren() !== 4) { throw new \RuntimeException('Invalid data.'); diff --git a/src/Serializer/PublicKey/DerPublicKeySerializer.php b/src/Serializer/PublicKey/DerPublicKeySerializer.php index d3a143fd..2b6eedf3 100644 --- a/src/Serializer/PublicKey/DerPublicKeySerializer.php +++ b/src/Serializer/PublicKey/DerPublicKeySerializer.php @@ -76,8 +76,8 @@ public function getUncompressedKey(PublicKeyInterface $key): string * {@inheritDoc} * @see \Mdanter\Ecc\Serializer\PublicKey\PublicKeySerializerInterface::parse() */ - public function parse(string $string): PublicKeyInterface + public function parse(string $formattedKey): PublicKeyInterface { - return $this->parser->parse($string); + return $this->parser->parse($formattedKey); } } diff --git a/src/Serializer/Util/CurveOidMapper.php b/src/Serializer/Util/CurveOidMapper.php index 41fcb416..09df317c 100644 --- a/src/Serializer/Util/CurveOidMapper.php +++ b/src/Serializer/Util/CurveOidMapper.php @@ -69,6 +69,7 @@ class CurveOidMapper /** * @return array + * @psalm-suppress PossiblyUnusedMethod */ public static function getNames(): array { @@ -106,6 +107,8 @@ public static function getCurveOid(NamedCurveFp $curve): ObjectIdentifier /** * @param ObjectIdentifier $oid * @return NamedCurveFp + * + * @psalm-suppress PossiblyUnusedMethod */ public static function getCurveFromOid(ObjectIdentifier $oid): NamedCurveFp { diff --git a/src/Util/NumberSize.php b/src/Util/NumberSize.php index 6d2b93a0..79a0e021 100644 --- a/src/Util/NumberSize.php +++ b/src/Util/NumberSize.php @@ -12,6 +12,8 @@ class NumberSize * @param GmpMathInterface $adapter * @param \GMP $x * @return float + * + * @psalm-suppress PossiblyUnusedMethod */ public static function getCeiledByteSize(GmpMathInterface $adapter, \GMP $x): float { @@ -23,6 +25,8 @@ public static function getCeiledByteSize(GmpMathInterface $adapter, \GMP $x): fl * @param GmpMathInterface $adapter * @param \GMP $x * @return float + * + * @psalm-suppress PossiblyUnusedMethod */ public static function getFlooredByteSize(GmpMathInterface $adapter, \GMP $x): float { @@ -38,6 +42,8 @@ public static function getFlooredByteSize(GmpMathInterface $adapter, \GMP $x): f * @return int * * @link https://www.openssl.org/docs/crypto/BN_num_bytes.html + * + * @psalm-suppress PossiblyUnusedMethod */ public static function bnNumBytes(GmpMathInterface $adapter, \GMP $x): int {