From 6958ba162782cafa4ae3e50b20b4ba7e83e153dd Mon Sep 17 00:00:00 2001 From: Jack Worman Date: Thu, 11 Aug 2022 08:25:16 -0500 Subject: [PATCH] php-cs-fixer @PHP81Migration rule set --- build/php-cs-fixer.php | 4 +- build/php_codesniffer.xml | 2 +- build/psalm_baseline.xml | 759 ++++++++++-------- composer.json | 2 +- phpseclib/Crypt/Common/AsymmetricKey.php | 6 +- .../Crypt/Common/Formats/Keys/OpenSSH.php | 2 +- phpseclib/Crypt/Common/Formats/Keys/PuTTY.php | 2 +- phpseclib/Crypt/DH/Formats/Keys/PKCS8.php | 2 +- phpseclib/Crypt/DSA/Formats/Keys/PKCS8.php | 2 +- phpseclib/Crypt/EC/Curves/Ed25519.php | 3 +- phpseclib/Crypt/EC/Curves/Ed448.php | 2 +- phpseclib/Crypt/EC/Formats/Keys/PKCS8.php | 2 +- phpseclib/Crypt/RSA/Formats/Keys/PKCS1.php | 4 +- phpseclib/Crypt/RSA/Formats/Keys/PKCS8.php | 4 +- phpseclib/Crypt/RSA/Formats/Keys/PSS.php | 2 +- phpseclib/File/ASN1.php | 5 +- phpseclib/Math/BigInteger/Engines/OpenSSL.php | 2 +- phpseclib/Math/BigInteger/Engines/PHP.php | 2 +- phpseclib/Net/SFTP.php | 26 +- phpseclib/Net/SSH2.php | 6 +- tests/Functional/Net/SFTPUserStoryTest.php | 6 +- tests/PhpseclibTestCase.php | 4 +- tests/Unit/Crypt/ChaCha20Test.php | 4 +- 23 files changed, 452 insertions(+), 401 deletions(-) diff --git a/build/php-cs-fixer.php b/build/php-cs-fixer.php index 359d1f9f..27fe4781 100644 --- a/build/php-cs-fixer.php +++ b/build/php-cs-fixer.php @@ -26,7 +26,7 @@ return (new PhpCsFixer\Config()) 'phpdoc_trim_consecutive_blank_line_separation' => true, 'phpdoc_trim' => true, - '@PHP74Migration' => true, - '@PHP74Migration:risky' => true, + '@PHP81Migration' => true, + '@PHP80Migration:risky' => true, ] ); diff --git a/build/php_codesniffer.xml b/build/php_codesniffer.xml index de09391e..4a7b18d7 100644 --- a/build/php_codesniffer.xml +++ b/build/php_codesniffer.xml @@ -6,7 +6,7 @@ - + diff --git a/build/psalm_baseline.xml b/build/psalm_baseline.xml index f012cc1a..078e7204 100644 --- a/build/psalm_baseline.xml +++ b/build/psalm_baseline.xml @@ -1,5 +1,5 @@ - + $var @@ -117,11 +117,13 @@ - + + pack("N*", $r, $l) + pack('L*', ...$cdata) pack('N*', $r ^ $p[0], $l ^ $p[1]) - pack('N*', $r ^ $p[17], $l ^ $p[16]) - + + string string string @@ -129,44 +131,48 @@ $j - - $sb_0[$l >> 24 & 0xff] + $sb_1[$l >> 16 & 0xff] - $sb_0[$l >> 24 & 0xff] + $sb_1[$l >> 16 & 0xff] - $sb_0[$r >> 24 & 0xff] + $sb_1[$r >> 16 & 0xff] - $sb_0[$r >> 24 & 0xff] + $sb_1[$r >> 16 & 0xff] + + $cdata[$j + 1] + $cdata[$j] + $l + $p + $r + $sb_0 + $sb_1 + $sb_2 + $sb_3 - - $p[$i + 1] + + $p + $sbox0 + $sbox1 + $sbox2 + $sbox3 + $sha2pass + $sha2pass + $sha2salt + $sha2salt + + $p[$i + 1] $p[$i - 1] $p[$i - 1] $p[$i] $p[$i] $p[$i] - $p[$i] $p[0] $p[0] $p[16] - $p[16] - $p[17] $p[17] $p[1] $p[1] $sb_0[$l >> 24 & 0xff] - $sb_0[$l >> 24 & 0xff] - $sb_0[$r >> 24 & 0xff] $sb_0[$r >> 24 & 0xff] $sb_1[$l >> 16 & 0xff] - $sb_1[$l >> 16 & 0xff] - $sb_1[$r >> 16 & 0xff] $sb_1[$r >> 16 & 0xff] $sb_2[$l >> 8 & 0xff] - $sb_2[$l >> 8 & 0xff] - $sb_2[$r >> 8 & 0xff] $sb_2[$r >> 8 & 0xff] $sb_3[$l & 0xff] - $sb_3[$l & 0xff] - $sb_3[$r & 0xff] $sb_3[$r & 0xff] $this->bctx['sb'][0] $this->bctx['sb'][0] @@ -177,32 +183,22 @@ $this->bctx['sb'][3] $this->bctx['sb'][3] - - $sb_0[$l >> 24 & 0xff] + $sb_0[$l >> 24 & 0xff] $sb_0[$r >> 24 & 0xff] - $sb_0[$r >> 24 & 0xff] - $sb_1[$l >> 16 & 0xff] $sb_1[$l >> 16 & 0xff] $sb_1[$r >> 16 & 0xff] - $sb_1[$r >> 16 & 0xff] - $sb_2[$l >> 8 & 0xff] $sb_2[$l >> 8 & 0xff] $sb_2[$r >> 8 & 0xff] - $sb_2[$r >> 8 & 0xff] $sb_3[$l & 0xff] - $sb_3[$l & 0xff] - $sb_3[$r & 0xff] $sb_3[$r & 0xff] - + $data $l $l $l $l - $l - $l $p $p $p @@ -210,8 +206,6 @@ $r $r $r - $r - $r $sb_0 $sb_0 $sb_1 @@ -221,7 +215,7 @@ $sb_3 $sb_3 - + $data $l $l @@ -230,13 +224,6 @@ $l $l $l - $l - $l - $l - $l - $l - $l - $l $p[$i + 1] $p[$i - 1] $p[$i] @@ -252,28 +239,25 @@ $r $r $r - $r - $r - $r - $r - $r - $r - $r - $sb_0[$l >> 24 & 0xff] $sb_0[$l >> 24 & 0xff] $sb_0[$r >> 24 & 0xff] - $sb_0[$r >> 24 & 0xff] - $sb_2[$l >> 8 & 0xff] - $sb_2[$l >> 8 & 0xff] - $sb_2[$r >> 8 & 0xff] - $sb_2[$r >> 8 & 0xff] self::$parray[$i] - + + $sha2pass + $sha2pass + $sha2salt + $sha2salt unpack('C*', $this->key) unpack('N*', $data = $this->encryptBlock($data)) unpack('N*', $data = $this->encryptBlock($data)) + unpack('N*', $sha2pass) + unpack('N*', $sha2salt) + unpack('N*', 'OxychromaticBlowfishSwatDynamite') + + pack('N', $count++) + $in[1] $in[1] @@ -283,11 +267,113 @@ $this->openssl_translate_mode() - + + $data[0] + $data[1] + $data[2] + $data[3] $in[1] $in[1] $in[2] $in[2] + $key[0] + $key[0] + $key[10] + $key[10] + $key[11] + $key[11] + $key[12] + $key[12] + $key[13] + $key[13] + $key[14] + $key[14] + $key[15] + $key[15] + $key[1] + $key[1] + $key[2] + $key[2] + $key[3] + $key[3] + $key[4] + $key[4] + $key[5] + $key[5] + $key[6] + $key[6] + $key[7] + $key[7] + $key[8] + $key[8] + $key[9] + $key[9] + $p[0] + $p[0] + $p[0] + $p[10] + $p[10] + $p[10] + $p[11] + $p[11] + $p[11] + $p[12] + $p[12] + $p[12] + $p[13] + $p[13] + $p[13] + $p[14] + $p[14] + $p[14] + $p[15] + $p[15] + $p[15] + $p[16] + $p[16] + $p[16] + $p[17] + $p[17] + $p[17] + $p[1] + $p[1] + $p[1] + $p[2] + $p[2] + $p[2] + $p[3] + $p[3] + $p[3] + $p[4] + $p[4] + $p[4] + $p[5] + $p[5] + $p[5] + $p[6] + $p[6] + $p[6] + $p[7] + $p[7] + $p[7] + $p[8] + $p[8] + $p[8] + $p[9] + $p[9] + $p[9] + $sbox0[254] + $sbox0[254] + $sbox0[255] + $sbox0[255] + $sbox1[254] + $sbox1[254] + $sbox1[255] + $sbox1[255] + $sbox2[254] + $sbox2[254] + $sbox2[255] + $sbox2[255] $this->bctx['p'] @@ -1726,14 +1812,18 @@ -$rolen self::$invisiblePlugins[static::ALGORITHM] - + $components['comment'] + $components['secret'] + $components['secret'] self::$plugins[static::ALGORITHM]['Keys'] self::$plugins[static::ALGORITHM]['Keys'] - + $components['format'] $components['format'] + $components['secret'] + $components['secret'] self::$invisiblePlugins[static::ALGORITHM][] self::$plugins[static::ALGORITHM][$format] self::$plugins[static::ALGORITHM][$format] @@ -1752,12 +1842,14 @@ self::$plugins[static::ALGORITHM] self::$plugins[static::ALGORITHM] - + $comment $components $components $components['format'] $components['format'] + $components['secret'] + $components['secret'] $format $format $new @@ -1858,29 +1950,49 @@ - + + $salt + 32 + 32 + + $checkint $checkint $comment $kdfoptions $paddedKey $publicKey + $rounds + $rounds + $rounds + $salt $type $type static::$types static::$types - + $comment + $paddedKey + $rounds - + + decrypt + + $asciiType + $ciphername + $kdfname + + $rounds + $checkint - + $key + $password $parts[0] @@ -1888,8 +2000,7 @@ setBinaryOutput - - !empty($password) && is_string($password) + is_string($password) @@ -2458,13 +2569,17 @@ openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING) openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING) - + $func_args[0] + $salt $xor[0] $xor[0] + + $salt + string @@ -2475,16 +2590,10 @@ $length >> 3 - - $x - - - int - setupKey - + $buffer['ciphertext'] $buffer['ciphertext'] $buffer['ciphertext'] @@ -2523,6 +2632,9 @@ $key $key $key + $keylen + $keylen + $keylen + $this->block_size $len $len $one @@ -2544,11 +2656,10 @@ -$overflow -$overflow - $this->block_size - + $reverseMap[$engine] - $this->buffer['pos'] - + $bindedClosure $ciphertext $decrypt_block @@ -2562,6 +2673,7 @@ $init_decrypt $init_encrypt $key_length + $keylen $len $len $len @@ -2598,7 +2710,7 @@ string string - + $buffer['ciphertext'] $buffer['ciphertext'] $buffer['ciphertext'] @@ -2651,6 +2763,7 @@ $init_encrypt $init_encrypt $key_length + $keylen $len $len $len @@ -2712,7 +2825,7 @@ false false - + $count $count $count @@ -2720,6 +2833,9 @@ $dkLen $dkLen $dkLen + $keylen + $keylen + $rounds $salt $salt @@ -2737,7 +2853,10 @@ null - + + $func_args[0] + + $buffer['ciphertext'] $buffer['ciphertext'] $buffer['ciphertext'] @@ -2772,6 +2891,7 @@ $buffer['xor'] $cipher_code['decrypt_block'] $cipher_code['encrypt_block'] + $this->debuffer['pos'] $this->enbuffer['pos'] @@ -2828,25 +2948,16 @@ setupInlineCrypt - - $this->h->key - - - $this->h->key - $this->key_length - $this->buffer + $this->key_length $this->key_length $this->key_length $this->openssl_options $this->openssl_options - - break; - new static('ctr') new static('ctr') @@ -3164,8 +3275,9 @@ $key_length $openssl_mode_names - + $keys + $kl DES DES DES @@ -3176,9 +3288,6 @@ DES DES - - $this->kl - @@ -3201,10 +3310,8 @@ $new->publicKey $type - + $type::saveParameters($this->prime, $this->base) - powMod - toBytes $args[0] @@ -3219,13 +3326,9 @@ onLoad - + $new->privateKey - $new->publicKey - - $public->publicKey - @@ -3295,7 +3398,8 @@ $type::saveParameters($this->prime, $this->base, $options) - + + Parameters Parameters Parameters Parameters @@ -3342,26 +3446,21 @@ $type - - \phpseclib3\Math\BigInteger + string $type::savePublicKey($this->prime, $this->base, $this->publicKey, $options) - - $this->publicKey + $type::savePublicKey($this->prime, $this->base, $this->publicKey, $options) - + + PublicKey PublicKey PublicKey PublicKey - - $this->publicKey - $this->publicKey - @@ -3788,26 +3887,39 @@ getParameters - + $components['curve']::HASH + $curve->getBasePoint() $curve::HASH + $dA $dA->toBytes() $decoded[0] $key $params $this->QA[0]->toBytes(true) - + + $arr['dA'] + $arr['secret'] + + + $arr + $dA $dA $key $new->QA $new->curve $new->curve $new->dA + $new->secret + $new->sigFormat $params $privatekey->QA $privatekey->dA + $privatekey->dA + $privatekey->secret $this->curveName + $this->sigFormat $type @@ -3855,10 +3967,11 @@ $this->QA[0] $this->QA[1] - + $components['QA'] $components['curve'] $components['curve'] + $components['secret'] self::$engines['OpenSSL'] self::$engines['libsodium'] self::$engines['libsodium'] @@ -3892,19 +4005,17 @@ is_string($context) - + $decoded encodePoint + extractSecret withSignatureFormat $new->dA - $new->sigFormat + $new->secret $privatekey->curveName - - $this->sigFormat - $namedCurves @@ -4105,6 +4216,9 @@ $this->p[0] + + static::extendedGCD($lambda->toBigInteger(), $this->order) + BigInteger[] @@ -4112,69 +4226,49 @@ $p - + + $basis + $beta + + $basis['a']->toHex(true) $basis['b']->toHex(true) + $k + $one + $one $one $p $p['naf'] - $r->multiply($two) - $r->multiply($two) $rhs $two + $two - - $c1 - $c2 + $p['naf'] $p['nafwidth'] $p[0] $p[0] $p[1] $p[1] - $r - $r - $v1 - $v1['a'] - $v1['b'] - $v1['b'] - $v2 - $v2['a'] - $v2['b'] - $v2['b'] - + $a2 $b2 $beta['nafwidth'] - $c1 - $c1 - $c2 - $c2 $inv $k - $k1 - $k1 - $k2 - $k2 $lhs $lhs $npoints[$pos] $nscalars[$pos] $nscalars[$pos] $p - $p1 - $p2 - $q1 - $q2 $rhs $rhs $rhs $s $temp - [$c1, $r] - [$c2, $r] - [$v1, $v2] + $this->beta FiniteField[] @@ -4182,21 +4276,14 @@ FiniteField[] boolean - - add - add - add + add add add compare divide - divide - divide equals equals - isNegative - isNegative multiply multiply multiply @@ -4206,25 +4293,11 @@ multiply multiply multiply - multiply - multiply - multiply - multiply - multiply - multiply - multiply - multiply - negate - negate - negate - negate negate negate negate squareRoot subtract - subtract - subtract toBigInteger toHex toHex @@ -4244,6 +4317,10 @@ $b0 $b0 + + isset($this->basis) + isset($this->beta) + $this->factory $this->factory @@ -4255,10 +4332,6 @@ $basis $basis - - $this->basis - $this->beta - @@ -4718,15 +4791,9 @@ - - $dA - $this->extractSecret(Random::string(32)) + clone $this->zero - - BigInteger - \phpseclib3\Math\PrimeField\Integer - [clone $this->zero, clone $this->one, clone $this->one, clone $this->zero] @@ -4755,7 +4822,8 @@ $y[0] $y[0] - + + BigInteger FiniteField[] FiniteField[] @@ -4785,6 +4853,9 @@ $y[0] $y[0] + + $this->extractSecret(Random::string(32))['dA'] + $p $p @@ -4796,6 +4867,9 @@ $p[0] $p[1] + + $this->extractSecret(Random::string(32))['dA'] + addPoint doublePoint @@ -4817,20 +4891,11 @@ FiniteField[] FiniteField[] - - $dA->secret - - - $dA - $this->extractSecret(Random::string(57)) + clone $this->zero - - BigInteger - \phpseclib3\Math\PrimeField\Integer - [clone $this->zero, clone $this->one, clone $this->one] @@ -4843,7 +4908,8 @@ $y $y2 - + + BigInteger FiniteField[] FiniteField[] @@ -4866,6 +4932,9 @@ $y->toBytes() + + $this->extractSecret(Random::string(57))['dA'] + $p $p @@ -4873,6 +4942,9 @@ \phpseclib3\Math\PrimeField\Integer[] object[] + + $this->extractSecret(Random::string(57))['dA'] + addPoint doublePoint @@ -4895,9 +4967,6 @@ FiniteField[] FiniteField[] - - $dA->secret - @@ -5384,6 +5453,9 @@ + + $this->beta + newInteger @@ -5403,12 +5475,6 @@ $this->factory - - $this->basis - $this->basis - $this->basis - $this->beta - $this->factory @@ -5453,6 +5519,9 @@ + + $this->beta + newInteger @@ -5472,12 +5541,6 @@ $this->factory - - $this->basis - $this->basis - $this->basis - $this->beta - $this->factory @@ -5501,6 +5564,9 @@ + + $this->beta + newInteger @@ -5520,12 +5586,6 @@ $this->factory - - $this->basis - $this->basis - $this->basis - $this->beta - $this->factory @@ -5549,6 +5609,9 @@ + + $this->beta + newInteger @@ -5568,12 +5631,6 @@ $this->factory - - $this->basis - $this->basis - $this->basis - $this->beta - $this->factory @@ -6103,14 +6160,16 @@ new $curveName() - + + string|false + + $key $paddedKey $parsed['publicKey'] $parsed['publicKey'] $parsed['publicKey'] $privateKey - $privateKey->secret $comment @@ -6133,6 +6192,10 @@ rangeCheck + + $password + $password + $publicKey[0] $publicKey[0] @@ -6224,11 +6287,9 @@ - - $components['dA'] - - + $components['curve']->getBasePoint() + $components['dA'] $curve->encodePoint($publicKey) $decoded[0] $decoded[0] @@ -6246,9 +6307,12 @@ $key['privateKeyAlgorithm']['algorithm'] $key['publicKeyAlgorithm']['algorithm'] - + + $components['dA'] + $components['secret'] + + $key['publicKey'] - $privateKey->secret $key[$type . 'Algorithm']['parameters']->element @@ -6278,6 +6342,9 @@ $key['privateKey'] + + $secret + $key @@ -6293,7 +6360,9 @@ $publicKey[1] $publicKey[1] - + + $arr['dA'] + $arr['secret'] $key[$type . 'Algorithm'] $key[$type . 'Algorithm'] $key['privateKey'] @@ -6317,25 +6386,27 @@ toBytes toBytes - - $privateKey->secret - $publicKey - + $components['type'] $length $length $private $private $private - $privateKey->secret - + + $arr['dA'] + $arr['secret'] + + + $arr $components['dA'] + $components['secret'] $private @@ -6350,8 +6421,9 @@ $length $length - + $password + $secret $public[1] @@ -6376,9 +6448,6 @@ extractSecret - - $privateKey->secret - @@ -6573,16 +6642,21 @@ $curve->multiplyPoint($curve->getBasePoint(), $components['dA']) - - $components['dA'] - + $components['dA'] $private - $privateKey->secret + + $components['dA'] + $components['secret'] + $components['dA'] + + $arr['dA'] + $arr['secret'] + savePrivateKey savePublicKey @@ -6685,11 +6759,18 @@ $this->dA $this->dA + + $format === false + + + $format::save($r, $s) + $format::save($r, $s, $this->getCurve()) + getPublicKey sign - + $curve::HASH $curve::SIZE $curve::SIZE @@ -6697,16 +6778,14 @@ $key $point[0]->toBytes(true) $this->curve->getBasePoint() - $this->dA->secret $this->dA->toBytes() $r - + $A $R - $format $key $key $key @@ -6719,12 +6798,10 @@ string string - - $format::save($r, $s) + $format::save($r, $s) $format::save($r, $s, $this->getCurve()) - $format::save($r, $s, $this->getCurve()) - $type::savePrivateKey($this->dA, $this->curve, $this->QA, $this->password, $options) + $type::savePrivateKey($this->dA, $this->curve, $this->QA, $this->secret, $this->password, $options) $type::savePublicKey($this->curve, $this->QA) divide equals @@ -6746,7 +6823,7 @@ $this->curve->encodePoint($point) - $type::savePrivateKey($this->dA, $this->curve, $this->QA, $this->password, $options) + $type::savePrivateKey($this->dA, $this->curve, $this->QA, $this->secret, $this->password, $options) $this->getCurve() @@ -6796,17 +6873,20 @@ getBasePoint withSignatureFormat - - $this->sigFormat - $y + + $format === false + toBigInteger + + $format::load($signature) + $Ln $curve::HASH @@ -6831,10 +6911,9 @@ $u2 $x1 - + $A $Ln - $format $n_1 $params $rhs @@ -6849,8 +6928,7 @@ bool string - - $format::load($signature) + $type::savePublicKey($this->curve, $this->QA, $options) between between @@ -6909,9 +6987,6 @@ encodePoint getBasePoint - - $this->sigFormat - @@ -7148,9 +7223,7 @@ $algo($text, ...array_values($this->parameters)) call_user_func($this->algo, $this->key) - - int - int + string @@ -7215,7 +7288,7 @@ toBytes toBytes - + $hash[0]->toBytes() $hash[2]->toBytes() $hash[3]->toBytes() @@ -7269,7 +7342,6 @@ $st[$i][4] $st[$i][4][0] $st[$i][4][1] - $this->blockSize unpack('C', $index)[1] ~$st[$i][0] ~$st[$i][0][0] @@ -7287,9 +7359,7 @@ ~$st[$i][4][0] ~$st[$i][4][1] - - $this->blockSize - $this->blockSize >> 3 + $y->toBytes() @@ -7402,8 +7472,9 @@ $index - + $algo + $blockSize $c $hashParam $ipad @@ -7416,21 +7487,6 @@ hash($this->algo, $this->key, true) is_string($this->key) - - $this->blockSize - $this->blockSize - $this->blockSize - $this->blockSize - $this->blockSize - $this->blockSize - $this->blockSize - $this->blockSize - $this->blockSize - - - $this->blockSize - $this->blockSize - $b @@ -7726,6 +7782,10 @@ RSA::load($privatekeystr) + + $privateExponent + $publicExponent + $bits $components['MGFHash'] @@ -7863,12 +7923,10 @@ !isset($this->modulus) $this->modulus->getLength() - + $key->coefficients $key->exponents $key->primes - $key->privateExponent - $key->publicExponent $i0 @@ -8245,9 +8303,9 @@ - function ($var) { - function ($var) { - function ($var) { + fn ($var) => clone $var + fn ($var) => clone $var + fn ($var) => clone $var $components['primes'][1] @@ -8338,9 +8396,6 @@ string - - $publicExponent - $key $r @@ -8517,9 +8572,6 @@ $decoded $decoded - - $this->publicExponent - $pkcs15_compat @@ -8528,8 +8580,7 @@ $length - - 0 + 1 @@ -8560,9 +8611,8 @@ $r $r - + $old_session_id - $old_use_cookies isset($_COOKIE) @@ -9196,13 +9246,7 @@ string - - $A + $B - $A + $B - $A + $B - $A + $B - $A + $B - $A + $B + $le_longs[1] $le_longs[1] $le_longs[1] @@ -9221,14 +9265,6 @@ $le_longs[6] $le_longs[7] $le_longs[8] - $t0 + $t1 + $K[++$ki] - $t0 + $t1 + $K[++$ki] - $t0 + $t1 + $K[--$ki] - $t0 + $t1 + $K[--$ki] - $t0 + ($t1 << 1) + $K[++$ki] - $t0 + ($t1 << 1) + $K[++$ki] - $t0 + ($t1 << 1) + $K[--$ki] - $t0 + ($t1 << 1) + $K[--$ki] $S0[ $R0 & 0xff] @@ -9372,7 +9408,13 @@ $q1[$q1[$q0[$q1[$i] ^ $sf] ^ $sb] ^ $s7] $q1[$q1[$q0[$q1[$j] ^ $key[32]] ^ $key[24]] ^ $key[16]] - + + $A + $A + $A + $A + $A + $A $A $A $A @@ -9382,6 +9424,12 @@ $B $B $B + $K[] + $K[] + $K[] + $K[] + $K[] + $K[] $R0 $R0 $R0 @@ -9423,13 +9471,19 @@ $t1 $t1 - + + $A + $A + $A + $A + $A + $A + $A + $A + $A $A $A $A - $B - $B - $B $B $B $B @@ -10603,7 +10657,7 @@ $x - function ($x) { + fn ($x) => '\x' . bin2hex($x[0]) $dn @@ -11785,7 +11839,7 @@ $this->value[0] $y->value[0] - + $current $current $current @@ -11810,7 +11864,6 @@ $this->value $this->value $this->value - $this->value $u $v $v @@ -12778,6 +12831,9 @@ toBytes + + new $class($result, 256) + @@ -12788,11 +12844,10 @@ $x - + $prime $s $temp - $temp $temp->value $temp[self::VALUE] $temp[self::VALUE] @@ -13722,7 +13777,7 @@ $custom_reduction - + $class::BASE_FULL $class::BASE_FULL $class::MAX_DIGIT2 @@ -13730,11 +13785,13 @@ $class::MAX_DIGIT2 $class::MAX_DIGIT2 $known[$j] * $class::BASE_FULL + $known[$i] - $m - $m->value $m1 $u + + array_map(self::class . '::float2string', $m) + array_map(self::class . '::float2string', $m->value) + $m1 $u @@ -13808,18 +13865,10 @@ $m->value $m->value - - $m - $m->value - generateCustomReduction reduce - - $m - $m->value - @@ -14362,8 +14411,7 @@ randomInteger setReduction - - $this->modulo + $this->reduce @@ -15524,6 +15572,7 @@ $this->decryptInvocationCounter $this->encryptInvocationCounter array_shift($this->message_log) + preg_replace_callback('#.#s', fn ($matches) => $this->log_boundary . str_pad(dechex(ord($matches[0])), 2, '0', STR_PAD_LEFT), $fragment) $raw @@ -16255,7 +16304,7 @@ callFunc getVar - + $expected $expected $filename @@ -16263,8 +16312,6 @@ $func $obj $obj - $obj - $obj $params $value $var @@ -16848,12 +16895,20 @@ - - $components['dA'] - $key + + $components['dA'] + + + $components['dA'] + $components['secret'] + + + $arr['dA'] + $arr['secret'] + load diff --git a/composer.json b/composer.json index 9c1244f0..9b94c1b6 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,7 @@ } ], "require": { - "php": ">=7.3", + "php": ">=8.1", "paragonie/constant_time_encoding": "^2" }, "require-dev": { diff --git a/phpseclib/Crypt/Common/AsymmetricKey.php b/phpseclib/Crypt/Common/AsymmetricKey.php index 465dbbb5..9e1f7aad 100644 --- a/phpseclib/Crypt/Common/AsymmetricKey.php +++ b/phpseclib/Crypt/Common/AsymmetricKey.php @@ -15,9 +15,7 @@ declare(strict_types=1); namespace phpseclib3\Crypt\Common; -use phpseclib3\Crypt\DSA; use phpseclib3\Crypt\Hash; -use phpseclib3\Crypt\RSA; use phpseclib3\Exception\NoKeyLoadedException; use phpseclib3\Exception\UnsupportedFormatException; use phpseclib3\Math\BigInteger; @@ -152,7 +150,7 @@ abstract class AsymmetricKey } $components['format'] = $format; - $components['secret'] = $components['secret'] ?? ''; + $components['secret'] ??= ''; $comment = $components['comment'] ?? null; $new = static::onLoad($components); $new->format = $format; @@ -226,7 +224,7 @@ abstract class AsymmetricKey } $components['format'] = $format; - $components['secret'] = $components['secret'] ?? ''; + $components['secret'] ??= ''; $new = static::onLoad($components); $new->format = $format; diff --git a/phpseclib/Crypt/Common/Formats/Keys/OpenSSH.php b/phpseclib/Crypt/Common/Formats/Keys/OpenSSH.php index f42d1ade..46ae7dfa 100644 --- a/phpseclib/Crypt/Common/Formats/Keys/OpenSSH.php +++ b/phpseclib/Crypt/Common/Formats/Keys/OpenSSH.php @@ -67,7 +67,7 @@ abstract class OpenSSH // key format is described here: // https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.key?annotate=HEAD - if (strpos($key, 'BEGIN OPENSSH PRIVATE KEY') !== false) { + if (str_contains($key, 'BEGIN OPENSSH PRIVATE KEY')) { $key = preg_replace('#(?:^-.*?-[\r\n]*$)|\s#ms', '', $key); $key = Base64::decode($key); $magic = Strings::shift($key, 15); diff --git a/phpseclib/Crypt/Common/Formats/Keys/PuTTY.php b/phpseclib/Crypt/Common/Formats/Keys/PuTTY.php index 52386b46..fde255f0 100644 --- a/phpseclib/Crypt/Common/Formats/Keys/PuTTY.php +++ b/phpseclib/Crypt/Common/Formats/Keys/PuTTY.php @@ -122,7 +122,7 @@ abstract class PuTTY throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key)); } - if (strpos($key, 'BEGIN SSH2 PUBLIC KEY') !== false) { + if (str_contains($key, 'BEGIN SSH2 PUBLIC KEY')) { $lines = preg_split('#[\r\n]+#', $key); switch (true) { case $lines[0] != '---- BEGIN SSH2 PUBLIC KEY ----': diff --git a/phpseclib/Crypt/DH/Formats/Keys/PKCS8.php b/phpseclib/Crypt/DH/Formats/Keys/PKCS8.php index c774f0c0..2918af16 100644 --- a/phpseclib/Crypt/DH/Formats/Keys/PKCS8.php +++ b/phpseclib/Crypt/DH/Formats/Keys/PKCS8.php @@ -66,7 +66,7 @@ abstract class PKCS8 extends Progenitor throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key)); } - $isPublic = strpos($key, 'PUBLIC') !== false; + $isPublic = str_contains($key, 'PUBLIC'); $key = parent::load($key, $password); diff --git a/phpseclib/Crypt/DSA/Formats/Keys/PKCS8.php b/phpseclib/Crypt/DSA/Formats/Keys/PKCS8.php index f5a440a0..f90ead08 100644 --- a/phpseclib/Crypt/DSA/Formats/Keys/PKCS8.php +++ b/phpseclib/Crypt/DSA/Formats/Keys/PKCS8.php @@ -70,7 +70,7 @@ abstract class PKCS8 extends Progenitor throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key)); } - $isPublic = strpos($key, 'PUBLIC') !== false; + $isPublic = str_contains($key, 'PUBLIC'); $key = parent::load($key, $password); diff --git a/phpseclib/Crypt/EC/Curves/Ed25519.php b/phpseclib/Crypt/EC/Curves/Ed25519.php index fd467dea..74e0b2b3 100644 --- a/phpseclib/Crypt/EC/Curves/Ed25519.php +++ b/phpseclib/Crypt/EC/Curves/Ed25519.php @@ -18,7 +18,6 @@ use phpseclib3\Crypt\EC\BaseCurves\TwistedEdwards; use phpseclib3\Crypt\Hash; use phpseclib3\Crypt\Random; use phpseclib3\Math\BigInteger; -use phpseclib3\Math\PrimeField\Integer; class Ed25519 extends TwistedEdwards { @@ -182,7 +181,7 @@ class Ed25519 extends TwistedEdwards return [ 'dA' => $dA, - 'secret' => $str + 'secret' => $str, ]; } diff --git a/phpseclib/Crypt/EC/Curves/Ed448.php b/phpseclib/Crypt/EC/Curves/Ed448.php index b0b0827a..52920e01 100644 --- a/phpseclib/Crypt/EC/Curves/Ed448.php +++ b/phpseclib/Crypt/EC/Curves/Ed448.php @@ -123,7 +123,7 @@ class Ed448 extends TwistedEdwards return [ 'dA' => $dA, - 'secret' => $str + 'secret' => $str, ]; } diff --git a/phpseclib/Crypt/EC/Formats/Keys/PKCS8.php b/phpseclib/Crypt/EC/Formats/Keys/PKCS8.php index c1c89c67..01e9db8f 100644 --- a/phpseclib/Crypt/EC/Formats/Keys/PKCS8.php +++ b/phpseclib/Crypt/EC/Formats/Keys/PKCS8.php @@ -79,7 +79,7 @@ abstract class PKCS8 extends Progenitor throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key)); } - $isPublic = strpos($key, 'PUBLIC') !== false; + $isPublic = str_contains($key, 'PUBLIC'); $key = parent::load($key, $password); diff --git a/phpseclib/Crypt/RSA/Formats/Keys/PKCS1.php b/phpseclib/Crypt/RSA/Formats/Keys/PKCS1.php index 0a35afba..eb08ad2b 100644 --- a/phpseclib/Crypt/RSA/Formats/Keys/PKCS1.php +++ b/phpseclib/Crypt/RSA/Formats/Keys/PKCS1.php @@ -49,9 +49,9 @@ abstract class PKCS1 extends Progenitor throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key)); } - if (strpos($key, 'PUBLIC') !== false) { + if (str_contains($key, 'PUBLIC')) { $components = ['isPublicKey' => true]; - } elseif (strpos($key, 'PRIVATE') !== false) { + } elseif (str_contains($key, 'PRIVATE')) { $components = ['isPublicKey' => false]; } else { $components = []; diff --git a/phpseclib/Crypt/RSA/Formats/Keys/PKCS8.php b/phpseclib/Crypt/RSA/Formats/Keys/PKCS8.php index 6a6495a4..3c452eb5 100644 --- a/phpseclib/Crypt/RSA/Formats/Keys/PKCS8.php +++ b/phpseclib/Crypt/RSA/Formats/Keys/PKCS8.php @@ -71,9 +71,9 @@ abstract class PKCS8 extends Progenitor throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key)); } - if (strpos($key, 'PUBLIC') !== false) { + if (str_contains($key, 'PUBLIC')) { $components = ['isPublicKey' => true]; - } elseif (strpos($key, 'PRIVATE') !== false) { + } elseif (str_contains($key, 'PRIVATE')) { $components = ['isPublicKey' => false]; } else { $components = []; diff --git a/phpseclib/Crypt/RSA/Formats/Keys/PSS.php b/phpseclib/Crypt/RSA/Formats/Keys/PSS.php index bf3b09bb..5db9aad0 100644 --- a/phpseclib/Crypt/RSA/Formats/Keys/PSS.php +++ b/phpseclib/Crypt/RSA/Formats/Keys/PSS.php @@ -103,7 +103,7 @@ abstract class PSS extends Progenitor throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key)); } - $components = ['isPublicKey' => strpos($key, 'PUBLIC') !== false]; + $components = ['isPublicKey' => str_contains($key, 'PUBLIC')]; $key = parent::load($key, $password); diff --git a/phpseclib/File/ASN1.php b/phpseclib/File/ASN1.php index 7b83e8d8..6f25c59f 100644 --- a/phpseclib/File/ASN1.php +++ b/phpseclib/File/ASN1.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace phpseclib3\File; -use DateTime; use ParagonIE\ConstantTime\Base64; use phpseclib3\Common\Functions\Strings; use phpseclib3\File\ASN1\Element; @@ -1253,7 +1252,7 @@ abstract class ASN1 } $prefix = substr($content, 0, 2) >= 50 ? '19' : '20'; $content = $prefix . $content; - } elseif (strpos($content, '.') !== false) { + } elseif (str_contains($content, '.')) { $format .= '.u'; } @@ -1261,7 +1260,7 @@ abstract class ASN1 $content = substr($content, 0, -1) . '+0000'; } - if (strpos($content, '-') !== false || strpos($content, '+') !== false) { + if (str_contains($content, '-') || str_contains($content, '+')) { $format .= 'O'; } diff --git a/phpseclib/Math/BigInteger/Engines/OpenSSL.php b/phpseclib/Math/BigInteger/Engines/OpenSSL.php index 7042037e..142f28cd 100644 --- a/phpseclib/Math/BigInteger/Engines/OpenSSL.php +++ b/phpseclib/Math/BigInteger/Engines/OpenSSL.php @@ -57,7 +57,7 @@ abstract class OpenSSL throw new \UnexpectedValueException(openssl_error_string()); } - $class = get_class($x); + $class = $x::class; return new $class($result, 256); } } diff --git a/phpseclib/Math/BigInteger/Engines/PHP.php b/phpseclib/Math/BigInteger/Engines/PHP.php index 6fcf472e..f65af19c 100644 --- a/phpseclib/Math/BigInteger/Engines/PHP.php +++ b/phpseclib/Math/BigInteger/Engines/PHP.php @@ -550,7 +550,7 @@ abstract class PHP extends Engine $lhs = new static(); $rhs = new static(); } - if (static::class != get_class($temp)) { + if (static::class != $temp::class) { $temp = new static(); $lhs = new static(); $rhs = new static(); diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index b96aa7e9..ae03a30d 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -1027,8 +1027,8 @@ class SFTP extends SSH2 } break; case 'mode': - $a[$sort] &= 07777; - $b[$sort] &= 07777; + $a[$sort] &= 0o7777; + $b[$sort] &= 0o7777; // fall-through default: if ($a[$sort] === $b[$sort]) { @@ -1450,7 +1450,7 @@ class SFTP extends SSH2 $filename = $temp; } - $attr = pack('N2', Attribute::PERMISSIONS, $mode & 07777); + $attr = pack('N2', Attribute::PERMISSIONS, $mode & 0o7777); if (!$this->setstat($filename, $attr, $recursive)) { return false; } @@ -2825,26 +2825,26 @@ class SFTP extends SSH2 { // values come from http://lxr.free-electrons.com/source/include/uapi/linux/stat.h#L12 // see, also, http://linux.die.net/man/2/stat - switch ($mode & 0170000) {// ie. 1111 0000 0000 0000 - case 0000000: // no file type specified - figure out the file type using alternative means + switch ($mode & 0o170000) {// ie. 1111 0000 0000 0000 + case 0: // no file type specified - figure out the file type using alternative means return false; - case 0040000: + case 0o040000: return FileType::DIRECTORY; - case 0100000: + case 0o100000: return FileType::REGULAR; - case 0120000: + case 0o120000: return FileType::SYMLINK; // new types introduced in SFTPv5+ // http://tools.ietf.org/html/draft-ietf-secsh-filexfer-05#section-5.2 - case 0010000: // named pipe (fifo) + case 0o010000: // named pipe (fifo) return FileType::FIFO; - case 0020000: // character special + case 0o020000: // character special return FileType::CHAR_DEVICE; - case 0060000: // block special + case 0o060000: // block special return FileType::BLOCK_DEVICE; - case 0140000: // socket + case 0o140000: // socket return FileType::SOCKET; - case 0160000: // whiteout + case 0o160000: // whiteout // "SPECIAL should be used for files that are of // a known type which cannot be expressed in the protocol" return FileType::SPECIAL; diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 09456c01..09dab2e8 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -1500,8 +1500,8 @@ class SSH2 $exchange_hash_rfc4419 = ''; - if (strpos($this->kex_algorithm, 'curve25519-sha256') === 0 || strpos($this->kex_algorithm, 'ecdh-sha2-nistp') === 0) { - $curve = strpos($this->kex_algorithm, 'curve25519-sha256') === 0 ? + if (str_starts_with($this->kex_algorithm, 'curve25519-sha256') || str_starts_with($this->kex_algorithm, 'ecdh-sha2-nistp')) { + $curve = str_starts_with($this->kex_algorithm, 'curve25519-sha256') ? 'Curve25519' : substr($this->kex_algorithm, 10); $ourPrivate = EC::createKey($curve); @@ -1509,7 +1509,7 @@ class SSH2 $clientKexInitMessage = MessageTypeExtra::KEX_ECDH_INIT; $serverKexReplyMessage = MessageTypeExtra::KEX_ECDH_REPLY; } else { - if (strpos($this->kex_algorithm, 'diffie-hellman-group-exchange') === 0) { + if (str_starts_with($this->kex_algorithm, 'diffie-hellman-group-exchange')) { $dh_group_sizes_packed = pack( 'NNN', $this->kex_dh_group_size_min, diff --git a/tests/Functional/Net/SFTPUserStoryTest.php b/tests/Functional/Net/SFTPUserStoryTest.php index e69fc61b..6f440a84 100644 --- a/tests/Functional/Net/SFTPUserStoryTest.php +++ b/tests/Functional/Net/SFTPUserStoryTest.php @@ -268,7 +268,7 @@ class SFTPUserStoryTest extends PhpseclibFunctionalTestCase public function testChModOnFile($sftp) { $this->assertNotFalse( - $sftp->chmod(0755, 'file1.txt'), + $sftp->chmod(0o755, 'file1.txt'), 'Failed asserting that chmod() was successful.' ); @@ -717,12 +717,12 @@ class SFTPUserStoryTest extends PhpseclibFunctionalTestCase */ public function testReadableWritable($sftp) { - $sftp->chmod(0000, 'offset.txt'); + $sftp->chmod(0, 'offset.txt'); $this->assertFalse($sftp->is_writable('offset.txt')); $this->assertFalse($sftp->is_writeable('offset.txt')); $this->assertFalse($sftp->is_readable('offset.txt')); - $sftp->chmod(0777, 'offset.txt'); + $sftp->chmod(0o777, 'offset.txt'); $this->assertTrue($sftp->is_writable('offset.txt')); $this->assertTrue($sftp->is_writeable('offset.txt')); $this->assertTrue($sftp->is_readable('offset.txt')); diff --git a/tests/PhpseclibTestCase.php b/tests/PhpseclibTestCase.php index 4c273100..0418c7d2 100644 --- a/tests/PhpseclibTestCase.php +++ b/tests/PhpseclibTestCase.php @@ -82,7 +82,7 @@ abstract class PhpseclibTestCase extends TestCase protected static function getVar($obj, $var) { - $reflection = new \ReflectionClass(get_class($obj)); + $reflection = new \ReflectionClass($obj::class); $prop = $reflection->getProperty($var); $prop->setAccessible(true); return $prop->getValue($obj); @@ -90,7 +90,7 @@ abstract class PhpseclibTestCase extends TestCase public static function callFunc($obj, $func, $params = []) { - $reflection = new \ReflectionClass(get_class($obj)); + $reflection = new \ReflectionClass($obj::class); $method = $reflection->getMethod($func); $method->setAccessible(true); return $method->invokeArgs($obj, $params); diff --git a/tests/Unit/Crypt/ChaCha20Test.php b/tests/Unit/Crypt/ChaCha20Test.php index 56244092..357de9f5 100644 --- a/tests/Unit/Crypt/ChaCha20Test.php +++ b/tests/Unit/Crypt/ChaCha20Test.php @@ -100,7 +100,7 @@ class ChaCha20Test extends PhpseclibTestCase $c = new ChaCha20(); $c->setPoly1305Key($key); - $r = new \ReflectionClass(get_class($c)); + $r = new \ReflectionClass($c::class); // this unit test is testing Poly1305 independent of ChaCha20, which phpseclib doesn't // really support, hence this hackish approach $m = $r->getMethod('poly1305'); @@ -128,7 +128,7 @@ class ChaCha20Test extends PhpseclibTestCase $c->setKey($key); $c->setNonce($nonce); - $r = new \ReflectionClass(get_class($c)); + $r = new \ReflectionClass($c::class); $m = $r->getMethod('createPoly1305Key'); $m->setAccessible(true); $result = $m->invoke($c);