From beafe2a8a14de116c05494668914d642c2e7b9f2 Mon Sep 17 00:00:00 2001 From: Jack Worman Date: Sun, 19 Jun 2022 08:03:28 -0500 Subject: [PATCH] 1st round of comments --- build/psalm_baseline.xml | 133 +++++++---------------- phpseclib/Common/Functions/Strings.php | 2 +- phpseclib/Crypt/EC/BaseCurves/Binary.php | 2 +- phpseclib/Crypt/EC/BaseCurves/Prime.php | 4 +- phpseclib/Crypt/RC2.php | 6 +- phpseclib/Crypt/RSA.php | 12 +- phpseclib/Crypt/RSA/Formats/Keys/XML.php | 4 +- phpseclib/Crypt/Twofish.php | 4 +- 8 files changed, 54 insertions(+), 113 deletions(-) diff --git a/build/psalm_baseline.xml b/build/psalm_baseline.xml index 979a4626..fea4a007 100644 --- a/build/psalm_baseline.xml +++ b/build/psalm_baseline.xml @@ -1,8 +1,7 @@ - - $trim + $var @@ -4090,9 +4089,8 @@ $order $p - + $m - $modulo $lhs @@ -4414,9 +4412,8 @@ new PrimeField($modulo) - + $jsf - $res $this->convertToAffine($acc) $this->p @@ -4453,10 +4450,8 @@ $two $two - + $m - $point - $wnd $m @@ -4464,28 +4459,24 @@ $naf[$b] $p $point - $point $points[$a] $points[$a] $points[$b] $points[$b] - $res[$i - 1] + $points[$i] + $points[0] $scalars[$a] $scalars[$b] $wnd[$j][(-$z - 1) >> 1] - - $point['naf'] + $points[$i]['nafwidth'] $points[0]['nafwidth'] - - $point['naf'] - $wnd[$j][($z - 1) >> 1] - + $b $bn $jsf[0][] @@ -4507,7 +4498,6 @@ $m8 $m8 $m8 - $max $naf[$a] $naf[$b] $p @@ -4540,7 +4530,7 @@ FiniteField[] FiniteField[] boolean - int[] + list<array> add @@ -4584,7 +4574,7 @@ testBit testBit - + $k1->testBit(0) $k1->testBit(0) $k1->testBit(1) @@ -4607,9 +4597,7 @@ $m8 $u1 $u2 - $wnd $z - 1 << $wnd $lhs->equals($rhs) @@ -4629,10 +4617,6 @@ $factory - - $p - $wnd[$j][(-$z - 1) >> 1] - $dbl @@ -7663,13 +7647,10 @@ $length >> 3 - - $t1 - $l - + $keys[$r0 & 0x3F] $keys[$r0 & 0x3F] $keys[$r1 & 0x3F] @@ -7678,20 +7659,13 @@ $keys[$r2 & 0x3F] $keys[$r3 & 0x3F] $keys[$r3 & 0x3F] - $l[$i + $t8] - $l[$i + 1] - $l[$i] - $l[$i] - $l[$i] $pitable[$l[$i + 1] ^ $l[$i + $t8]] $pitable[$l[$i - 1] + $l[$i - $t]] $pitable[$l[$i] & $tm] self::$invpitable[$l[0]] self::$pitable[$l['a']] - - $i - $i + $l[$i] $l[$i] $l[$i] @@ -7720,14 +7694,8 @@ $r3 $r3 $r3 - $t8 - $this->current_key_length - $tm - - $i - $i - $i + $keys[$j++] $keys[$j++] $keys[$j++] @@ -7788,9 +7756,6 @@ $r3 $r3 $r3 - $t1 - $t8 - $t8 ($r0 + $keys[$j++] + ((($r1 ^ $r2) & $r3) ^ $r1)) & 0xFFFF ($r0 ^ $r1) & $r2 ($r0 ^ $r1) & $r2 @@ -7803,7 +7768,6 @@ ($r3 + $keys[$j++] + ((($r0 ^ $r1) & $r2) ^ $r0)) & 0xFFFF ($r3 ^ $r0) & $r1 ($r3 ^ $r0) & $r1 - 8 * $t8 self::$pitable[$l['a']] @@ -8040,9 +8004,6 @@ modInverse subtract - - toBytes - $primes[1] $primes[2] @@ -8515,19 +8476,11 @@ !empty($password) && is_string($password) is_string($password) - - Strings::is_stringable($key) - XML - - $em[0] - $em[0] - $em[1] - !$hashesMatch $m[$i] === "\0" @@ -8540,16 +8493,10 @@ string - - $em - $publicExponent - - $em[0] - $em[0] - $em[1] + $key $r $r->multiply($h) @@ -8610,11 +8557,12 @@ strpos($em, chr(0), 2) - - $em - $em - $em - $em + + $m + $m + $s + $s + $temp $this->coefficients[2] @@ -8649,15 +8597,13 @@ false false - - $c + $this->rsassa_pss_verify($message, $signature) hash_equals($h, $h2) - + bool string - string $decoded[0] @@ -8685,11 +8631,13 @@ $type::savePublicKey($this->modulus, $this->publicExponent, $options) - - $em - $em - $em - $em + + $c + $c + $m2 + $m2 + $m2 + $temp $decoded['digest'] @@ -8713,8 +8661,11 @@ PublicKey PublicKey - + !is_array($decoded) + $em === false + $em === false + $em === false $decoded @@ -9976,12 +9927,6 @@ $le_longs[7] $le_longs[8] - - $A - $A - $B - $B - $K[0] $K[0] @@ -14893,6 +14838,9 @@ $value $value + + $this->$this + $result['.']->lstat $result['.']->stat @@ -14926,9 +14874,10 @@ unpack('Nlength', Strings::shift($this->packet_buffer, 4)) unpack('Npacket_id', Strings::shift($this->packet_buffer, 4)) - + $attr $this->pwd + $this->pwd false @@ -14968,9 +14917,10 @@ preg_replace('#^/|/(?=/)|/$#', '', $path) preg_replace('#^/|/(?=/)|/$#', '', $path) - + $dirs[0] $this->channel_status[self::CHANNEL] + $this->channel_status[self::CHANNEL] $this->server_channels[self::CHANNEL] @@ -15805,8 +15755,7 @@ $temp['length'] - - $elapsed + $matches $matches $matches diff --git a/phpseclib/Common/Functions/Strings.php b/phpseclib/Common/Functions/Strings.php index 9a5ffcb8..bfaa1907 100644 --- a/phpseclib/Common/Functions/Strings.php +++ b/phpseclib/Common/Functions/Strings.php @@ -278,7 +278,7 @@ abstract class Strings /** * Convert bits to binary data */ - public static function bin2bits(string $x, $trim = true): string + public static function bin2bits(string $x, bool $trim = true): string { /* // the pure-PHP approach is slower than the GMP approach BUT diff --git a/phpseclib/Crypt/EC/BaseCurves/Binary.php b/phpseclib/Crypt/EC/BaseCurves/Binary.php index 960f99af..209cce45 100644 --- a/phpseclib/Crypt/EC/BaseCurves/Binary.php +++ b/phpseclib/Crypt/EC/BaseCurves/Binary.php @@ -86,7 +86,7 @@ class Binary extends Base /** * Sets the modulo */ - public function setModulo(...$modulo): void + public function setModulo(int ...$modulo): void { $this->modulo = $modulo; $this->factory = new BinaryField(...$modulo); diff --git a/phpseclib/Crypt/EC/BaseCurves/Prime.php b/phpseclib/Crypt/EC/BaseCurves/Prime.php index 55b2d79d..93b55a15 100644 --- a/phpseclib/Crypt/EC/BaseCurves/Prime.php +++ b/phpseclib/Crypt/EC/BaseCurves/Prime.php @@ -640,9 +640,9 @@ class Prime extends Base * Adapted from: * https://github.com/indutny/elliptic/blob/725bd91/lib/elliptic/curve/base.js#L351 * - * @return int[] + * @return list */ - private function getNAFPoints($point, $wnd): array + private function getNAFPoints(array $point, int $wnd): array { if (isset($point['naf'])) { return $point['naf']; diff --git a/phpseclib/Crypt/RC2.php b/phpseclib/Crypt/RC2.php index 49d66198..3eb527c5 100644 --- a/phpseclib/Crypt/RC2.php +++ b/phpseclib/Crypt/RC2.php @@ -324,16 +324,16 @@ class RC2 extends BlockCipher * @throws \LengthException if the key length isn't supported *@see \phpseclib3\Crypt\Common\SymmetricKey::setKey() */ - public function setKey(string $key, $t1 = false): void + public function setKey(string $key, ?int $t1 = null): void { $this->orig_key = $key; - if ($t1 === false) { + if ($t1 === null) { $t1 = $this->default_key_length; } if ($t1 < 1 || $t1 > 1024) { - //throw new \LengthException('Key size of ' . $t1 . ' bits is not supported by this algorithm. Only keys between 1 and 1024 bits, inclusive, are supported'); + throw new \LengthException('Key size of ' . $t1 . ' bits is not supported by this algorithm. Only keys between 1 and 1024 bits, inclusive, are supported'); } $this->current_key_length = $t1; diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php index 7be7ecae..4d35851d 100644 --- a/phpseclib/Crypt/RSA.php +++ b/phpseclib/Crypt/RSA.php @@ -196,7 +196,7 @@ abstract class RSA extends AsymmetricKey /** * Modulus (ie. n) * - * @var \phpseclib3\Math\BigInteger + * @var BigInteger */ protected $modulus; @@ -210,7 +210,7 @@ abstract class RSA extends AsymmetricKey /** * Exponent (ie. e or d) * - * @var \phpseclib3\Math\BigInteger + * @var BigInteger */ protected $exponent; @@ -491,15 +491,9 @@ abstract class RSA extends AsymmetricKey * Integer-to-Octet-String primitive * * See {@link http://tools.ietf.org/html/rfc3447#section-4.1 RFC3447#section-4.1}. - * - * @param bool|\phpseclib3\Math\BigInteger $x - * @return bool|string */ - protected function i2osp($x, int $xLen) + protected function i2osp(BigInteger $x, int $xLen): string { - if ($x === false) { - return false; - } $x = $x->toBytes(); if (strlen($x) > $xLen) { throw new \OutOfRangeException('Resultant string length out of range'); diff --git a/phpseclib/Crypt/RSA/Formats/Keys/XML.php b/phpseclib/Crypt/RSA/Formats/Keys/XML.php index 227d6cac..8de03ad6 100644 --- a/phpseclib/Crypt/RSA/Formats/Keys/XML.php +++ b/phpseclib/Crypt/RSA/Formats/Keys/XML.php @@ -38,9 +38,9 @@ abstract class XML /** * Break a public or private key down into its constituent components * - * @param string|false $password + * @param string|array $key */ - public static function load(string $key, $password = ''): array + public static function load($key): array { if (!Strings::is_stringable($key)) { throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key)); diff --git a/phpseclib/Crypt/Twofish.php b/phpseclib/Crypt/Twofish.php index a2a90514..cac16f1f 100644 --- a/phpseclib/Crypt/Twofish.php +++ b/phpseclib/Crypt/Twofish.php @@ -523,10 +523,8 @@ class Twofish extends BlockCipher /** * _mdsrem function using by the twofish cipher algorithm - * @param string|int $A - * @param string|int $B */ - private function mdsrem($A, $B): array + private function mdsrem(int $A, int $B): array { // No gain by unrolling this loop. for ($i = 0; $i < 8; ++$i) {