mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-05 03:22:29 +00:00
Fix saving of StringSession
This commit is contained in:
@@ -2,6 +2,7 @@ import base64
|
||||
import ipaddress
|
||||
import struct
|
||||
|
||||
from .abstract import Session
|
||||
from .memory import MemorySession
|
||||
from ..crypto import AuthKey
|
||||
|
||||
@@ -34,7 +35,7 @@ class StringSession(MemorySession):
|
||||
string = string[1:]
|
||||
ip_len = 4 if len(string) == 352 else 16
|
||||
self._dc_id, ip, self._port, key = struct.unpack(
|
||||
_STRUCT_PREFORMAT.format(ip_len), self.decode(string))
|
||||
_STRUCT_PREFORMAT.format(ip_len), StringSession.decode(string))
|
||||
|
||||
self._server_address = ipaddress.ip_address(ip).compressed
|
||||
if any(key):
|
||||
@@ -48,15 +49,15 @@ class StringSession(MemorySession):
|
||||
def decode(x: str) -> bytes:
|
||||
return base64.urlsafe_b64decode(x)
|
||||
|
||||
def save(self):
|
||||
if not self._auth_key:
|
||||
def save(self: Session):
|
||||
if not self.auth_key:
|
||||
return ''
|
||||
|
||||
ip = ipaddress.ip_address(self._server_address).packed
|
||||
return CURRENT_VERSION + self.encode(struct.pack(
|
||||
ip = ipaddress.ip_address(self.server_address).packed
|
||||
return CURRENT_VERSION + StringSession.encode(struct.pack(
|
||||
_STRUCT_PREFORMAT.format(len(ip)),
|
||||
self._dc_id,
|
||||
self.dc_id,
|
||||
ip,
|
||||
self._port,
|
||||
self._auth_key.key
|
||||
self.port,
|
||||
self.auth_key.key
|
||||
))
|
||||
|
Reference in New Issue
Block a user