Remove critical code from assert statements

This commit is contained in:
Lonami Exo 2018-08-14 19:14:13 +02:00
parent 7efa53fedf
commit f4b9c9d6d4
4 changed files with 17 additions and 7 deletions

View File

@ -16,10 +16,14 @@ class Raw(EventBuilder):
if not types:
self.types = None
elif not utils.is_list_like(types):
assert isinstance(types, type)
if not isinstance(types, type):
raise TypeError('Invalid input type given %s', types)
self.types = types
else:
assert all(isinstance(x, type) for x in types)
if not all(isinstance(x, type) for x in types):
raise TypeError('Invalid input types given %s', types)
self.types = tuple(types)
async def resolve(self, client):

View File

@ -163,7 +163,9 @@ async def do_authentication(sender):
if dh_hash != new_nonce_hash:
raise SecurityError('Step 3 invalid new nonce hash')
assert isinstance(dh_gen, DhGenOk), 'Step 3.2 answer was %s' % dh_gen
if not isinstance(dh_gen, DhGenOk):
raise AssertionError('Step 3.2 answer was %s' % dh_gen)
return auth_key, time_offset

View File

@ -39,15 +39,18 @@ class MTProtoPlainSender:
raise BrokenAuthKeyError()
with BinaryReader(body) as reader:
assert reader.read_long() == 0, 'Bad auth_key_id' # auth_key_id
auth_key_id = reader.read_long()
assert auth_key_id == 0, 'Bad auth_key_id'
assert reader.read_long() != 0, 'Bad msg_id' # msg_id
msg_id = reader.read_long()
assert msg_id != 0, 'Bad msg_id'
# ^ We should make sure that the read ``msg_id`` is greater
# than our own ``msg_id``. However, under some circumstances
# (bad system clock/working behind proxies) this seems to not
# be the case, which would cause endless assertion errors.
assert reader.read_int() > 0, 'Bad length' # length
length = reader.read_int()
assert length > 0, 'Bad length'
# We could read length bytes and use those in a new reader to read
# the next TLObject without including the padding, but since the
# reader isn't used for anything else after this, it's unnecessary.

View File

@ -31,7 +31,8 @@ class GzipPacked(TLObject):
@staticmethod
def read(reader):
assert reader.read_int(signed=False) == GzipPacked.CONSTRUCTOR_ID
constructor = reader.read_int(signed=False)
assert constructor == GzipPacked.CONSTRUCTOR_ID
return gzip.decompress(reader.tgread_bytes())
@classmethod