Applied fixes from StyleCI

This commit is contained in:
Daniil Gentili 2016-08-18 13:08:14 -04:00 committed by StyleCI Bot
parent 4bf443cd64
commit d96fab3c89
3 changed files with 27 additions and 22 deletions

View File

@ -128,7 +128,9 @@ class Connection
break;
}
}
public function read_message() {
public function read_message()
{
switch ($this->protocol) {
case 'tcp_full':
$packet_length_data = $this->read(4);
@ -172,9 +174,12 @@ class Connection
$payload = Tools::fopen_and_write('php://memory', 'rw+b', $packet);
break;
}
return $payload;
}
public function send_message($message) {
public function send_message($message)
{
switch ($this->protocol) {
case 'tcp_full':
$this->out_seq_no++;

View File

@ -71,6 +71,7 @@ class Crypt
}
$ciphered .= $outdata;
}
return $ciphered;
}
}

View File

@ -134,10 +134,8 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
array_shift($this->message_ids);
}
}
}
/**
* Forming the message frame and sending message to server
* :param message: byte string to send.
@ -193,31 +191,31 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
$this->check_message_id($message_id, false);
$seq_no = $this->struct->unpack('<I', fread($decrypted_data, 4)) [0];
var_dump($seq_no, $this->seq_no *2);
var_dump($seq_no, $this->seq_no * 2);
if ($seq_no != $this->seq_no * 2) {
throw new Exception('Seq_no mismatch');
}
$message_data_length = $this->struct->unpack('<I', fread($decrypted_data, 4)) [0];
if ($message_data_length > fstat($decrypted_data)["size"]) {
if ($message_data_length > fstat($decrypted_data)['size']) {
throw new Exception('message_data_length is too big');
}
if ((fstat($decrypted_data)["size"] - 32) - $message_data_length > 15) {
if ((fstat($decrypted_data)['size'] - 32) - $message_data_length > 15) {
throw new Exception('difference between message_data_length and the length of the remaining decrypted buffer is too big');
}
if ($message_data_length < 0) {
throw new Exception('message_data_length not positive');
throw new Exception('message_data_length not positive');
}
if ($message_data_length % 4 != 0) {
throw new Exception('message_data_length not divisible by 4');
throw new Exception('message_data_length not divisible by 4');
}
$message_data = fread($decrypted_data, $message_data_length);
DebugTools::hex_dump(substr(sha1(stream_get_contents($decrypted_data, 32 + $message_data_length), true), -16), $message_key);
DebugTools::hex_dump(substr(sha1(stream_get_contents($decrypted_data, 32 + $message_data_length), true), -16), $message_key);
if ($message_key != sha1($message_data, true)) {
throw new Exception('msg_key mismatch');
}
@ -244,6 +242,7 @@ DebugTools::hex_dump(substr(sha1(stream_get_contents($decrypted_data, 32 + $mess
throw new Exception('An error occurred while calling method '.$method.'.');
}
$deserialized = $this->tl->deserialize(Tools::fopen_and_write('php://memory', 'rw+b', $server_answer));
return $deserialized;
}
throw new Exception('An error occurred while calling method '.$method.'.');