1- # phpseclib3_rector
1+ # rector_rules
22
33Rector rules to upgrade a phpseclib v2.0 install to phpseclib v3.0
44
@@ -11,7 +11,7 @@ You can use [phpseclib2_compat](https://github.com/phpseclib/phpseclib2_compat)
1111With [ Composer] ( https://getcomposer.org/ ) :
1212
1313```
14- composer require phpseclib/phpseclib3_rector :~1.0
14+ composer require phpseclib/rector_rules :~1.0
1515```
1616
1717## Usage
@@ -21,10 +21,10 @@ Create a rector.php file with the following contents:
2121``` php
2222<?php
2323use Rector\Config\RectorConfig;
24- use phpseclib\phpseclib3Rector \Set;
24+ use phpseclib\rectorRules \Set\V2toV3Set ;
2525
2626return RectorConfig::configure()
27- ->withSets([Set ::PATH]);
27+ ->withSets([V2toV3Set ::PATH]);
2828```
2929In the same directory where you created that file you can then run Rector by doing either of these commands:
3030
@@ -104,10 +104,10 @@ Additionally it replaces the following methods:
104104| $rsa->getSize() | $rsa->getLength() |
105105| $rsa->setHash('sha256'); | $rsa = $rsa->withHash('sha256') |
106106| $rsa->setMGFHash('sha256'); | $rsa = $rsa->withMGFHash('sha256') |
107- | $rsa->setSaltLength(10); | $rsa->withSaltLength(10) |
108- | $rsa->setSignatureMode(RSA::SIGNATURE_PKCS1); | $rsa->withPadding(RSA::SIGNATURE_PKCS1); |
109- | $rsa->setEncryptionMode(RSA::ENCRYPTION_PKCS1); | $rsa->withPadding(RSA::ENCYRPTION_PKCS1); |
110- | $rsa->setEncryptionMode(RSA::ENCRYPTION_PKCS1); $rsa->setSignatureMode(RSA::SIGNATURE_PKCS1); | $rsa->withPadding(RSA::SIGNATURE_PKCS1 | RSA::ENCYRPTION_PKCS1);|
107+ | $rsa->setSaltLength(10); | $rsa = $rsa ->withSaltLength(10) |
108+ | $rsa->setSignatureMode(RSA::SIGNATURE_PKCS1); | $rsa = $rsa ->withPadding(RSA::SIGNATURE_PKCS1); |
109+ | $rsa->setEncryptionMode(RSA::ENCRYPTION_PKCS1); | $rsa = $rsa ->withPadding(RSA::ENCYRPTION_PKCS1); |
110+ | $rsa->setEncryptionMode(RSA::ENCRYPTION_PKCS1); $rsa->setSignatureMode(RSA::SIGNATURE_PKCS1); | $rsa = $rsa ->withPadding(RSA::SIGNATURE_PKCS1 | RSA::ENCYRPTION_PKCS1);|
111111
112112### Public Key Loader Chained
113113
@@ -198,3 +198,37 @@ $sftp = new SFTP('...');
198198$sftp->login('username', 'password');
199199echo $sftp->filesize('/path/to/filename.ext');
200200```
201+
202+ ### Symmetric Key Constructor
203+
204+ This rule is for ` v2 ` -> ` v3 ` upgrade.
205+
206+ In phpseclib v2 you'd instantiate the constructor by doing stuff like this:
207+
208+ ``` php
209+ $cipher = new AES(AES::MODE_CTR);
210+ ```
211+
212+ In phpseclib v3 that's been replaced with strings. eg.
213+
214+ ``` php
215+ $cipher = new AES('ctr');
216+ ```
217+
218+ Also, in phpseclib v2, ` $cipher = new AES() ` was the same as ` $cipher = new AES(AES::MODE_CBC) ` .
219+ In v3 it doesn't default to cbc - the mode needs to be explicitly defined.
220+
221+
222+ This is true for all the classes that extend ` \phpseclib3\Crypt\Common\BlockCipher ` in v3:
223+
224+ | v2 | v3 |
225+ | ---------------------------------------------------| ---------------------------------------|
226+ | $default = new DES(); | $default = new DES('cbc'); |
227+ | $des = new DES(DES::MODE_CBC); | $des = new DES('cbc'); |
228+ | $rijndael = new Rijndael(Rijndael::MODE_ECB); | $rijndael = new Rijndael('ecb'); |
229+ | $tripleDES = new TripleDES(TripleDES::MODE_CTR); | $tripleDES = new TripleDES('ctr'); |
230+ | $blowfish = new Blowfish(Blowfish::MODE_CFB); | $blowfish = new Blowfish('cfb'); |
231+ | $twofish = new Twofish(Twofish::MODE_CFB8); | $twofish = new Twofish('cfb8'); |
232+ | $rc2 = new RC2(RC2::MODE_OFB); | $rc2 = new RC2('ofb'); |
233+ | $aes = new AES(AES::MODE_OFB8); | $aes = new AES('ofb8'); |
234+ | $aes2 = new AES(AES::MODE_GCM); | $aes2 = new AES('gcm'); |
0 commit comments