tests directory
This commit is contained in:
parent
52456b2f25
commit
4c1b5bd54f
16
mtproto.py
16
mtproto.py
@ -2,7 +2,7 @@
|
|||||||
"""
|
"""
|
||||||
Created on Tue Sep 2 19:26:15 2014
|
Created on Tue Sep 2 19:26:15 2014
|
||||||
|
|
||||||
@author: agrigoryev
|
@author: Anton Grigoryev
|
||||||
@author: Sammy Pfeiffer
|
@author: Sammy Pfeiffer
|
||||||
"""
|
"""
|
||||||
from binascii import crc32 as originalcrc32
|
from binascii import crc32 as originalcrc32
|
||||||
@ -11,12 +11,11 @@ def crc32(data):
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from time import time
|
from time import time
|
||||||
import io
|
import io
|
||||||
|
import os.path
|
||||||
import json
|
import json
|
||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def vis(bs):
|
def vis(bs):
|
||||||
"""
|
"""
|
||||||
Function to visualize byte streams. Split into bytes, print to console.
|
Function to visualize byte streams. Split into bytes, print to console.
|
||||||
@ -27,7 +26,8 @@ def vis(bs):
|
|||||||
n = len(bs) // symbols_in_one_line
|
n = len(bs) // symbols_in_one_line
|
||||||
for i in range(n):
|
for i in range(n):
|
||||||
print(str(i*symbols_in_one_line)+" | "+" ".join(["%02X" % b for b in bs[i*symbols_in_one_line:(i+1)*symbols_in_one_line]])) # for every 8 symbols line
|
print(str(i*symbols_in_one_line)+" | "+" ".join(["%02X" % b for b in bs[i*symbols_in_one_line:(i+1)*symbols_in_one_line]])) # for every 8 symbols line
|
||||||
print(" ".join(["%02X" % b for b in bs[(i+1)*symbols_in_one_line:]])+"\n") # for last line
|
if not len(bs) % symbols_in_one_line == 0:
|
||||||
|
print(str((i+1)*symbols_in_one_line)+" | "+" ".join(["%02X" % b for b in bs[(i+1)*symbols_in_one_line:]])+"\n") # for last line
|
||||||
|
|
||||||
|
|
||||||
class TlConstructor:
|
class TlConstructor:
|
||||||
@ -77,8 +77,8 @@ class TL:
|
|||||||
self.method_name[z.method] = z
|
self.method_name[z.method] = z
|
||||||
|
|
||||||
|
|
||||||
## Loading TL_schema
|
## Loading TL_schema (should be placed in the same directory as mtproto.py
|
||||||
tl = TL("TL_schema.JSON")
|
tl = TL(os.path.join(os.path.dirname(__file__), "TL_schema.JSON"))
|
||||||
|
|
||||||
|
|
||||||
def serialize_obj(bytes_io, type_, **kwargs):
|
def serialize_obj(bytes_io, type_, **kwargs):
|
||||||
@ -140,10 +140,10 @@ def deserialize(bytes_io, type_=None, subtype=None):
|
|||||||
elif type_ == 'int256': x = bytes_io.read(32)
|
elif type_ == 'int256': x = bytes_io.read(32)
|
||||||
elif type_ == 'string' or type_ == 'bytes':
|
elif type_ == 'string' or type_ == 'bytes':
|
||||||
l = struct.unpack('<b', bytes_io.read(1))[0]
|
l = struct.unpack('<b', bytes_io.read(1))[0]
|
||||||
assert l <= 254
|
assert l <= 254 # In general, 0xFF byte is not allowed here
|
||||||
if l == 254:
|
if l == 254:
|
||||||
# We have a long string
|
# We have a long string
|
||||||
long_len = struct.unpack('<l', bytes_io.read(3))[0]
|
long_len = struct.unpack('<i', bytes_io.read(3))[0]
|
||||||
x = bytes_io.read(long_len)
|
x = bytes_io.read(long_len)
|
||||||
bytes_io.read(-long_len % 4) # skip padding bytes
|
bytes_io.read(-long_len % 4) # skip padding bytes
|
||||||
else:
|
else:
|
||||||
|
11
testing.py
11
testing.py
@ -75,14 +75,3 @@ z = Session.method_call('req_DH_params',
|
|||||||
|
|
||||||
print(z)
|
print(z)
|
||||||
|
|
||||||
# # used for serialization and SHA testing (passed)
|
|
||||||
# z = io.BytesIO()
|
|
||||||
# mtproto.serialize_obj(z, 'p_q_inner_data',
|
|
||||||
# pq=b"\x17\xED\x48\x94\x1A\x08\xF9\x81",
|
|
||||||
# p=b"\x49\x4C\x55\x3B",
|
|
||||||
# q=b"\x53\x91\x10\x73",
|
|
||||||
# nonce=b"\x3E\x05\x49\x82\x8C\xCA\x27\xE9\x66\xB3\x01\xA4\x8F\xEC\xE2\xFC",
|
|
||||||
# server_nonce=b"\xA5\xCF\x4D\x33\xF4\xA1\x1E\xA8\x77\xBA\x4A\xA5\x73\x90\x73\x30",
|
|
||||||
# new_nonce=b"\x31\x1C\x85\xDB\x23\x4A\xA2\x64\x0A\xFC\x4A\x76\xA7\x35\xCF\x5B\x1F\x0F\xD6\x8B\xD1\x7F\xA1\x81\xE1\x22\x9A\xD8\x67\xCC\x02\x4D")
|
|
||||||
# x=z.getvalue()
|
|
||||||
# print(SHA.new(x).hexdigest())
|
|
Loading…
Reference in New Issue
Block a user