Detect arbitrary negative HTTP error codes

This commit is contained in:
Lonami Exo
2018-10-12 19:47:40 +02:00
parent cca7055fcf
commit 6e77f583f1
5 changed files with 28 additions and 20 deletions
+3 -4
View File
@@ -5,7 +5,7 @@ in plain text, when no authorization key has been created yet.
import struct
from .mtprotostate import MTProtoState
from ..errors import BrokenAuthKeyError
from ..errors import InvalidBufferError
from ..extensions import BinaryReader
@@ -34,9 +34,8 @@ class MTProtoPlainSender:
)
body = await self._connection.recv()
if body == b'l\xfe\xff\xff': # -404 little endian signed
# Broken authorization, must reset the auth key
raise BrokenAuthKeyError()
if len(body) < 8:
raise InvalidBufferError(body)
with BinaryReader(body) as reader:
auth_key_id = reader.read_long()