From b18c16aedc414e5a4027e7c56204a9c70e140a33 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 17 Nov 2016 14:26:20 +0000 Subject: [PATCH] Applied fixes from StyleCI --- src/danog/MadelineProto/API.php | 1 + src/danog/MadelineProto/APIFactory.php | 1 - src/danog/MadelineProto/DataCenter.php | 13 ++++--- src/danog/MadelineProto/MTProto.php | 4 +-- .../MTProtoTools/AuthKeyHandler.php | 35 ++++++++++--------- .../MTProtoTools/CallHandler.php | 1 + .../MTProtoTools/MsgIdHandler.php | 2 +- src/danog/MadelineProto/RSA.php | 6 ++-- src/danog/MadelineProto/TL/TL.php | 4 +-- src/danog/MadelineProto/TL/TLConstructor.php | 22 +++++++----- src/danog/MadelineProto/TL/TLMethod.php | 14 ++++---- 11 files changed, 58 insertions(+), 45 deletions(-) diff --git a/src/danog/MadelineProto/API.php b/src/danog/MadelineProto/API.php index 9c962ef39..5881f7999 100644 --- a/src/danog/MadelineProto/API.php +++ b/src/danog/MadelineProto/API.php @@ -16,6 +16,7 @@ class API extends Tools { public $API; public $settings; + public function __construct($params = []) { set_error_handler(['\danog\MadelineProto\Exception', 'ExceptionErrorHandler']); diff --git a/src/danog/MadelineProto/APIFactory.php b/src/danog/MadelineProto/APIFactory.php index 4a68e270e..2aba4df96 100644 --- a/src/danog/MadelineProto/APIFactory.php +++ b/src/danog/MadelineProto/APIFactory.php @@ -27,5 +27,4 @@ class APIFactory { return $this->API->method_call($this->namespace.$name, $arguments[0]); } - } diff --git a/src/danog/MadelineProto/DataCenter.php b/src/danog/MadelineProto/DataCenter.php index f49e3cd6d..78afc13e9 100644 --- a/src/danog/MadelineProto/DataCenter.php +++ b/src/danog/MadelineProto/DataCenter.php @@ -17,7 +17,7 @@ namespace danog\MadelineProto; */ class DataCenter extends Tools { - public $referenced_variables = ["time_delta", "temp_auth_key", "auth_key", "session_id", "seq_no"]; + public $referenced_variables = ['time_delta', 'temp_auth_key', 'auth_key', 'session_id', 'seq_no']; public $sockets; public function __construct($dclist, $settings) @@ -72,23 +72,26 @@ class DataCenter extends Tools $address = 'https://'.$subdomain.'.web.telegram.org/'.$path; } $this->sockets[$dc_number] = new Connection($address, $settings['port'], $settings['protocol']); + return true; } - public function set_curdc($dc_number) { + public function set_curdc($dc_number) + { $this->curdc = $dc_number; foreach ($this->referenced_variables as $key) { - $this->{$key} = &$this->sockets[$dc_number]->{$key}; + $this->{$key} = &$this->sockets[$dc_number]->{$key}; } } - public function unset_curdc($dc_number) { + + public function unset_curdc($dc_number) + { unset($this->curdc); foreach ($this->referenced_variables as $key) { unset($this->sockets[$dc_number]->{$key}); } } - public function __call($name, $arguments) { return $this->sockets[$this->curdc]->{$name}(...$arguments); diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index ef56342f8..fca58f99f 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -161,8 +161,9 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB $this->datacenter->temp_auth_key = $this->create_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in']); } } - public function write_client_info($allow_switch) { + public function write_client_info($allow_switch) + { \danog\MadelineProto\Logger::log('Writing client info...'); $nearest_dc = $this->method_call( 'invokeWithLayer', @@ -182,6 +183,5 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB $this->switch_dc($nearest_dc['nearest_dc']); $this->settings['connection_settings']['default_dc'] = $nearest_dc['nearest_dc']; } - } } diff --git a/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php b/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php index 8c47cfef9..8ae6cda33 100644 --- a/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php @@ -27,22 +27,22 @@ class AuthKeyHandler extends AckHandler \danog\MadelineProto\Logger::log('Requesting pq'); /** - * *********************************************************************** - * Make pq request, DH exchange initiation. - * - * @method req_pq - * - * @param [ - * int128 $nonce : The value of nonce is selected randomly by the client (random number) and identifies the client within this communication - * ] - * - * @return ResPQ [ - * int128 $nonce : The value of nonce is selected randomly by the server - * int128 $server_nonce : The value of server_nonce is selected randomly by the server - * string $pq : This is a representation of a natural number (in binary big endian format). This number is the product of two different odd prime numbers - * Vector long $server_public_key_fingerprints : This is a list of public RSA key fingerprints - * ] - */ + * *********************************************************************** + * Make pq request, DH exchange initiation. + * + * @method req_pq + * + * @param [ + * int128 $nonce : The value of nonce is selected randomly by the client (random number) and identifies the client within this communication + * ] + * + * @return ResPQ [ + * int128 $nonce : The value of nonce is selected randomly by the server + * int128 $server_nonce : The value of server_nonce is selected randomly by the server + * string $pq : This is a representation of a natural number (in binary big endian format). This number is the product of two different odd prime numbers + * Vector long $server_public_key_fingerprints : This is a list of public RSA key fingerprints + * ] + */ $nonce = \phpseclib\Crypt\Random::string(16); $ResPQ = $this->method_call('req_pq', [ @@ -495,7 +495,7 @@ class AuthKeyHandler extends AckHandler ); $int_message_id = $this->generate_message_id(); $this->check_message_id($int_message_id, true); - + $message_id = \danog\PHP\Struct::pack('method_call('auth.bindTempAuthKey', ['perm_auth_key_id' => $perm_auth_key_id, 'nonce' => $nonce, 'expires_at' => $expires_at, 'encrypted_message' => $encrypted_message], $int_message_id)) { \danog\MadelineProto\Logger::log('Successfully binded temporary and permanent authorization keys.'); + return true; } throw new Exception('An error occurred while binding temporary and permanent authorization keys.'); diff --git a/src/danog/MadelineProto/MTProtoTools/CallHandler.php b/src/danog/MadelineProto/MTProtoTools/CallHandler.php index fc0cd288b..385f88f92 100644 --- a/src/danog/MadelineProto/MTProtoTools/CallHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/CallHandler.php @@ -42,6 +42,7 @@ class CallHandler extends AuthKeyHandler $dc = preg_replace('/[^0-9]+/', '', $response['error_message']); \danog\MadelineProto\Logger::log('Received request to switch to DC '.$dc); $this->switch_dc($dc); + return $this->method_call($this->outgoing_messages[$last_sent]['content']['method'], $this->outgoing_messages[$last_sent]['content']['args']); break; diff --git a/src/danog/MadelineProto/MTProtoTools/MsgIdHandler.php b/src/danog/MadelineProto/MTProtoTools/MsgIdHandler.php index 8bdd01b4e..cc1e0f142 100644 --- a/src/danog/MadelineProto/MTProtoTools/MsgIdHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/MsgIdHandler.php @@ -74,7 +74,7 @@ class MsgIdHandler extends MessageHandler rand(0, 524288) << 2 ); */ - + $keys = array_keys($this->outgoing_messages); asort($keys); $keys = end($keys); diff --git a/src/danog/MadelineProto/RSA.php b/src/danog/MadelineProto/RSA.php index 4bfd5de87..14417cb2c 100644 --- a/src/danog/MadelineProto/RSA.php +++ b/src/danog/MadelineProto/RSA.php @@ -35,15 +35,15 @@ class RSA extends TL\TL sha1( $this->serialize_param( 'bytes', - null, + null, $this->n->toBytes() ) . $this->serialize_param( 'bytes', - null, + null, $this->e->toBytes() - ), + ), true ), -8 diff --git a/src/danog/MadelineProto/TL/TL.php b/src/danog/MadelineProto/TL/TL.php index 808dcc081..e58bd3baa 100644 --- a/src/danog/MadelineProto/TL/TL.php +++ b/src/danog/MadelineProto/TL/TL.php @@ -123,7 +123,7 @@ class TL extends \danog\MadelineProto\Tools break; case 'int128': case 'int256': - return (string)$value; + return (string) $value; break; case 'double': return \danog\PHP\Struct::pack('key++; } - public function find_by_type($type) { + + public function find_by_type($type) + { $key = array_search($type, $this->type); + return ($key == false) ? false : [ - 'id' => $this->id[$key], + 'id' => $this->id[$key], 'predicate' => $this->predicate[$key], - 'type' => $this->type[$key], - 'params' => $this->params[$key], + 'type' => $this->type[$key], + 'params' => $this->params[$key], ]; } - public function find_by_id($id) { + + public function find_by_id($id) + { $key = array_search($id, $this->id); + return ($key == false) ? false : [ - 'id' => $this->id[$key], + 'id' => $this->id[$key], 'predicate' => $this->predicate[$key], - 'type' => $this->type[$key], - 'params' => $this->params[$key], + 'type' => $this->type[$key], + 'params' => $this->params[$key], ]; } } diff --git a/src/danog/MadelineProto/TL/TLMethod.php b/src/danog/MadelineProto/TL/TLMethod.php index 1f9edc907..4897afe76 100644 --- a/src/danog/MadelineProto/TL/TLMethod.php +++ b/src/danog/MadelineProto/TL/TLMethod.php @@ -53,15 +53,17 @@ class TLMethod } $this->key++; } - public function find_by_method($method) { + + public function find_by_method($method) + { $key = array_search($method, $this->method); + return ($key == false) ? false : [ - 'id' => $this->id[$key], - 'method' => $this->method[$key], - 'type' => $this->type[$key], - 'params' => $this->params[$key], + 'id' => $this->id[$key], + 'method' => $this->method[$key], + 'type' => $this->type[$key], + 'params' => $this->params[$key], 'method_namespaced' => $this->method_namespaced[$key], ]; } - }