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,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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,23 +12,30 @@ 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
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
*/
|
||||
@ -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.");
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
@ -17,4 +19,4 @@ class TLObject extends \ArrayObject
|
||||
parent::__construct();
|
||||
$this->name = $tl_elem->predicate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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