From b04cf9ec9297ce0884943879b1fac07fa7e2933f Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Thu, 21 Feb 2019 21:43:57 +0300 Subject: [PATCH] Add string session storage --- pyrogram/client/session_storage/__init__.py | 1 + .../session_storage/string_session_storage.py | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 pyrogram/client/session_storage/string_session_storage.py diff --git a/pyrogram/client/session_storage/__init__.py b/pyrogram/client/session_storage/__init__.py index 6ee92ebc..ced103ce 100644 --- a/pyrogram/client/session_storage/__init__.py +++ b/pyrogram/client/session_storage/__init__.py @@ -19,3 +19,4 @@ from .session_storage_mixin import SessionStorageMixin from .base_session_storage import BaseSessionStorage, SessionDoesNotExist from .json_session_storage import JsonSessionStorage +from .string_session_storage import StringSessionStorage diff --git a/pyrogram/client/session_storage/string_session_storage.py b/pyrogram/client/session_storage/string_session_storage.py new file mode 100644 index 00000000..9b6ebf0e --- /dev/null +++ b/pyrogram/client/session_storage/string_session_storage.py @@ -0,0 +1,38 @@ +import base64 +import binascii +import struct + +from . import BaseSessionStorage, SessionDoesNotExist + + +def StringSessionStorage(print_session: bool = False): + class StringSessionStorageClass(BaseSessionStorage): + """ + Packs session data as following (forcing little-endian byte order): + Char dc_id (1 byte, unsigned) + Boolean test_mode (1 byte) + Long long user_id (8 bytes, signed) + Bytes auth_key (256 bytes) + + Uses Base64 encoding for printable representation + """ + PACK_FORMAT = '