Skip to content

Commit ed9c7e4

Browse files
committed
Simplify the error handling a bit
1 parent c2a29c8 commit ed9c7e4

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

pyrogram/crypto/mtproto.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from hashlib import sha256
2121
from io import BytesIO
2222
from os import urandom
23-
from typing import List, Tuple
23+
from typing import List
2424

2525
from pyrogram.raw.core import Message, Long
2626
from . import aes
@@ -60,8 +60,8 @@ def unpack(
6060
auth_key: bytes,
6161
auth_key_id: bytes,
6262
stored_msg_ids: List[int]
63-
) -> Tuple[Message, bool]:
64-
assert b.read(8) == auth_key_id, b.getvalue()
63+
) -> Message:
64+
assert b.read(8) == auth_key_id
6565

6666
msg_key = b.read(16)
6767
aes_key, aes_iv = kdf(auth_key, msg_key, False)
@@ -105,22 +105,22 @@ def unpack(
105105
if stored_msg_ids:
106106
# Ignored message: msg_id is lower than all of the stored values
107107
if message.msg_id < stored_msg_ids[0]:
108-
return message, False
108+
assert False
109109

110110
# Ignored message: msg_id is equal to any of the stored values
111111
if message.msg_id in stored_msg_ids:
112-
return message, False
112+
assert False
113113

114114
time_diff = (message.msg_id - MsgId()) / 2 ** 32
115115

116116
# Ignored message: msg_id belongs over 30 seconds in the future
117117
if time_diff > 30:
118-
return message, False
118+
assert False
119119

120120
# Ignored message: msg_id belongs over 300 seconds in the past
121121
if time_diff < -300:
122-
return message, False
122+
assert False
123123

124124
bisect.insort(stored_msg_ids, message.msg_id)
125125

126-
return message, True
126+
return message

pyrogram/session/session.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ async def restart(self):
221221

222222
async def handle_packet(self, packet):
223223
try:
224-
data, ok = await self.loop.run_in_executor(
224+
data = await self.loop.run_in_executor(
225225
pyrogram.crypto_executor,
226226
mtproto.unpack,
227227
BytesIO(packet),
@@ -234,10 +234,6 @@ async def handle_packet(self, packet):
234234
self.connection.close()
235235
return
236236

237-
if not ok:
238-
self.connection.close()
239-
return
240-
241237
messages = (
242238
data.body.messages
243239
if isinstance(data.body, MsgContainer)

0 commit comments

Comments
 (0)