From 845135f887c6657ecf00aab0134b8e252a2ac62a Mon Sep 17 00:00:00 2001 From: terrafrost Date: Fri, 9 Sep 2016 21:52:56 -0800 Subject: [PATCH] add PHP5-style constructors along side PHP4-style ones --- .travis.yml | 3 ++- phpseclib/Crypt/Base.php | 14 +++++++++++++- phpseclib/Crypt/Hash.php | 14 +++++++++++++- phpseclib/Crypt/RC4.php | 13 ++++++++++++- phpseclib/Crypt/RSA.php | 13 ++++++++++++- phpseclib/Crypt/Rijndael.php | 28 ---------------------------- phpseclib/Crypt/TripleDES.php | 16 ++++++++++++++-- phpseclib/File/ANSI.php | 13 ++++++++++++- phpseclib/File/ASN1.php | 27 +++++++++++++++++++++++++-- phpseclib/File/X509.php | 13 ++++++++++++- phpseclib/Math/BigInteger.php | 15 ++++++++++++++- phpseclib/Net/SCP.php | 18 ++++++++++++++---- phpseclib/Net/SFTP.php | 18 ++++++++++++++++-- phpseclib/Net/SFTP/Stream.php | 2 +- phpseclib/Net/SSH1.php | 17 ++++++++++++++++- phpseclib/Net/SSH2.php | 16 +++++++++++++++- phpseclib/System/SSH/Agent.php | 27 +++++++++++++++++++++++++-- travis/run-phpunit.sh | 2 +- 18 files changed, 217 insertions(+), 52 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7b837a2b..d54c933a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ php: - 5.5.9 - 5.5 - 5.6 + - 7.0 - hhvm env: @@ -26,7 +27,7 @@ install: - cd .. - eval `ssh-agent -s` - travis/setup-secure-shell.sh - - sh -c "if [ '$TRAVIS_PHP_VERSION' != 'hhvm' ]; then travis/install-php-extensions.sh; fi" + - sh -c "if [ '$TRAVIS_PHP_VERSION' != 'hhvm' -a '$TRAVIS_PHP_VERSION' != '7.0' ]; then travis/install-php-extensions.sh; fi" - travis/setup-composer.sh script: diff --git a/phpseclib/Crypt/Base.php b/phpseclib/Crypt/Base.php index 58a5fc47..4c8f721c 100644 --- a/phpseclib/Crypt/Base.php +++ b/phpseclib/Crypt/Base.php @@ -503,7 +503,7 @@ class Crypt_Base * @param int $mode * @access public */ - function Crypt_Base($mode = CRYPT_MODE_CBC) + function __construct($mode = CRYPT_MODE_CBC) { // $mode dependent settings switch ($mode) { @@ -531,6 +531,18 @@ class Crypt_Base } } + /** + * PHP4 compatible Default Constructor. + * + * @see self::__construct() + * @param int $mode + * @access public + */ + function Crypt_Base($mode = CRYPT_MODE_CBC) + { + $this->__construct($mode); + } + /** * Sets the initialization vector. (optional) * diff --git a/phpseclib/Crypt/Hash.php b/phpseclib/Crypt/Hash.php index 5dda8eae..621a5b9e 100644 --- a/phpseclib/Crypt/Hash.php +++ b/phpseclib/Crypt/Hash.php @@ -151,7 +151,7 @@ class Crypt_Hash * @return Crypt_Hash * @access public */ - function Crypt_Hash($hash = 'sha1') + function __construct($hash = 'sha1') { if (!defined('CRYPT_HASH_MODE')) { switch (true) { @@ -169,6 +169,18 @@ class Crypt_Hash $this->setHash($hash); } + /** + * PHP4 compatible Default Constructor. + * + * @see self::__construct() + * @param int $mode + * @access public + */ + function Crypt_Hash($hash = 'sha1') + { + $this->__construct($mode); + } + /** * Sets the key for HMACs * diff --git a/phpseclib/Crypt/RC4.php b/phpseclib/Crypt/RC4.php index eccf682c..ce29e6af 100644 --- a/phpseclib/Crypt/RC4.php +++ b/phpseclib/Crypt/RC4.php @@ -161,9 +161,20 @@ class Crypt_RC4 extends Crypt_Base * @return Crypt_RC4 * @access public */ + function __construct() + { + parent::__construct(CRYPT_MODE_STREAM); + } + + /** + * PHP4 compatible Default Constructor. + * + * @see self::__construct() + * @access public + */ function Crypt_RC4() { - parent::Crypt_Base(CRYPT_MODE_STREAM); + $this->__construct(); } /** diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php index 23ba0d07..3eacfe16 100644 --- a/phpseclib/Crypt/RSA.php +++ b/phpseclib/Crypt/RSA.php @@ -491,7 +491,7 @@ class Crypt_RSA * @return Crypt_RSA * @access public */ - function Crypt_RSA() + function __construct() { if (!class_exists('Math_BigInteger')) { include_once 'Math/BigInteger.php'; @@ -562,6 +562,17 @@ class Crypt_RSA $this->mgfHLen = $this->mgfHash->getLength(); } + /** + * PHP4 compatible Default Constructor. + * + * @see self::__construct() + * @access public + */ + function Crypt_RSA() + { + $this->__construct(); + } + /** * Create public / private key pair * diff --git a/phpseclib/Crypt/Rijndael.php b/phpseclib/Crypt/Rijndael.php index b84166b5..56bc4e9a 100644 --- a/phpseclib/Crypt/Rijndael.php +++ b/phpseclib/Crypt/Rijndael.php @@ -241,34 +241,6 @@ class Crypt_Rijndael extends Crypt_Base */ var $kl; - /** - * Default Constructor. - * - * Determines whether or not the mcrypt extension should be used. - * - * $mode could be: - * - * - CRYPT_RIJNDAEL_MODE_ECB - * - * - CRYPT_RIJNDAEL_MODE_CBC - * - * - CRYPT_RIJNDAEL_MODE_CTR - * - * - CRYPT_RIJNDAEL_MODE_CFB - * - * - CRYPT_RIJNDAEL_MODE_OFB - * - * If not explictly set, CRYPT_RIJNDAEL_MODE_CBC will be used. - * - * @see Crypt_Base::Crypt_Base() - * @param int $mode - * @access public - */ - function Crypt_Rijndael($mode = CRYPT_RIJNDAEL_MODE_CBC) - { - parent::Crypt_Base($mode); - } - /** * Sets the key. * diff --git a/phpseclib/Crypt/TripleDES.php b/phpseclib/Crypt/TripleDES.php index a878918b..4c0b6770 100644 --- a/phpseclib/Crypt/TripleDES.php +++ b/phpseclib/Crypt/TripleDES.php @@ -196,7 +196,7 @@ class Crypt_TripleDES extends Crypt_DES * @param int $mode * @access public */ - function Crypt_TripleDES($mode = CRYPT_MODE_CBC) + function __construct($mode = CRYPT_MODE_CBC) { switch ($mode) { // In case of CRYPT_DES_MODE_3CBC, we init as CRYPT_DES_MODE_CBC @@ -219,10 +219,22 @@ class Crypt_TripleDES extends Crypt_DES break; // If not 3CBC, we init as usual default: - parent::Crypt_Base($mode); + parent::__construct($mode); } } + /** + * PHP4 compatible Default Constructor. + * + * @see self::__construct() + * @param int $mode + * @access public + */ + function Crypt_TripleDES($mode = CRYPT_MODE_CBC) + { + $this->__construct($mode); + } + /** * Test for engine validity * diff --git a/phpseclib/File/ANSI.php b/phpseclib/File/ANSI.php index 95acf374..989537be 100644 --- a/phpseclib/File/ANSI.php +++ b/phpseclib/File/ANSI.php @@ -179,7 +179,7 @@ class File_ANSI * @return File_ANSI * @access public */ - function File_ANSI() + function __construct() { $attr_cell = new stdClass(); $attr_cell->bold = false; @@ -195,6 +195,17 @@ class File_ANSI $this->setDimensions(80, 24); } + /** + * PHP4 compatible Default Constructor. + * + * @see self::__construct() + * @access public + */ + function File_ANSI() + { + $this->__construct($mode); + } + /** * Set terminal width and height * diff --git a/phpseclib/File/ASN1.php b/phpseclib/File/ASN1.php index b7f7c119..2fd2339e 100644 --- a/phpseclib/File/ASN1.php +++ b/phpseclib/File/ASN1.php @@ -131,10 +131,22 @@ class File_ASN1_Element * @return File_ASN1_Element * @access public */ - function File_ASN1_Element($encoded) + function __construct($encoded) { $this->element = $encoded; } + + /** + * PHP4 compatible Default Constructor. + * + * @see self::__construct() + * @param int $mode + * @access public + */ + function File_ASN1_Element($encoded) + { + $this->__construct($encoded); + } } /** @@ -245,7 +257,7 @@ class File_ASN1 * * @access public */ - function File_ASN1() + function __construct() { static $static_init = null; if (!$static_init) { @@ -256,6 +268,17 @@ class File_ASN1 } } + /** + * PHP4 compatible Default Constructor. + * + * @see self::__construct() + * @access public + */ + function File_ASN1() + { + $this->__construct($mode); + } + /** * Parse BER-encoding * diff --git a/phpseclib/File/X509.php b/phpseclib/File/X509.php index f1bb94fb..040551f0 100644 --- a/phpseclib/File/X509.php +++ b/phpseclib/File/X509.php @@ -326,7 +326,7 @@ class File_X509 * @return File_X509 * @access public */ - function File_X509() + function __construct() { if (!class_exists('Math_BigInteger')) { include_once 'Math/BigInteger.php'; @@ -1448,6 +1448,17 @@ class File_X509 ); } + /** + * PHP4 compatible Default Constructor. + * + * @see self::__construct() + * @access public + */ + function File_X509() + { + $this->__construct(); + } + /** * Load X.509 certificate * diff --git a/phpseclib/Math/BigInteger.php b/phpseclib/Math/BigInteger.php index 9b2d8bf7..192ce82f 100644 --- a/phpseclib/Math/BigInteger.php +++ b/phpseclib/Math/BigInteger.php @@ -243,7 +243,7 @@ class Math_BigInteger * @return Math_BigInteger * @access public */ - function Math_BigInteger($x = 0, $base = 10) + function __construct($x = 0, $base = 10) { if (!defined('MATH_BIGINTEGER_MODE')) { switch (true) { @@ -500,6 +500,19 @@ class Math_BigInteger } } + /** + * PHP4 compatible Default Constructor. + * + * @see self::__construct() + * @param $x base-10 number or base-$base number if $base set. + * @param int $base + * @access public + */ + function Math_BigInteger($x = 0, $base = 10) + { + $this->__construct($x, $base); + } + /** * Converts a BigInteger to a byte string (eg. base-256). * diff --git a/phpseclib/Net/SCP.php b/phpseclib/Net/SCP.php index 60b67f32..83ae5cc8 100644 --- a/phpseclib/Net/SCP.php +++ b/phpseclib/Net/SCP.php @@ -116,13 +116,11 @@ class Net_SCP * * Connects to an SSH server * - * @param string $host - * @param int $port - * @param int $timeout + * @param Net_SSH1|Net_SSH2 $ssh * @return Net_SCP * @access public */ - function Net_SCP($ssh) + function __construct($ssh) { if (!is_object($ssh)) { return; @@ -143,6 +141,18 @@ class Net_SCP $this->ssh = $ssh; } + /** + * PHP4 compatible Default Constructor. + * + * @see self::__construct() + * @param Net_SSH1|Net_SSH2 $ssh + * @access public + */ + function Net_SCP($ssh) + { + $this->__construct($ssh); + } + /** * Uploads a file to the SCP server. * diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 2ca06b73..b1e60cbc 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -288,9 +288,9 @@ class Net_SFTP extends Net_SSH2 * @return Net_SFTP * @access public */ - function Net_SFTP($host, $port = 22, $timeout = 10) + function __construct($host, $port = 22, $timeout = 10) { - parent::Net_SSH2($host, $port, $timeout); + parent::__construct($host, $port, $timeout); $this->max_sftp_packet = 1 << 15; @@ -417,6 +417,20 @@ class Net_SFTP extends Net_SSH2 } } + /** + * PHP4 compatible Default Constructor. + * + * @see self::__construct() + * @param string $host + * @param int $port + * @param int $timeout + * @access public + */ + function Net_SFTP($host, $port = 22, $timeout = 10) + { + $this->__construct($host, $port, $timeout); + } + /** * Login * diff --git a/phpseclib/Net/SFTP/Stream.php b/phpseclib/Net/SFTP/Stream.php index e374b9b9..a944d7f0 100644 --- a/phpseclib/Net/SFTP/Stream.php +++ b/phpseclib/Net/SFTP/Stream.php @@ -146,7 +146,7 @@ class Net_SFTP_Stream * * @access public */ - function Net_SFTP_Stream() + function __construct() { if (defined('NET_SFTP_STREAM_LOGGING')) { echo "__construct()\r\n"; diff --git a/phpseclib/Net/SSH1.php b/phpseclib/Net/SSH1.php index d50a9931..fb23daa6 100644 --- a/phpseclib/Net/SSH1.php +++ b/phpseclib/Net/SSH1.php @@ -515,7 +515,7 @@ class Net_SSH1 * @return Net_SSH1 * @access public */ - function Net_SSH1($host, $port = 22, $timeout = 10, $cipher = NET_SSH1_CIPHER_3DES) + function __construct($host, $port = 22, $timeout = 10, $cipher = NET_SSH1_CIPHER_3DES) { if (!class_exists('Math_BigInteger')) { include_once 'Math/BigInteger.php'; @@ -557,6 +557,21 @@ class Net_SSH1 $this->cipher = $cipher; } + /** + * PHP4 compatible Default Constructor. + * + * @see self::__construct() + * @param string $host + * @param int $port + * @param int $timeout + * @param int $cipher + * @access public + */ + function Net_SSH1($host, $port = 22, $timeout = 10, $cipher = NET_SSH1_CIPHER_3DES) + { + $this->__construct($host, $port, $timeout, $cipher); + } + /** * Connect to an SSHv1 server * diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 623e7f3a..8281e73a 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -883,7 +883,7 @@ class Net_SSH2 * @return Net_SSH2 * @access public */ - function Net_SSH2($host, $port = 22, $timeout = 10) + function __construct($host, $port = 22, $timeout = 10) { // Include Math_BigInteger // Used to do Diffie-Hellman key exchange and DSA/RSA signature verification. @@ -992,6 +992,20 @@ class Net_SSH2 } } + /** + * PHP4 compatible Default Constructor. + * + * @see self::__construct() + * @param mixed $host + * @param int $port + * @param int $timeout + * @access public + */ + function Net_SSH2($host, $port = 22, $timeout = 10) + { + $this->__construct($host, $port, $timeout); + } + /** * Set Crypto Engine Mode * diff --git a/phpseclib/System/SSH/Agent.php b/phpseclib/System/SSH/Agent.php index 0f4874dc..7388cb47 100644 --- a/phpseclib/System/SSH/Agent.php +++ b/phpseclib/System/SSH/Agent.php @@ -130,11 +130,23 @@ class System_SSH_Agent_Identity * @return System_SSH_Agent_Identity * @access private */ - function System_SSH_Agent_Identity($fsock) + function __construct($fsock) { $this->fsock = $fsock; } + /** + * PHP4 compatible Default Constructor. + * + * @see self::__construct() + * @param resource $fsock + * @access public + */ + function System_SSH_Agent_Identity($fsock) + { + $this->__construct($fsock); + } + /** * Set Public Key * @@ -269,7 +281,7 @@ class System_SSH_Agent * @return System_SSH_Agent * @access public */ - function System_SSH_Agent() + function __construct() { switch (true) { case isset($_SERVER['SSH_AUTH_SOCK']): @@ -289,6 +301,17 @@ class System_SSH_Agent } } + /** + * PHP4 compatible Default Constructor. + * + * @see self::__construct() + * @access public + */ + function System_SSH_Agent() + { + $this->__construct(); + } + /** * Request Identities * diff --git a/travis/run-phpunit.sh b/travis/run-phpunit.sh index 600a1d94..5ee69d66 100755 --- a/travis/run-phpunit.sh +++ b/travis/run-phpunit.sh @@ -20,7 +20,7 @@ then PHPUNIT_ARGS="$PHPUNIT_ARGS -d zend.enable_gc=0" fi -if [ "$TRAVIS_PHP_VERSION" = 'hhvm' ] +if [ "$TRAVIS_PHP_VERSION" = 'hhvm' -o "$TRAVIS_PHP_VERSION" = '7.0' ] then find tests -type f -name "*Test.php" | \ parallel --gnu --keep-order \