diff --git a/pyrogram/storage/memory_storage.py b/pyrogram/storage/memory_storage.py index 49343540..5f097a1c 100644 --- a/pyrogram/storage/memory_storage.py +++ b/pyrogram/storage/memory_storage.py @@ -36,7 +36,8 @@ class MemoryStorage(SQLiteStorage): if self.name != ":memory:": dc_id, test_mode, auth_key, user_id, is_bot = struct.unpack( - self.SESSION_STRING_FORMAT, + (self.SESSION_STRING_FORMAT if len(self.name) == MemoryStorage.SESSION_STRING_SIZE else + self.SESSION_STRING_FORMAT_64), base64.urlsafe_b64decode( self.name + "=" * (-len(self.name) % 4) ) diff --git a/pyrogram/storage/storage.py b/pyrogram/storage/storage.py index c506c8ca..3690cafd 100644 --- a/pyrogram/storage/storage.py +++ b/pyrogram/storage/storage.py @@ -20,10 +20,14 @@ import base64 import struct from typing import List, Tuple +from pyrogram import utils + class Storage: SESSION_STRING_FORMAT = ">B?256sI?" + SESSION_STRING_FORMAT_64 = ">B?256sQ?" SESSION_STRING_SIZE = 351 + SESSION_STRING_SIZE_64 = 356 def __init__(self, name: str): self.name = name @@ -71,13 +75,14 @@ class Storage: raise NotImplementedError async def export_session_string(self): + user_id = await self.user_id() return base64.urlsafe_b64encode( struct.pack( - self.SESSION_STRING_FORMAT, + self.SESSION_STRING_FORMAT if user_id < utils.MAX_USER_ID_OLD else self.SESSION_STRING_FORMAT_64, await self.dc_id(), await self.test_mode(), await self.auth_key(), - await self.user_id(), + user_id, await self.is_bot() ) ).decode().rstrip("=") diff --git a/pyrogram/utils.py b/pyrogram/utils.py index e5b15aad..9d53d8bf 100644 --- a/pyrogram/utils.py +++ b/pyrogram/utils.py @@ -159,6 +159,7 @@ def unpack_inline_message_id(inline_message_id: str) -> "raw.types.InputBotInlin MIN_CHANNEL_ID = -1002147483647 MAX_CHANNEL_ID = -1000000000000 MIN_CHAT_ID = -2147483647 +MAX_USER_ID_OLD = 2147483647 MAX_USER_ID = 999999999999