From 624f328c88560e2ee6aa5f1ef8264cd318579c24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20K=C3=A4fer?= Date: Tue, 14 Dec 2021 13:18:33 +0100 Subject: [PATCH] Remove define() from SSH2 and use class constants instead --- phpseclib/Net/SSH2.php | 60 ++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 6d0c4762..6863ebb2 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -61,23 +61,6 @@ use phpseclib\Crypt\Twofish; use phpseclib\Math\BigInteger; // Used to do Diffie-Hellman key exchange and DSA/RSA signature verification. use phpseclib\System\SSH\Agent; -/**#@+ - * @access private - */ -/** - * No compression - */ -define('NET_SSH2_COMPRESSION_NONE', 1); -/** - * zlib compression - */ -define('NET_SSH2_COMPRESSION_ZLIB', 2); -/** - * zlib@openssh.com - */ -define('NET_SSH2_COMPRESSION_ZLIB_AT_OPENSSH', 3); -/**#@-*/ - /** * Pure-PHP implementation of SSHv2. * @@ -87,6 +70,25 @@ define('NET_SSH2_COMPRESSION_ZLIB_AT_OPENSSH', 3); */ class SSH2 { + /**#@+ + * Compression Types + * + * @access private + */ + /** + * No compression + */ + const NET_SSH2_COMPRESSION_NONE = 1; + /** + * zlib compression + */ + const NET_SSH2_COMPRESSION_ZLIB = 2; + /** + * zlib@openssh.com + */ + const NET_SSH2_COMPRESSION_ZLIB_AT_OPENSSH = 3; + /**#@-*/ + /**#@+ * Execution Bitmap Masks * @@ -1002,7 +1004,7 @@ class SSH2 * @var int * @access private */ - var $compress = NET_SSH2_COMPRESSION_NONE; + var $compress = self::NET_SSH2_COMPRESSION_NONE; /** * Decompression method @@ -1010,7 +1012,7 @@ class SSH2 * @var resource|object * @access private */ - var $decompress = NET_SSH2_COMPRESSION_NONE; + var $decompress = self::NET_SSH2_COMPRESSION_NONE; /** * Compression context @@ -1644,9 +1646,9 @@ class SSH2 } $compression_map = array( - 'none' => NET_SSH2_COMPRESSION_NONE, - 'zlib' => NET_SSH2_COMPRESSION_ZLIB, - 'zlib@openssh.com' => NET_SSH2_COMPRESSION_ZLIB_AT_OPENSSH + 'none' => self::NET_SSH2_COMPRESSION_NONE, + 'zlib' => self::NET_SSH2_COMPRESSION_ZLIB, + 'zlib@openssh.com' => self::NET_SSH2_COMPRESSION_ZLIB_AT_OPENSSH ); $compression_algorithm_out = $this->_array_intersect_first($c2s_compression_algorithms, $this->compression_algorithms_client_to_server); @@ -3589,11 +3591,11 @@ class SSH2 } switch ($this->decompress) { - case NET_SSH2_COMPRESSION_ZLIB_AT_OPENSSH: + case self::NET_SSH2_COMPRESSION_ZLIB_AT_OPENSSH: if (!$this->isAuthenticated()) { break; } - case NET_SSH2_COMPRESSION_ZLIB: + case self::NET_SSH2_COMPRESSION_ZLIB: if ($this->regenerate_decompression_context) { $this->regenerate_decompression_context = false; @@ -4181,11 +4183,11 @@ class SSH2 } switch ($this->compress) { - case NET_SSH2_COMPRESSION_ZLIB_AT_OPENSSH: + case self::NET_SSH2_COMPRESSION_ZLIB_AT_OPENSSH: if (!$this->isAuthenticated()) { break; } - case NET_SSH2_COMPRESSION_ZLIB: + case self::NET_SSH2_COMPRESSION_ZLIB: if (!$this->regenerate_compression_context) { $header = ''; } else { @@ -4943,9 +4945,9 @@ class SSH2 $this->_connect(); $compression_map = array( - NET_SSH2_COMPRESSION_NONE => 'none', - NET_SSH2_COMPRESSION_ZLIB => 'zlib', - NET_SSH2_COMPRESSION_ZLIB_AT_OPENSSH => 'zlib@openssh.com' + self::NET_SSH2_COMPRESSION_NONE => 'none', + self::NET_SSH2_COMPRESSION_ZLIB => 'zlib', + self::NET_SSH2_COMPRESSION_ZLIB_AT_OPENSSH => 'zlib@openssh.com' ); return array(