Skip to content

Commit fe764e0

Browse files
authored
Update session string format (pyrogram#818)
1 parent ef6125b commit fe764e0

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

pyrogram/storage/memory_storage.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ async def open(self):
3636

3737
if self.name != ":memory:":
3838
dc_id, test_mode, auth_key, user_id, is_bot = struct.unpack(
39-
self.SESSION_STRING_FORMAT,
39+
(self.SESSION_STRING_FORMAT if len(self.name) == MemoryStorage.SESSION_STRING_SIZE else
40+
self.SESSION_STRING_FORMAT_64),
4041
base64.urlsafe_b64decode(
4142
self.name + "=" * (-len(self.name) % 4)
4243
)

pyrogram/storage/storage.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@
2020
import struct
2121
from typing import List, Tuple
2222

23+
from pyrogram import utils
24+
2325

2426
class Storage:
2527
SESSION_STRING_FORMAT = ">B?256sI?"
28+
SESSION_STRING_FORMAT_64 = ">B?256sQ?"
2629
SESSION_STRING_SIZE = 351
30+
SESSION_STRING_SIZE_64 = 356
2731

2832
def __init__(self, name: str):
2933
self.name = name
@@ -71,13 +75,14 @@ async def is_bot(self, value: bool = object):
7175
raise NotImplementedError
7276

7377
async def export_session_string(self):
78+
user_id = await self.user_id()
7479
return base64.urlsafe_b64encode(
7580
struct.pack(
76-
self.SESSION_STRING_FORMAT,
81+
self.SESSION_STRING_FORMAT if user_id < utils.MAX_USER_ID_OLD else self.SESSION_STRING_FORMAT_64,
7782
await self.dc_id(),
7883
await self.test_mode(),
7984
await self.auth_key(),
80-
await self.user_id(),
85+
user_id,
8186
await self.is_bot()
8287
)
8388
).decode().rstrip("=")

pyrogram/utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def unpack_inline_message_id(inline_message_id: str) -> "raw.types.InputBotInlin
159159
MIN_CHANNEL_ID = -1002147483647
160160
MAX_CHANNEL_ID = -1000000000000
161161
MIN_CHAT_ID = -2147483647
162+
MAX_USER_ID_OLD = 2147483647
162163
MAX_USER_ID = 999999999999
163164

164165

0 commit comments

Comments
 (0)