Applied fixes from StyleCI

This commit is contained in:
Daniil Gentili 2016-08-17 13:20:00 -04:00 committed by StyleCI Bot
parent 8874d3ecfa
commit bf0f0de385
2 changed files with 33 additions and 24 deletions

View File

@ -38,7 +38,7 @@ Efzk2DWgkBluml8OREmvfraX3bkHZJTKX4EQSjBbbdJ2ZXIsRrYOXfaA+xayEGB+
8hdlLmAjbCVfaigxX0CDqWeR1yFL9kwd9P0NsZRPsmoqVwMbMu7mStFai6aIhc3n
Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
-----END RSA PUBLIC KEY-----',
'message_ids_limit' => 5
'message_ids_limit' => 5,
],
'connection' => [
'ip_address' => '149.154.167.50',
@ -63,8 +63,8 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
],
'max_tries' => [
'query' => 5,
'authorization' => 5
]
'authorization' => 5,
],
];
foreach ($default_settings as $key => $param) {
if (!isset($settings[$key])) {
@ -108,23 +108,25 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
unset($this->sock);
}
public function add_check_message_ids($new_message_id) {
public function add_check_message_ids($new_message_id)
{
if (((int) ((time() + $this->timedelta - 300) * pow(2, 30)) * 4) > $new_message_id) {
throw new Exception("Given message id is too old.");
throw new Exception('Given message id is too old.');
}
if (((int) ((time() + $this->timedelta + 30) * pow(2, 30)) * 4) < $new_message_id) {
throw new Exception("Given message id is too new.");
throw new Exception('Given message id is too new.');
}
foreach ($this->message_ids as $message_id) {
if ($new_message_id <= $message_id) {
throw new Exception("Given message id is lower than or equal than the current limit (".$message_id.").");
throw new Exception('Given message id is lower than or equal than the current limit ('.$message_id.').');
}
}
$this->message_ids[] = $new_message_id;
if (count($this->message_ids) > $this->settings["authorization"]["message_ids_limit"]) {
if (count($this->message_ids) > $this->settings['authorization']['message_ids_limit']) {
array_shift($this->message_ids);
}
}
/**
* Function to get hex crc32.
*
@ -260,6 +262,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
} else {
throw new Exception('Got unknown auth_key id');
}
return $data;
}
@ -327,7 +330,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
if ($expires_in == -1) {
$data = $this->tl->serialize_obj('p_q_inner_data', ['pq' => $pq_bytes, 'p' => $p_bytes, 'q' => $q_bytes, 'nonce' => $nonce, 'server_nonce' => $server_nonce, 'new_nonce' => $new_nonce]);
} else {
$data = $this->tl->serialize_obj('p_q_inner_data_temp', ['pq' => $pq_bytes, 'p' => $p_bytes, 'q' => $q_bytes, 'nonce' => $nonce, 'server_nonce' => $server_nonce, 'new_nonce' => $new_nonce, "expires_in" => $expires_in]);
$data = $this->tl->serialize_obj('p_q_inner_data_temp', ['pq' => $pq_bytes, 'p' => $p_bytes, 'q' => $q_bytes, 'nonce' => $nonce, 'server_nonce' => $server_nonce, 'new_nonce' => $new_nonce, 'expires_in' => $expires_in]);
}
$sha_digest = sha1($data, true);
@ -413,7 +416,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
$auth_key_id = substr($auth_key_sha, -8);
$this->log->log('Auth key generated');
return ["auth_key" => $auth_key, "auth_key_id" => $auth_key_id, "server_salt", $server_salt];
return ['auth_key' => $auth_key, 'auth_key_id' => $auth_key_id, 'server_salt', $server_salt];
} elseif ($Set_client_DH_params_answer['_'] == 'dh_gen_retry') {
if ($Set_client_DH_params_answer['new_nonce_hash2'] != $new_nonce_hash2) {
throw new Exception('Handshake: wrong new_nonce_hash_2');

View File

@ -130,13 +130,19 @@ class TL
break;
}
}
public function deserialize($bytes_io, $type_ = null, $subtype = null) {
public function deserialize($bytes_io, $type_ = null, $subtype = null)
{
return $this->deserialize_length($bytes_io, $type_, $subtype);
}
public function get_length($bytes_io, $type_ = null, $subtype = null) {
public function get_length($bytes_io, $type_ = null, $subtype = null)
{
$this->deserialize_length($bytes_io, $type_, $subtype);
return ftell($bytes_io);
}
/**
* :type bytes_io: io.BytesIO object.
*/
@ -215,7 +221,7 @@ class TL
if (in_array($tl_elem->type, $base_boxed_types)) {
$x = $this->deserialize_length($bytes_io, $tl_elem->predicate, $subtype);
} else {
$x = [ "_" => $tl_elem->predicate ];
$x = ['_' => $tl_elem->predicate];
foreach ($tl_elem->params as $arg) {
$x[$arg['name']] = $this->deserialize_length($bytes_io, $arg['type'], $arg['subtype']);
}