From 86ef8ef262c451682eeb7118188547ffd3174c6f Mon Sep 17 00:00:00 2001 From: Jack Worman Date: Thu, 23 Jun 2022 19:44:04 -0500 Subject: [PATCH] 2nd round of comments --- build/psalm_baseline.xml | 48 +++++++------------ phpseclib/Crypt/AES.php | 4 +- phpseclib/Crypt/Blowfish.php | 2 +- phpseclib/Crypt/ChaCha20.php | 10 ++-- phpseclib/Crypt/Common/AsymmetricKey.php | 2 +- phpseclib/Crypt/Common/Formats/Keys/PKCS8.php | 2 +- phpseclib/Crypt/Common/SymmetricKey.php | 36 +++++++------- phpseclib/Crypt/DES.php | 10 ++-- phpseclib/Crypt/DH.php | 2 +- phpseclib/Crypt/DSA.php | 2 +- phpseclib/Crypt/EC.php | 6 +-- phpseclib/Crypt/EC/Formats/Keys/Common.php | 2 +- phpseclib/Crypt/RC2.php | 12 ++--- phpseclib/Crypt/RC4.php | 8 ++-- phpseclib/Crypt/RSA.php | 6 +-- phpseclib/Crypt/RSA/PrivateKey.php | 4 +- phpseclib/Crypt/RSA/PublicKey.php | 8 ++-- phpseclib/Crypt/Random.php | 2 +- phpseclib/Crypt/Rijndael.php | 12 ++--- phpseclib/Crypt/Salsa20.php | 8 ++-- phpseclib/Crypt/TripleDES.php | 16 +++---- phpseclib/Crypt/Twofish.php | 2 +- phpseclib/File/X509.php | 2 +- .../Math/BigInteger/Engines/BCMath/Base.php | 6 +-- phpseclib/Math/BigInteger/Engines/PHP.php | 6 +-- .../Math/BigInteger/Engines/PHP/Base.php | 6 +-- .../Engines/PHP/Reductions/MontgomeryMult.php | 2 +- phpseclib/Math/BigInteger/Engines/PHP32.php | 2 +- phpseclib/Math/BinaryField/Integer.php | 8 ++-- phpseclib/Math/PrimeField/Integer.php | 2 +- phpseclib/Net/SFTP.php | 21 ++++---- phpseclib/Net/SSH2.php | 12 ++--- 32 files changed, 127 insertions(+), 144 deletions(-) diff --git a/build/psalm_baseline.xml b/build/psalm_baseline.xml index fea4a007..8123382b 100644 --- a/build/psalm_baseline.xml +++ b/build/psalm_baseline.xml @@ -14194,12 +14194,16 @@ self::minHelper($nums) self::randomRangeHelper($min, $max) + + $digit / 2 ** (2 * $step) + $digit $digit $vals[] - + + $digit $digit $digit @@ -14398,37 +14402,21 @@ string - - $instanceID + $instanceID $instanceID $num - $x - $x - $x - $y - $y - $y $z - + $num - $r - $r - $x - $x - $y - $y - $y $z - - static::$modulo[$instanceID] + static::$reduce[$instanceID] static::$reduce[$instanceID] - - $r + $this->instanceID $this->value $x @@ -14541,9 +14529,6 @@ - - $instanceID - $length $one @@ -14552,10 +14537,6 @@ static::$zero[static::class] static::$zero[static::class] - - static::$modulo[$instanceID] - static::$reduce[$instanceID] - $this->value @@ -14599,6 +14580,9 @@ false false + + [&$this, 'comparator'] + array array|string @@ -14796,11 +14780,11 @@ $value + ?int array array|false array|false bool - int string string string|bool @@ -15024,12 +15008,14 @@ break; + + comparator + $key - + bool - int $attrib_bits diff --git a/phpseclib/Crypt/AES.php b/phpseclib/Crypt/AES.php index 17ab2490..eae4c76b 100644 --- a/phpseclib/Crypt/AES.php +++ b/phpseclib/Crypt/AES.php @@ -62,7 +62,7 @@ class AES extends Rijndael * Since \phpseclib3\Crypt\AES extends \phpseclib3\Crypt\Rijndael, this function is, technically, available, but it doesn't do anything. * * @throws \BadMethodCallException anytime it's called - *@see \phpseclib3\Crypt\Rijndael::setBlockLength() + * @see \phpseclib3\Crypt\Rijndael::setBlockLength() */ public function setBlockLength(int $length): void { @@ -75,7 +75,7 @@ class AES extends Rijndael * Valid key lengths are 128, 192, and 256. Set the link to bool(false) to disable a fixed key length * * @throws \LengthException if the key length isn't supported - *@see \phpseclib3\Crypt\Rijndael:setKeyLength() + * @see \phpseclib3\Crypt\Rijndael:setKeyLength() */ public function setKeyLength(int $length): void { diff --git a/phpseclib/Crypt/Blowfish.php b/phpseclib/Crypt/Blowfish.php index 62abe52d..a5732b2b 100644 --- a/phpseclib/Crypt/Blowfish.php +++ b/phpseclib/Crypt/Blowfish.php @@ -307,7 +307,7 @@ class Blowfish extends BlockCipher * * This is mainly just a wrapper to set things up for \phpseclib3\Crypt\Common\SymmetricKey::isValidEngine() * - *@see \phpseclib3\Crypt\Common\SymmetricKey::isValidEngine() + * @see \phpseclib3\Crypt\Common\SymmetricKey::isValidEngine() */ protected function isValidEngineHelper(int $engine): bool { diff --git a/phpseclib/Crypt/ChaCha20.php b/phpseclib/Crypt/ChaCha20.php index 151fe9eb..3fc37143 100644 --- a/phpseclib/Crypt/ChaCha20.php +++ b/phpseclib/Crypt/ChaCha20.php @@ -37,7 +37,7 @@ class ChaCha20 extends Salsa20 * * This is mainly just a wrapper to set things up for \phpseclib3\Crypt\Common\SymmetricKey::isValidEngine() * - *@see \phpseclib3\Crypt\Common\SymmetricKey::__construct() + * @see \phpseclib3\Crypt\Common\SymmetricKey::__construct() */ protected function isValidEngineHelper(int $engine): bool { @@ -74,7 +74,7 @@ class ChaCha20 extends Salsa20 * Encrypts a message. * * @return string $ciphertext - *@see \phpseclib3\Crypt\Common\SymmetricKey::decrypt() + * @see \phpseclib3\Crypt\Common\SymmetricKey::decrypt() * @see self::crypt() */ public function encrypt(string $plaintext): string @@ -95,7 +95,7 @@ class ChaCha20 extends Salsa20 * At least if the continuous buffer is disabled. * * @return string $plaintext - *@see \phpseclib3\Crypt\Common\SymmetricKey::encrypt() + * @see \phpseclib3\Crypt\Common\SymmetricKey::encrypt() * @see self::crypt() */ public function decrypt(string $ciphertext): string @@ -113,7 +113,7 @@ class ChaCha20 extends Salsa20 * Encrypts a message with libsodium * * @return string $text - *@see self::encrypt() + * @see self::encrypt() */ private function encrypt_with_libsodium(string $plaintext): string { @@ -138,7 +138,7 @@ class ChaCha20 extends Salsa20 * Decrypts a message with libsodium * * @return string $text - *@see self::decrypt() + * @see self::decrypt() */ private function decrypt_with_libsodium(string $ciphertext): string { diff --git a/phpseclib/Crypt/Common/AsymmetricKey.php b/phpseclib/Crypt/Common/AsymmetricKey.php index 17016ea5..28ced301 100644 --- a/phpseclib/Crypt/Common/AsymmetricKey.php +++ b/phpseclib/Crypt/Common/AsymmetricKey.php @@ -356,7 +356,7 @@ abstract class AsymmetricKey * The plugin needs to either already be loaded or be auto-loadable. * Loading a plugin whose shortname overwrite an existing shortname will overwrite the old plugin. * - *@see self::load() + * @see self::load() */ public static function addFileFormat(string $fullname): void { diff --git a/phpseclib/Crypt/Common/Formats/Keys/PKCS8.php b/phpseclib/Crypt/Common/Formats/Keys/PKCS8.php index b288ec51..937aef5d 100644 --- a/phpseclib/Crypt/Common/Formats/Keys/PKCS8.php +++ b/phpseclib/Crypt/Common/Formats/Keys/PKCS8.php @@ -122,7 +122,7 @@ abstract class PKCS8 extends PKCS /** * Returns a SymmetricKey object based on a PBES1 $algo * - *@return \phpseclib3\Crypt\Common\SymmetricKey + * @return \phpseclib3\Crypt\Common\SymmetricKey */ private static function getPBES1EncryptionObject(string $algo) { diff --git a/phpseclib/Crypt/Common/SymmetricKey.php b/phpseclib/Crypt/Common/SymmetricKey.php index c0803dd4..773079f8 100644 --- a/phpseclib/Crypt/Common/SymmetricKey.php +++ b/phpseclib/Crypt/Common/SymmetricKey.php @@ -841,7 +841,7 @@ abstract class SymmetricKey * {@internal Could, but not must, extend by the child Crypt_* class} * * @param string[] ...$func_args - *@throws \LengthException if pbkdf1 is being used and the derived key length exceeds the hash length + * @throws \LengthException if pbkdf1 is being used and the derived key length exceeds the hash length * @see Crypt/Hash.php */ public function setPassword(string $password, string $method = 'pbkdf2', ...$func_args): bool @@ -982,7 +982,7 @@ abstract class SymmetricKey * {@link https://tools.ietf.org/html/rfc7292#appendix-B} * * @return string $a - *@see self::setPassword() + * @see self::setPassword() */ private static function pkcs12helper(int $n, Hash $hashObj, string $i, string $d, int $count): string { @@ -1039,7 +1039,7 @@ abstract class SymmetricKey * {@internal Could, but not must, extend by the child Crypt_* class} * * @return string $ciphertext - *@see self::decrypt() + * @see self::decrypt() */ public function encrypt(string $plaintext): string { @@ -1418,7 +1418,7 @@ abstract class SymmetricKey * * @return string $plaintext * @throws \LengthException if we're inside a block cipher and the ciphertext length is not a multiple of the block size - *@see self::encrypt() + * @see self::encrypt() */ public function decrypt(string $ciphertext): string { @@ -1787,7 +1787,7 @@ abstract class SymmetricKey * @return string * @throws \LengthException if $length isn't of a sufficient length * @throws \RuntimeException if GCM mode isn't being used - *@see self::encrypt() + * @see self::encrypt() */ public function getTag(int $length = 16) { @@ -1820,7 +1820,7 @@ abstract class SymmetricKey * * @throws \LengthException if $length isn't of a sufficient length * @throws \RuntimeException if GCM mode isn't being used - *@see self::decrypt() + * @see self::decrypt() */ public function setTag(string $tag): void { @@ -1844,7 +1844,7 @@ abstract class SymmetricKey * * mcrypt requires an IV even if ECB is used * - *@see self::encrypt() + * @see self::encrypt() * @see self::decrypt() */ protected function getIV(string $iv): string @@ -1860,7 +1860,7 @@ abstract class SymmetricKey * and SymmetricKey::decrypt(). Also, OpenSSL doesn't implement CTR for all of it's symmetric ciphers so this * function will emulate CTR with ECB when necessary. * - *@see self::encrypt() + * @see self::encrypt() * @see self::decrypt() */ private function openssl_ctr_process(string $plaintext, string &$encryptIV, array &$buffer): string @@ -1943,7 +1943,7 @@ abstract class SymmetricKey * for OFB is the same for both encrypting and decrypting this function is re-used by both SymmetricKey::encrypt() * and SymmetricKey::decrypt(). * - *@see self::encrypt() + * @see self::encrypt() * @see self::decrypt() */ private function openssl_ofb_process(string $plaintext, string &$encryptIV, array &$buffer): string @@ -2117,7 +2117,7 @@ abstract class SymmetricKey /** * Test for engine validity * - *@see self::__construct() + * @see self::__construct() */ protected function isValidEngineHelper(int $engine): bool { @@ -2164,7 +2164,7 @@ abstract class SymmetricKey /** * Test for engine validity * - *@see self::__construct() + * @see self::__construct() */ public function isValidEngine(string $engine): bool { @@ -2198,7 +2198,7 @@ abstract class SymmetricKey * * If the preferred crypt engine is not available the fastest available one will be used * - *@see self::__construct() + * @see self::__construct() */ public function setPreferredEngine(string $engine): void { @@ -2424,7 +2424,7 @@ abstract class SymmetricKey * If padding is disabled and $text is not a multiple of the blocksize, the string will be padded regardless * and padding will, hence forth, be enabled. * - *@throws \LengthException if padding is disabled and the plaintext's length is not a multiple of the block size + * @throws \LengthException if padding is disabled and the plaintext's length is not a multiple of the block size * @see self::unpad() */ protected function pad(string $text): string @@ -2450,7 +2450,7 @@ abstract class SymmetricKey * If padding is enabled and the reported padding length is invalid the encryption key will be assumed to be wrong * and false will be returned. * - *@throws \LengthException if the ciphertext's length is not a multiple of the block size + * @throws \LengthException if the ciphertext's length is not a multiple of the block size * @see self::pad() */ protected function unpad(string $text): string @@ -2632,7 +2632,7 @@ abstract class SymmetricKey * * * @return string (the name of the created callback function) - *@see self::decrypt() + * @see self::decrypt() * @see self::setupInlineCrypt() * @see self::encrypt() */ @@ -3146,7 +3146,7 @@ abstract class SymmetricKey * See https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf#page=20 * for more info * - *@see self::decrypt() + * @see self::decrypt() * @see self::encrypt() */ private function ghash(string $x): string @@ -3177,7 +3177,7 @@ abstract class SymmetricKey /** * Returns the bit length of a string in a packed format * - *@see self::setupGCM() + * @see self::setupGCM() * @see self::decrypt() * @see self::encrypt() */ @@ -3189,7 +3189,7 @@ abstract class SymmetricKey /** * NULL pads a string to be a multiple of 128 * - *@see self::setupGCM() + * @see self::setupGCM() * @see self::decrypt() * @see self::encrypt() */ diff --git a/phpseclib/Crypt/DES.php b/phpseclib/Crypt/DES.php index 3f391813..f4e23185 100644 --- a/phpseclib/Crypt/DES.php +++ b/phpseclib/Crypt/DES.php @@ -579,7 +579,7 @@ class DES extends BlockCipher * * This is mainly just a wrapper to set things up for \phpseclib3\Crypt\Common\SymmetricKey::isValidEngine() * - *@see \phpseclib3\Crypt\Common\SymmetricKey::isValidEngine() + * @see \phpseclib3\Crypt\Common\SymmetricKey::isValidEngine() */ protected function isValidEngineHelper(int $engine): bool { @@ -600,7 +600,7 @@ class DES extends BlockCipher * * DES also requires that every eighth bit be a parity bit, however, we'll ignore that. * - *@see \phpseclib3\Crypt\Common\SymmetricKey::setKey() + * @see \phpseclib3\Crypt\Common\SymmetricKey::setKey() */ public function setKey(string $key): void { @@ -615,7 +615,7 @@ class DES extends BlockCipher /** * Encrypts a block * - *@see self::encrypt() + * @see self::encrypt() * @see \phpseclib3\Crypt\Common\SymmetricKey::encryptBlock() * @see \phpseclib3\Crypt\Common\SymmetricKey::encrypt() */ @@ -627,7 +627,7 @@ class DES extends BlockCipher /** * Decrypts a block * - *@see self::decrypt() + * @see self::decrypt() * @see \phpseclib3\Crypt\Common\SymmetricKey::decryptBlock() * @see \phpseclib3\Crypt\Common\SymmetricKey::decrypt() */ @@ -644,7 +644,7 @@ class DES extends BlockCipher * idea of what this function does. * * @return string - *@see self::decryptBlock() + * @see self::decryptBlock() * @see self::encryptBlock() */ private function processBlock(string $block, int $mode) diff --git a/phpseclib/Crypt/DH.php b/phpseclib/Crypt/DH.php index 4120219d..833435b1 100644 --- a/phpseclib/Crypt/DH.php +++ b/phpseclib/Crypt/DH.php @@ -322,7 +322,7 @@ abstract class DH extends AsymmetricKey /** * OnLoad Handler * - *@return bool + * @return bool */ protected static function onLoad(array $components) { diff --git a/phpseclib/Crypt/DSA.php b/phpseclib/Crypt/DSA.php index 1e0f72c7..95948185 100644 --- a/phpseclib/Crypt/DSA.php +++ b/phpseclib/Crypt/DSA.php @@ -213,7 +213,7 @@ abstract class DSA extends AsymmetricKey /** * OnLoad Handler * - *@return bool + * @return bool */ protected static function onLoad(array $components) { diff --git a/phpseclib/Crypt/EC.php b/phpseclib/Crypt/EC.php index f80b2e82..20cef681 100644 --- a/phpseclib/Crypt/EC.php +++ b/phpseclib/Crypt/EC.php @@ -197,7 +197,7 @@ abstract class EC extends AsymmetricKey /** * OnLoad Handler * - *@return bool + * @return bool */ protected static function onLoad(array $components) { @@ -338,7 +338,7 @@ abstract class EC extends AsymmetricKey * Returns the parameters * * @param string $type optional - *@see self::getPublicKey() + * @see self::getPublicKey() */ public function getParameters(string $type = 'PKCS1') { @@ -382,7 +382,7 @@ abstract class EC extends AsymmetricKey * Used by Ed25519 / Ed448. * * @param string|null $context optional - *@see self::verify() + * @see self::verify() * @see self::sign() */ public function withContext(string $context = null): EC diff --git a/phpseclib/Crypt/EC/Formats/Keys/Common.php b/phpseclib/Crypt/EC/Formats/Keys/Common.php index 09456a20..913108ff 100644 --- a/phpseclib/Crypt/EC/Formats/Keys/Common.php +++ b/phpseclib/Crypt/EC/Formats/Keys/Common.php @@ -335,7 +335,7 @@ trait Common * @param bool $returnArray optional * @param array $options optional * @return string|false - *@todo Maybe at some point this could be moved to __toString() for each of the curves? + * @todo Maybe at some point this could be moved to __toString() for each of the curves? */ private static function encodeParameters(BaseCurve $curve, bool $returnArray = false, array $options = []) { diff --git a/phpseclib/Crypt/RC2.php b/phpseclib/Crypt/RC2.php index 3eb527c5..446a8b15 100644 --- a/phpseclib/Crypt/RC2.php +++ b/phpseclib/Crypt/RC2.php @@ -269,7 +269,7 @@ class RC2 extends BlockCipher * * This is mainly just a wrapper to set things up for \phpseclib3\Crypt\Common\SymmetricKey::isValidEngine() * - *@see \phpseclib3\Crypt\Common\SymmetricKey::__construct() + * @see \phpseclib3\Crypt\Common\SymmetricKey::__construct() */ protected function isValidEngineHelper(int $engine): bool { @@ -322,7 +322,7 @@ class RC2 extends BlockCipher * it is empty. * * @throws \LengthException if the key length isn't supported - *@see \phpseclib3\Crypt\Common\SymmetricKey::setKey() + * @see \phpseclib3\Crypt\Common\SymmetricKey::setKey() */ public function setKey(string $key, ?int $t1 = null): void { @@ -381,7 +381,7 @@ class RC2 extends BlockCipher * Mostly a wrapper for \phpseclib3\Crypt\Common\SymmetricKey::encrypt, with some additional OpenSSL handling code * * @return string $ciphertext - *@see self::decrypt() + * @see self::decrypt() */ public function encrypt(string $plaintext): string { @@ -402,7 +402,7 @@ class RC2 extends BlockCipher * Mostly a wrapper for \phpseclib3\Crypt\Common\SymmetricKey::decrypt, with some additional OpenSSL handling code * * @return string $plaintext - *@see self::encrypt() + * @see self::encrypt() */ public function decrypt(string $ciphertext): string { @@ -420,7 +420,7 @@ class RC2 extends BlockCipher /** * Encrypts a block * - *@see \phpseclib3\Crypt\Common\SymmetricKey::encryptBlock() + * @see \phpseclib3\Crypt\Common\SymmetricKey::encryptBlock() * @see \phpseclib3\Crypt\Common\SymmetricKey::encrypt() */ protected function encryptBlock(string $in): string @@ -462,7 +462,7 @@ class RC2 extends BlockCipher /** * Decrypts a block * - *@see \phpseclib3\Crypt\Common\SymmetricKey::decryptBlock() + * @see \phpseclib3\Crypt\Common\SymmetricKey::decryptBlock() * @see \phpseclib3\Crypt\Common\SymmetricKey::decrypt() */ protected function decryptBlock(string $in): string diff --git a/phpseclib/Crypt/RC4.php b/phpseclib/Crypt/RC4.php index e57c4c3f..306d729d 100644 --- a/phpseclib/Crypt/RC4.php +++ b/phpseclib/Crypt/RC4.php @@ -100,7 +100,7 @@ class RC4 extends StreamCipher * * This is mainly just a wrapper to set things up for \phpseclib3\Crypt\Common\SymmetricKey::isValidEngine() * - *@see \phpseclib3\Crypt\Common\SymmetricKey::__construct() + * @see \phpseclib3\Crypt\Common\SymmetricKey::__construct() */ protected function isValidEngineHelper(int $engine): bool { @@ -167,7 +167,7 @@ class RC4 extends StreamCipher * Encrypts a message. * * @return string $ciphertext - *@see \phpseclib3\Crypt\Common\SymmetricKey::decrypt() + * @see \phpseclib3\Crypt\Common\SymmetricKey::decrypt() * @see self::crypt() */ public function encrypt(string $plaintext): string @@ -185,7 +185,7 @@ class RC4 extends StreamCipher * At least if the continuous buffer is disabled. * * @return string $plaintext - *@see \phpseclib3\Crypt\Common\SymmetricKey::encrypt() + * @see \phpseclib3\Crypt\Common\SymmetricKey::encrypt() * @see self::crypt() */ public function decrypt(string $ciphertext): string @@ -244,7 +244,7 @@ class RC4 extends StreamCipher * Encrypts or decrypts a message. * * @return string $text - *@see self::decrypt() + * @see self::decrypt() * @see self::encrypt() */ private function crypt(string $text, int $mode): string diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php index 4d35851d..b8095045 100644 --- a/phpseclib/Crypt/RSA.php +++ b/phpseclib/Crypt/RSA.php @@ -286,7 +286,7 @@ abstract class RSA extends AsymmetricKey * * The public key can be extracted from the private key * - *@return RSA + * @return RSA */ public static function createKey(int $bits = 2048) { @@ -416,7 +416,7 @@ abstract class RSA extends AsymmetricKey /** * OnLoad Handler * - *@return bool + * @return bool */ protected static function onLoad(array $components) { @@ -516,7 +516,7 @@ abstract class RSA extends AsymmetricKey * * See {@link http://tools.ietf.org/html/rfc3447#section-9.2 RFC3447#section-9.2}. * - *@throws \LengthException if the intended encoded message length is too short + * @throws \LengthException if the intended encoded message length is too short */ protected function emsa_pkcs1_v1_5_encode(string $m, int $emLen): string { diff --git a/phpseclib/Crypt/RSA/PrivateKey.php b/phpseclib/Crypt/RSA/PrivateKey.php index 3d4faee1..e7e618e6 100644 --- a/phpseclib/Crypt/RSA/PrivateKey.php +++ b/phpseclib/Crypt/RSA/PrivateKey.php @@ -241,7 +241,7 @@ class PrivateKey extends RSA implements Common\PrivateKey * See {@link http://tools.ietf.org/html/rfc3447#section-8.2.1 RFC3447#section-8.2.1}. * * @return bool|string - *@throws \LengthException if the RSA modulus is too short + * @throws \LengthException if the RSA modulus is too short */ private function rsassa_pkcs1_v1_5_sign(string $m) { @@ -413,7 +413,7 @@ class PrivateKey extends RSA implements Common\PrivateKey * Decryption * * @return bool|string - *@see self::encrypt() + * @see self::encrypt() */ public function decrypt(string $ciphertext) { diff --git a/phpseclib/Crypt/RSA/PublicKey.php b/phpseclib/Crypt/RSA/PublicKey.php index ebbf15ce..f50d5a12 100644 --- a/phpseclib/Crypt/RSA/PublicKey.php +++ b/phpseclib/Crypt/RSA/PublicKey.php @@ -62,7 +62,7 @@ class PublicKey extends RSA implements Common\PublicKey * * See {@link http://tools.ietf.org/html/rfc3447#section-8.2.2 RFC3447#section-8.2.2}. * - *@throws \LengthException if the RSA modulus is too short + * @throws \LengthException if the RSA modulus is too short */ private function rsassa_pkcs1_v1_5_verify(string $m, string $s): bool { @@ -305,7 +305,7 @@ class PublicKey extends RSA implements Common\PublicKey * * @param bool $pkcs15_compat optional * @return bool|string - *@throws \LengthException if strlen($m) > $this->k - 11 + * @throws \LengthException if strlen($m) > $this->k - 11 */ private function rsaes_pkcs1_v1_5_encrypt(string $m, bool $pkcs15_compat = false) { @@ -345,7 +345,7 @@ class PublicKey extends RSA implements Common\PublicKey * See {@link http://tools.ietf.org/html/rfc3447#section-7.1.1 RFC3447#section-7.1.1} and * {http://en.wikipedia.org/wiki/Optimal_Asymmetric_Encryption_Padding OAES}. * - *@throws \LengthException if strlen($m) > $this->k - 2 * $this->hLen - 2 + * @throws \LengthException if strlen($m) > $this->k - 2 * $this->hLen - 2 */ private function rsaes_oaep_encrypt(string $m): string { @@ -426,7 +426,7 @@ class PublicKey extends RSA implements Common\PublicKey * * @return bool|string * @throws \LengthException if the RSA modulus is too short - *@see self::decrypt() + * @see self::decrypt() */ public function encrypt(string $plaintext) { diff --git a/phpseclib/Crypt/Random.php b/phpseclib/Crypt/Random.php index 2b0e5f93..7d53833d 100644 --- a/phpseclib/Crypt/Random.php +++ b/phpseclib/Crypt/Random.php @@ -38,7 +38,7 @@ abstract class Random * microoptimizations because this function has the potential of being called a huge number of times. * eg. for RSA key generation. * - *@throws \RuntimeException if a symmetric cipher is needed but not loaded + * @throws \RuntimeException if a symmetric cipher is needed but not loaded */ public static function string(int $length): string { diff --git a/phpseclib/Crypt/Rijndael.php b/phpseclib/Crypt/Rijndael.php index 9d758561..f17e2b61 100644 --- a/phpseclib/Crypt/Rijndael.php +++ b/phpseclib/Crypt/Rijndael.php @@ -187,7 +187,7 @@ class Rijndael extends BlockCipher * the mcrypt php extension, even if available. * This results then in slower encryption. * - *@throws \LengthException if the key length is invalid + * @throws \LengthException if the key length is invalid */ public function setKeyLength(int $length): void { @@ -212,7 +212,7 @@ class Rijndael extends BlockCipher * Rijndael supports five different key lengths * * @throws \LengthException if the key length isn't supported - *@see setKeyLength() + * @see setKeyLength() */ public function setKey(string $key): void { @@ -259,7 +259,7 @@ class Rijndael extends BlockCipher * * This is mainly just a wrapper to set things up for \phpseclib3\Crypt\Common\SymmetricKey::isValidEngine() * - *@see \phpseclib3\Crypt\Common\SymmetricKey::__construct() + * @see \phpseclib3\Crypt\Common\SymmetricKey::__construct() */ protected function isValidEngineHelper(int $engine): bool { @@ -612,7 +612,7 @@ class Rijndael extends BlockCipher /** * Performs S-Box substitutions * - *@return array + * @return array */ private function subWord(int $word) { @@ -942,7 +942,7 @@ class Rijndael extends BlockCipher /** * Encrypts a message. * - *@see self::decrypt() + * @see self::decrypt() * @see parent::encrypt() */ public function encrypt(string $plaintext): string @@ -971,7 +971,7 @@ class Rijndael extends BlockCipher /** * Decrypts a message. * - *@see self::encrypt() + * @see self::encrypt() * @see parent::decrypt() */ public function decrypt(string $ciphertext): string diff --git a/phpseclib/Crypt/Salsa20.php b/phpseclib/Crypt/Salsa20.php index 0b8db7c8..9612678c 100644 --- a/phpseclib/Crypt/Salsa20.php +++ b/phpseclib/Crypt/Salsa20.php @@ -232,7 +232,7 @@ class Salsa20 extends StreamCipher * Encrypts a message. * * @return string $ciphertext - *@see \phpseclib3\Crypt\Common\SymmetricKey::decrypt() + * @see \phpseclib3\Crypt\Common\SymmetricKey::decrypt() * @see self::crypt() */ public function encrypt(string $plaintext): string @@ -251,7 +251,7 @@ class Salsa20 extends StreamCipher * At least if the continuous buffer is disabled. * * @return string $plaintext - *@see \phpseclib3\Crypt\Common\SymmetricKey::encrypt() + * @see \phpseclib3\Crypt\Common\SymmetricKey::encrypt() * @see self::crypt() */ public function decrypt(string $ciphertext): string @@ -293,7 +293,7 @@ class Salsa20 extends StreamCipher * Encrypts or decrypts a message. * * @return string $text - *@see self::decrypt() + * @see self::decrypt() * @see self::encrypt() */ private function crypt(string $text, int $mode): string @@ -465,7 +465,7 @@ class Salsa20 extends StreamCipher /** * Calculates Poly1305 MAC * - *@see self::decrypt() + * @see self::decrypt() * @see self::encrypt() */ protected function poly1305(string $text): string diff --git a/phpseclib/Crypt/TripleDES.php b/phpseclib/Crypt/TripleDES.php index 058bdc2b..6505df17 100644 --- a/phpseclib/Crypt/TripleDES.php +++ b/phpseclib/Crypt/TripleDES.php @@ -128,7 +128,7 @@ class TripleDES extends DES * * - cbc3 (same as cbc) * - *@see \phpseclib3\Crypt\Common\SymmetricKey::__construct() + * @see \phpseclib3\Crypt\Common\SymmetricKey::__construct() * @see \phpseclib3\Crypt\DES::__construct() */ public function __construct(string $mode) @@ -170,7 +170,7 @@ class TripleDES extends DES * * This is mainly just a wrapper to set things up for \phpseclib3\Crypt\Common\SymmetricKey::isValidEngine() * - *@see \phpseclib3\Crypt\Common\SymmetricKey::__construct() + * @see \phpseclib3\Crypt\Common\SymmetricKey::__construct() */ protected function isValidEngineHelper(int $engine): bool { @@ -188,7 +188,7 @@ class TripleDES extends DES * * SetIV is not required when \phpseclib3\Crypt\Common\SymmetricKey::MODE_ECB is being used. * - *@see \phpseclib3\Crypt\Common\SymmetricKey::setIV() + * @see \phpseclib3\Crypt\Common\SymmetricKey::setIV() */ public function setIV(string $iv): void { @@ -207,7 +207,7 @@ class TripleDES extends DES * * If you want to use a 64-bit key use DES.php * - *@throws \LengthException if the key length is invalid + * @throws \LengthException if the key length is invalid * @see \phpseclib3\Crypt\Common\SymmetricKey:setKeyLength() */ public function setKeyLength(int $length): void @@ -230,7 +230,7 @@ class TripleDES extends DES * * DES also requires that every eighth bit be a parity bit, however, we'll ignore that. * - *@throws \LengthException if the key length is invalid + * @throws \LengthException if the key length is invalid * @see \phpseclib3\Crypt\DES::setKey() * @see \phpseclib3\Crypt\Common\SymmetricKey::setKey() */ @@ -267,7 +267,7 @@ class TripleDES extends DES * Encrypts a message. * * @return string $cipertext - *@see \phpseclib3\Crypt\Common\SymmetricKey::encrypt() + * @see \phpseclib3\Crypt\Common\SymmetricKey::encrypt() */ public function encrypt(string $plaintext): string { @@ -292,7 +292,7 @@ class TripleDES extends DES * Decrypts a message. * * @return string $plaintext - *@see \phpseclib3\Crypt\Common\SymmetricKey::decrypt() + * @see \phpseclib3\Crypt\Common\SymmetricKey::decrypt() */ public function decrypt(string $ciphertext): string { @@ -413,7 +413,7 @@ class TripleDES extends DES /** * Sets the internal crypt engine * - *@see \phpseclib3\Crypt\Common\SymmetricKey::setPreferredEngine() + * @see \phpseclib3\Crypt\Common\SymmetricKey::setPreferredEngine() * @see \phpseclib3\Crypt\Common\SymmetricKey::__construct() */ public function setPreferredEngine(string $engine): void diff --git a/phpseclib/Crypt/Twofish.php b/phpseclib/Crypt/Twofish.php index cac16f1f..6ad04142 100644 --- a/phpseclib/Crypt/Twofish.php +++ b/phpseclib/Crypt/Twofish.php @@ -393,7 +393,7 @@ class Twofish extends BlockCipher * Rijndael supports five different key lengths * * @throws \LengthException if the key length isn't supported - *@see setKeyLength() + * @see setKeyLength() */ public function setKey(string $key): void { diff --git a/phpseclib/File/X509.php b/phpseclib/File/X509.php index 995b93bb..c87c2475 100644 --- a/phpseclib/File/X509.php +++ b/phpseclib/File/X509.php @@ -1340,7 +1340,7 @@ class X509 * Returns true if the signature is verified and false if it is not correct. * If the algorithms are unsupposed an exception is thrown. * - *@throws \phpseclib3\Exception\UnsupportedAlgorithmException if the algorithm is unsupported + * @throws \phpseclib3\Exception\UnsupportedAlgorithmException if the algorithm is unsupported */ private function validateSignatureHelper(string $publicKeyAlgorithm, string $publicKey, string $signatureAlgorithm, string $signature, string $signatureSubject): bool { diff --git a/phpseclib/Math/BigInteger/Engines/BCMath/Base.php b/phpseclib/Math/BigInteger/Engines/BCMath/Base.php index 01955285..3ad9c8cd 100644 --- a/phpseclib/Math/BigInteger/Engines/BCMath/Base.php +++ b/phpseclib/Math/BigInteger/Engines/BCMath/Base.php @@ -60,7 +60,7 @@ abstract class Base extends BCMath /** * Modular reduction preparation * - *@see self::slidingWindow() + * @see self::slidingWindow() */ protected static function prepareReduce(string $x, string $n, string $class): string { @@ -70,7 +70,7 @@ abstract class Base extends BCMath /** * Modular multiply * - *@see self::slidingWindow() + * @see self::slidingWindow() */ protected static function multiplyReduce(string $x, string $y, string $n, string $class): string { @@ -80,7 +80,7 @@ abstract class Base extends BCMath /** * Modular square * - *@see self::slidingWindow() + * @see self::slidingWindow() */ protected static function squareReduce(string $x, string $n, string $class): string { diff --git a/phpseclib/Math/BigInteger/Engines/PHP.php b/phpseclib/Math/BigInteger/Engines/PHP.php index e7b953fc..a8ea96bc 100644 --- a/phpseclib/Math/BigInteger/Engines/PHP.php +++ b/phpseclib/Math/BigInteger/Engines/PHP.php @@ -649,7 +649,7 @@ abstract class PHP extends Engine $result = []; for ($i = count($dividend) - 1; $i >= 0; --$i) { - $temp = static::BASE_FULL * $carry + $dividend[$i]; + $temp = static::BASE_FULL * $carry + (int) $dividend[$i]; $result[$i] = self::safe_divide($temp, $divisor); $carry = (int)($temp - $divisor * $result[$i]); } @@ -664,10 +664,8 @@ abstract class PHP extends Engine * if the dividend is not evenly divisible by the divisor. Since a float64 doesn't * have the precision of int64 this is a problem so, when int64 is being used, * we'll guarantee that the dividend is divisible by first subtracting the remainder. - * - * @return int */ - private static function safe_divide(int $x, int $y) + private static function safe_divide(int $x, int $y): int { if (static::BASE === 26) { return (int)($x / $y); diff --git a/phpseclib/Math/BigInteger/Engines/PHP/Base.php b/phpseclib/Math/BigInteger/Engines/PHP/Base.php index 2c5cf3b8..60ff9d14 100644 --- a/phpseclib/Math/BigInteger/Engines/PHP/Base.php +++ b/phpseclib/Math/BigInteger/Engines/PHP/Base.php @@ -92,7 +92,7 @@ abstract class Base extends PHP /** * Modular reduction preparation * - *@see self::slidingWindow() + * @see self::slidingWindow() */ protected static function prepareReduce(array $x, array $n, string $class): array { @@ -102,7 +102,7 @@ abstract class Base extends PHP /** * Modular multiply * - *@see self::slidingWindow() + * @see self::slidingWindow() */ protected static function multiplyReduce(array $x, array $y, array $n, string $class): array { @@ -113,7 +113,7 @@ abstract class Base extends PHP /** * Modular square * - *@see self::slidingWindow() + * @see self::slidingWindow() */ protected static function squareReduce(array $x, array $n, string $class): array { diff --git a/phpseclib/Math/BigInteger/Engines/PHP/Reductions/MontgomeryMult.php b/phpseclib/Math/BigInteger/Engines/PHP/Reductions/MontgomeryMult.php index b8fe81c9..f92fe0c1 100644 --- a/phpseclib/Math/BigInteger/Engines/PHP/Reductions/MontgomeryMult.php +++ b/phpseclib/Math/BigInteger/Engines/PHP/Reductions/MontgomeryMult.php @@ -31,7 +31,7 @@ abstract class MontgomeryMult extends Montgomery * {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=13 HAC 14.36} * * @param class-string $class - *@see self::_prepMontgomery() + * @see self::_prepMontgomery() * @see self::_montgomery() */ public static function multiplyReduce(array $x, array $y, array $m, string $class): array diff --git a/phpseclib/Math/BigInteger/Engines/PHP32.php b/phpseclib/Math/BigInteger/Engines/PHP32.php index 81fe4297..321cfd80 100644 --- a/phpseclib/Math/BigInteger/Engines/PHP32.php +++ b/phpseclib/Math/BigInteger/Engines/PHP32.php @@ -82,7 +82,7 @@ class PHP32 extends PHP } $step = count($vals) & 3; if ($step) { - $digit = floor($digit / pow(2, 2 * $step)); + $digit = floor($digit / 2 ** (2 * $step)); } if ($step != 3) { $digit &= static::MAX_DIGIT; diff --git a/phpseclib/Math/BinaryField/Integer.php b/phpseclib/Math/BinaryField/Integer.php index d59c9a6b..b6bb12c8 100644 --- a/phpseclib/Math/BinaryField/Integer.php +++ b/phpseclib/Math/BinaryField/Integer.php @@ -155,7 +155,7 @@ class Integer extends Base * @return string[] * @link https://en.wikipedia.org/wiki/Polynomial_greatest_common_divisor#Euclidean_division */ - private static function polynomialDivide($x, $y): array + private static function polynomialDivide(string $x, string $y): array { // in wikipedia's description of the algorithm, lc() is the leading coefficient. over a binary field that's // always going to be 1. @@ -184,7 +184,7 @@ class Integer extends Base * * @link https://en.wikipedia.org/wiki/Finite_field_arithmetic#Multiplication */ - private static function regularPolynomialMultiply($x, $y): string + private static function regularPolynomialMultiply(string $x, string $y): string { $precomputed = [ltrim($x, "\0")]; $x = strrev(BinaryField::base256ToBase2($x)); @@ -222,7 +222,7 @@ class Integer extends Base * * @link https://en.wikipedia.org/wiki/Karatsuba_algorithm */ - private static function polynomialMultiply($x, $y): string + private static function polynomialMultiply(string $x, string $y): string { if (strlen($x) == strlen($y)) { $length = strlen($x); @@ -430,7 +430,7 @@ class Integer extends Base /** * Returns the modulo */ - public static function getModulo($instanceID): string + public static function getModulo(int $instanceID): string { return static::$modulo[$instanceID]; } diff --git a/phpseclib/Math/PrimeField/Integer.php b/phpseclib/Math/PrimeField/Integer.php index f3730997..7096a720 100644 --- a/phpseclib/Math/PrimeField/Integer.php +++ b/phpseclib/Math/PrimeField/Integer.php @@ -94,7 +94,7 @@ class Integer extends Base /** * Delete the modulo for a given instance */ - public static function cleanupCache($instanceID): void + public static function cleanupCache(int $instanceID): void { unset(static::$modulo[$instanceID]); unset(static::$reduce[$instanceID]); diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index be96095f..f873732f 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -620,7 +620,7 @@ class SFTP extends SSH2 * If canonicalize_paths has been disabled using disablePathCanonicalization(), $path is returned as-is. * * @throws \UnexpectedValueException on receipt of unexpected packets - *@see self::chdir() + * @see self::chdir() * @see self::disablePathCanonicalization() */ public function realpath(string $path) @@ -706,7 +706,7 @@ class SFTP extends SSH2 /** * Changes the current directory * - *@throws \UnexpectedValueException on receipt of unexpected packets + * @throws \UnexpectedValueException on receipt of unexpected packets */ public function chdir(string $dir): bool { @@ -951,10 +951,8 @@ class SFTP extends SSH2 * Compares two rawlist entries using parameters set by setListOrder() * * Intended for use with uasort() - * - * @return int */ - private function comparator(array $a, array $b) + private function comparator(array $a, array $b): ?int { switch (true) { case $a['filename'] === '.' || $b['filename'] === '.': @@ -1006,6 +1004,7 @@ class SFTP extends SSH2 return $order === SORT_ASC ? $a[$sort] - $b[$sort] : $b[$sort] - $a[$sort]; } } + return null; } /** @@ -1254,7 +1253,7 @@ class SFTP extends SSH2 * The second parameter can be either PacketType::STAT or PacketType::LSTAT. * * @return array|false - *@throws \UnexpectedValueException on receipt of unexpected packets + * @throws \UnexpectedValueException on receipt of unexpected packets */ private function stat_helper(string $filename, int $type) { @@ -1290,7 +1289,7 @@ class SFTP extends SSH2 * * If the file does not exist, it will be created. * - *@throws \UnexpectedValueException on receipt of unexpected packets + * @throws \UnexpectedValueException on receipt of unexpected packets */ public function touch(string $filename, int $time = null, int $atime = null): bool { @@ -1450,7 +1449,7 @@ class SFTP extends SSH2 /** * Sets information about a file * - *@throws \UnexpectedValueException on receipt of unexpected packets + * @throws \UnexpectedValueException on receipt of unexpected packets */ private function setstat(string $filename, string $attr, bool $recursive): bool { @@ -1613,7 +1612,7 @@ class SFTP extends SSH2 * * symlink() creates a symbolic link to the existing target with the specified name link. * - *@throws \UnexpectedValueException on receipt of unexpected packets + * @throws \UnexpectedValueException on receipt of unexpected packets */ public function symlink(string $target, string $link): bool { @@ -1729,7 +1728,7 @@ class SFTP extends SSH2 /** * Removes a directory. * - *@throws \UnexpectedValueException on receipt of unexpected packets + * @throws \UnexpectedValueException on receipt of unexpected packets */ public function rmdir(string $dir): bool { @@ -2051,7 +2050,7 @@ class SFTP extends SSH2 * * @param string|bool|resource|callable $local_file * @return string|bool - *@throws \UnexpectedValueException on receipt of unexpected packets + * @throws \UnexpectedValueException on receipt of unexpected packets */ public function get(string $remote_file, $local_file = false, int $offset = 0, int $length = -1, callable $progressCallback = null) { diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index f0790a1b..154ea153 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -2797,7 +2797,7 @@ class SSH2 * * @return string|bool|null * @throws \RuntimeException on connection error - *@see self::write() + * @see self::write() */ public function read(string $expect = '', int $mode = self::READ_SIMPLE) { @@ -2842,7 +2842,7 @@ class SSH2 * Inputs a command into an interactive shell. * * @throws \RuntimeException on connection error - *@see SSH2::read() + * @see SSH2::read() */ public function write(string $cmd): void { @@ -2866,7 +2866,7 @@ class SSH2 * returns that and then that that was passed into stopSubsystem() but that'll be saved for a future date and implemented * if there's sufficient demand for such a feature. * - *@see self::stopSubsystem() + * @see self::stopSubsystem() */ public function startSubsystem(string $subsystem): bool { @@ -3058,7 +3058,7 @@ class SSH2 * See '6. Binary Packet Protocol' of rfc4253 for more info. * * @return bool|string - *@see self::_send_binary_packet() + * @see self::_send_binary_packet() */ private function get_binary_packet(bool $skip_channel_filter = false) { @@ -3311,7 +3311,7 @@ class SSH2 * Read Remaining Bytes * * @return string - *@see self::get_binary_packet() + * @see self::get_binary_packet() */ private function read_remaining_bytes(int $remaining_length) { @@ -3368,7 +3368,7 @@ class SSH2 * Because some binary packets need to be ignored... * * @return string|bool - *@see self::_get_binary_packet() + * @see self::_get_binary_packet() */ private function filter(string $payload, bool $skip_channel_filter) {