Applied fixes from StyleCI
This commit is contained in:
parent
741f166640
commit
3a0a7179d4
@ -11,6 +11,7 @@ If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace danog\MadelineProto;
|
||||
|
||||
class API extends Exception
|
||||
{
|
||||
public $session;
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace danog\MadelineProto;
|
||||
|
||||
/**
|
||||
* Manages connection to telegram servers.
|
||||
*/
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace danog\MadelineProto;
|
||||
|
||||
class Crypt
|
||||
{
|
||||
public function ige_encrypt($message, $key, $iv)
|
||||
|
@ -9,9 +9,11 @@ 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace danog\MadelineProto;
|
||||
|
||||
class DebugFunctions {
|
||||
class DebugFunctions
|
||||
{
|
||||
/**
|
||||
* Function to dump the hex version of a string.
|
||||
*
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -12,10 +12,14 @@ If not, see <http://www.gnu.org/licenses/>.
|
||||
/*
|
||||
* Logging class
|
||||
*/
|
||||
|
||||
namespace danog\MadelineProto;
|
||||
class Logging {
|
||||
|
||||
class Logging
|
||||
{
|
||||
public $mode = null;
|
||||
public $optional = null;
|
||||
|
||||
/*
|
||||
* Constructor function
|
||||
* Accepts various logging modes:
|
||||
@ -24,11 +28,14 @@ class Logging {
|
||||
* 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,7 +69,7 @@ class Logging {
|
||||
error_log($param, 3, $this->optional);
|
||||
break;
|
||||
case '3':
|
||||
echo $param . PHP_EOL;
|
||||
echo $param.PHP_EOL;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace danog\MadelineProto;
|
||||
|
||||
class PrimeModule
|
||||
{
|
||||
public function __construct()
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace danog\MadelineProto;
|
||||
|
||||
/**
|
||||
* Manages encryption and message frames.
|
||||
*/
|
||||
@ -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])) {
|
||||
@ -65,9 +67,9 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
|
||||
$this->tl = new TL\TL(__DIR__.'/TL_schema.JSON');
|
||||
}
|
||||
// Istantiate logging class
|
||||
$this->log = new Logging($this->settings["logging"], $this->settings["logging_param"]);
|
||||
$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.");
|
||||
}
|
||||
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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('<i', $tl_constructor->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('<i', $tl_method->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_);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace danog\MadelineProto\TL;
|
||||
|
||||
class TLConstructor
|
||||
{
|
||||
public function __construct($json_dict)
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace danog\MadelineProto\TL;
|
||||
|
||||
class TLMethod
|
||||
{
|
||||
public function __construct($json_dict)
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace danog\MadelineProto\TL;
|
||||
|
||||
class TLObject extends \ArrayObject
|
||||
{
|
||||
public function __construct($tl_elem)
|
||||
|
@ -11,6 +11,7 @@ If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user