From 3a0a7179d40ceee8e2093fc184f1f9d586a54e61 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 8 Aug 2016 12:10:28 -0400 Subject: [PATCH] Applied fixes from StyleCI --- src/danog/MadelineProto/API.php | 1 + src/danog/MadelineProto/Connection.php | 2 ++ src/danog/MadelineProto/Crypt.php | 2 ++ src/danog/MadelineProto/DebugFunctions.php | 20 ++++++++------ src/danog/MadelineProto/Exception.php | 5 +++- src/danog/MadelineProto/Logging.php | 29 +++++++++++++------- src/danog/MadelineProto/PrimeModule.php | 2 ++ src/danog/MadelineProto/RSA.php | 5 +++- src/danog/MadelineProto/Session.php | 16 ++++++----- src/danog/MadelineProto/TL/TL.php | 8 ++++-- src/danog/MadelineProto/TL/TLConstructor.php | 2 ++ src/danog/MadelineProto/TL/TLMethod.php | 2 ++ src/danog/MadelineProto/TL/TLObject.php | 4 ++- src/danog/MadelineProto/Tools.php | 2 ++ 14 files changed, 68 insertions(+), 32 deletions(-) diff --git a/src/danog/MadelineProto/API.php b/src/danog/MadelineProto/API.php index b7ca3672..afe008bb 100644 --- a/src/danog/MadelineProto/API.php +++ b/src/danog/MadelineProto/API.php @@ -11,6 +11,7 @@ If not, see . */ namespace danog\MadelineProto; + class API extends Exception { public $session; diff --git a/src/danog/MadelineProto/Connection.php b/src/danog/MadelineProto/Connection.php index 5f983e3d..30c74d2c 100644 --- a/src/danog/MadelineProto/Connection.php +++ b/src/danog/MadelineProto/Connection.php @@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details. You should have received a copy of the GNU General Public License along with the MadelineProto. If not, see . */ + namespace danog\MadelineProto; + /** * Manages connection to telegram servers. */ diff --git a/src/danog/MadelineProto/Crypt.php b/src/danog/MadelineProto/Crypt.php index 978d7bd5..159d5279 100644 --- a/src/danog/MadelineProto/Crypt.php +++ b/src/danog/MadelineProto/Crypt.php @@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details. You should have received a copy of the GNU General Public License along with the MadelineProto. If not, see . */ + namespace danog\MadelineProto; + class Crypt { public function ige_encrypt($message, $key, $iv) diff --git a/src/danog/MadelineProto/DebugFunctions.php b/src/danog/MadelineProto/DebugFunctions.php index ef5e58a1..cf600c05 100644 --- a/src/danog/MadelineProto/DebugFunctions.php +++ b/src/danog/MadelineProto/DebugFunctions.php @@ -9,14 +9,16 @@ See the GNU Affero General Public License for more details. You should have received a copy of the GNU General Public License along with the MadelineProto. If not, see . */ + namespace danog\MadelineProto; -class DebugFunctions { +class DebugFunctions +{ /** - * Function to dump the hex version of a string. - * - * @param $what What to dump. - */ + * Function to dump the hex version of a string. + * + * @param $what What to dump. + */ public static function hex_dump(...$what) { foreach ($what as $w) { @@ -25,9 +27,9 @@ class DebugFunctions { } /** - * Function to visualize byte streams. Split into bytes, print to console. - * :param bs: BYTE STRING. - */ + * Function to visualize byte streams. Split into bytes, print to console. + * :param bs: BYTE STRING. + */ public static function vis($bs) { $bs = str_split($bs); @@ -49,4 +51,4 @@ class DebugFunctions { ).PHP_EOL; } } -} \ No newline at end of file +} diff --git a/src/danog/MadelineProto/Exception.php b/src/danog/MadelineProto/Exception.php index 118f4d62..877428f9 100644 --- a/src/danog/MadelineProto/Exception.php +++ b/src/danog/MadelineProto/Exception.php @@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details. You should have received a copy of the GNU General Public License along with the MadelineProto. If not, see . */ + namespace danog\MadelineProto; + class Exception extends \Exception { public function __construct($message, $code = 0, Exception $previous = null) @@ -21,6 +23,7 @@ class Exception extends \Exception // make sure everything is assigned properly parent::__construct($message, $code, $previous); } + /** * ExceptionErrorHandler. * @@ -32,6 +35,6 @@ class Exception extends \Exception if (error_reporting() === 0) { return true; // return true to continue through the others error handlers } - throw new Exception($errstr.' on line '.$errline.' of file '.$errfile, $errno); + throw new self($errstr.' on line '.$errline.' of file '.$errfile, $errno); } } diff --git a/src/danog/MadelineProto/Logging.php b/src/danog/MadelineProto/Logging.php index edd7f9c3..5f44385a 100644 --- a/src/danog/MadelineProto/Logging.php +++ b/src/danog/MadelineProto/Logging.php @@ -12,23 +12,30 @@ If not, see . /* * Logging class */ + namespace danog\MadelineProto; -class Logging { + +class Logging +{ public $mode = null; public $optional = null; + /* - * Constructor function + * Constructor function * Accepts various logging modes: * 0 - No logging * 1 - Log to the default logging destination * 2 - Log to file defined in second parameter * 3 - Echo logs */ - public function __construct($mode, $optional = null){ - $this->mode = (string)$mode; + public function __construct($mode, $optional = null) + { + $this->mode = (string) $mode; $this->optional = $optional; } - public function __invoke(...$params){ + + public function __invoke(...$params) + { foreach ($params as $param) { switch ($this->mode) { case '1': @@ -38,15 +45,17 @@ class Logging { error_log($param, 3, $this->optional); break; case '3': - echo $param . PHP_EOL; + echo $param.PHP_EOL; break; default: break; } } } - public function log(...$params) { - if($this->mode == null) { + + public function log(...$params) + { + if ($this->mode == null) { $mode = array_pop($params); } else { $mode = $this->mode; @@ -60,11 +69,11 @@ class Logging { error_log($param, 3, $this->optional); break; case '3': - echo $param . PHP_EOL; + echo $param.PHP_EOL; break; default: break; } } } -} \ No newline at end of file +} diff --git a/src/danog/MadelineProto/PrimeModule.php b/src/danog/MadelineProto/PrimeModule.php index da4ee64e..b7c43ef4 100644 --- a/src/danog/MadelineProto/PrimeModule.php +++ b/src/danog/MadelineProto/PrimeModule.php @@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details. You should have received a copy of the GNU General Public License along with the MadelineProto. If not, see . */ + namespace danog\MadelineProto; + class PrimeModule { public function __construct() diff --git a/src/danog/MadelineProto/RSA.php b/src/danog/MadelineProto/RSA.php index f6f6c090..c63d0e84 100644 --- a/src/danog/MadelineProto/RSA.php +++ b/src/danog/MadelineProto/RSA.php @@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details. You should have received a copy of the GNU General Public License along with the MadelineProto. If not, see . */ + namespace danog\MadelineProto; + class RSA extends TL\TL { public $key; // phpseclib\Crypt\RSA class @@ -25,13 +27,14 @@ class RSA extends TL\TL $this->n = $this->key->modulus; $this->e = $this->key->exponent; - $this->fp = new \phpseclib\Math\BigInteger(strrev(substr(sha1($this->serialize_param('bytes', $this->n->toBytes()) . $this->serialize_param('bytes', $this->e->toBytes()), true), -8)), -256); + $this->fp = new \phpseclib\Math\BigInteger(strrev(substr(sha1($this->serialize_param('bytes', $this->n->toBytes()).$this->serialize_param('bytes', $this->e->toBytes()), true), -8)), -256); $this->fp_float = (float) $this->fp->toString(); } public function encrypt($data) { $bigintdata = new \phpseclib\Math\BigInteger($data, 256); + return $bigintdata->powMod($this->e, $this->n)->toBytes(); } } diff --git a/src/danog/MadelineProto/Session.php b/src/danog/MadelineProto/Session.php index f5d8e711..aa304555 100755 --- a/src/danog/MadelineProto/Session.php +++ b/src/danog/MadelineProto/Session.php @@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details. You should have received a copy of the GNU General Public License along with the MadelineProto. If not, see . */ + namespace danog\MadelineProto; + /** * Manages encryption and message frames. */ @@ -19,7 +21,7 @@ class Session extends Tools public function __construct($settings) { - + // Set default settings $default_settings = [ 'auth_key' => null, @@ -40,7 +42,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB -----END RSA PUBLIC KEY-----', 'logging' => 1, 'logging_param' => '/tmp/MadelineProto.log', - 'logging' => 3 + 'logging' => 3, ]; foreach ($default_settings as $key => $param) { if (!isset($settings[$key])) { @@ -64,10 +66,10 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB } catch (Exception $e) { $this->tl = new TL\TL(__DIR__.'/TL_schema.JSON'); } - // Istantiate logging class - $this->log = new Logging($this->settings["logging"], $this->settings["logging_param"]); + // Istantiate logging class + $this->log = new Logging($this->settings['logging'], $this->settings['logging_param']); // Set some defaults - $this->auth_key = $this->settings["auth_key"]; + $this->auth_key = $this->settings['auth_key']; $this->number = 0; $this->timedelta = 0; $this->session_id = \phpseclib\Crypt\Random::string(8); @@ -193,12 +195,12 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB } $pq_bytes = $ResPQ['pq']; foreach ($ResPQ['server_public_key_fingerprints'] as $curfp) { - if($curfp === $this->key->fp_float) { + if ($curfp === $this->key->fp_float) { $public_key_fingerprint = $curfp; break; } } - if(!isset($public_key_fingerprint)) { + if (!isset($public_key_fingerprint)) { throw new Exception("Handshake: couldn't find our key in the server_public_key_fingerprints vector."); } diff --git a/src/danog/MadelineProto/TL/TL.php b/src/danog/MadelineProto/TL/TL.php index 9d1a1134..b58a486f 100644 --- a/src/danog/MadelineProto/TL/TL.php +++ b/src/danog/MadelineProto/TL/TL.php @@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details. You should have received a copy of the GNU General Public License along with the MadelineProto. If not, see . */ + namespace danog\MadelineProto\TL; + class TL { public function __construct($filename) @@ -39,7 +41,7 @@ class TL if (isset($this->constructor_type[$type_])) { $tl_constructor = $this->constructor_type[$type_]; } else { - throw new Exception('Could not extract type: ' . $type_); + throw new Exception('Could not extract type: '.$type_); } $bytes_io .= \danog\PHP\Struct::pack('id); foreach ($tl_constructor->params as $arg) { @@ -55,7 +57,7 @@ class TL if (isset($this->method_name[$type_])) { $tl_method = $this->method_name[$type_]; } else { - throw new Exception('Could not extract type: ' . $type_); + throw new Exception('Could not extract type: '.$type_); } $bytes_io .= \danog\PHP\Struct::pack('id); foreach ($tl_method->params as $arg) { @@ -179,7 +181,7 @@ class TL if (isset($this->constructor_id[$i])) { $tl_elem = $this->constructor_id[$i]; } else { - throw new Exception('Could not extract type: ' . $type_); + throw new Exception('Could not extract type: '.$type_); } } diff --git a/src/danog/MadelineProto/TL/TLConstructor.php b/src/danog/MadelineProto/TL/TLConstructor.php index 9c5cc043..cae0cd4d 100644 --- a/src/danog/MadelineProto/TL/TLConstructor.php +++ b/src/danog/MadelineProto/TL/TLConstructor.php @@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details. You should have received a copy of the GNU General Public License along with the MadelineProto. If not, see . */ + namespace danog\MadelineProto\TL; + class TLConstructor { public function __construct($json_dict) diff --git a/src/danog/MadelineProto/TL/TLMethod.php b/src/danog/MadelineProto/TL/TLMethod.php index d0e92d23..19211c73 100644 --- a/src/danog/MadelineProto/TL/TLMethod.php +++ b/src/danog/MadelineProto/TL/TLMethod.php @@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details. You should have received a copy of the GNU General Public License along with the MadelineProto. If not, see . */ + namespace danog\MadelineProto\TL; + class TLMethod { public function __construct($json_dict) diff --git a/src/danog/MadelineProto/TL/TLObject.php b/src/danog/MadelineProto/TL/TLObject.php index 78b07d87..5b1b6f45 100644 --- a/src/danog/MadelineProto/TL/TLObject.php +++ b/src/danog/MadelineProto/TL/TLObject.php @@ -9,7 +9,9 @@ See the GNU Affero General Public License for more details. You should have received a copy of the GNU General Public License along with the MadelineProto. If not, see . */ + namespace danog\MadelineProto\TL; + class TLObject extends \ArrayObject { public function __construct($tl_elem) @@ -17,4 +19,4 @@ class TLObject extends \ArrayObject parent::__construct(); $this->name = $tl_elem->predicate; } -} \ No newline at end of file +} diff --git a/src/danog/MadelineProto/Tools.php b/src/danog/MadelineProto/Tools.php index cb8dc401..df6e2f55 100644 --- a/src/danog/MadelineProto/Tools.php +++ b/src/danog/MadelineProto/Tools.php @@ -11,6 +11,7 @@ If not, see . */ namespace danog\MadelineProto; + /** * Some tools. */ @@ -60,6 +61,7 @@ class Tools return $res; } + // taken from mochikit: range( [start,] stop[, step] ) public static function range($start, $stop = null, $step = 1) {