feat(MtProtoState): reset auth_key on reset

This commit is contained in:
habcawa 2025-05-20 16:19:09 +02:00
parent 54cb16783f
commit a6259eaf3f

View File

@ -4,7 +4,7 @@ import time
from hashlib import sha1, sha256 from hashlib import sha1, sha256
from collections import deque from collections import deque
from ..crypto import AES from ..crypto import AES, AuthKey
from ..errors import SecurityError, InvalidBufferError from ..errors import SecurityError, InvalidBufferError
from ..extensions import BinaryReader from ..extensions import BinaryReader
from ..tl.core import TLMessage from ..tl.core import TLMessage
@ -70,10 +70,12 @@ class MTProtoState:
self._ignore_count = 0 self._ignore_count = 0
self.reset() self.reset()
def reset(self): def reset(self, keep_key=False):
""" """
Resets the state. Resets the state.
""" """
self._log.debug('MtProtoState reset')
# Session IDs can be random on every connection # Session IDs can be random on every connection
self.id = struct.unpack('q', os.urandom(8))[0] self.id = struct.unpack('q', os.urandom(8))[0]
self._sequence = 0 self._sequence = 0
@ -82,6 +84,10 @@ class MTProtoState:
self._highest_remote_id = 0 self._highest_remote_id = 0
self._ignore_count = 0 self._ignore_count = 0
if not keep_key:
self.auth_key = AuthKey(None)
self._log.debug('MtProtoState key reset')
def update_message_id(self, message): def update_message_id(self, message):
""" """
Updates the message ID to a new one, Updates the message ID to a new one,