mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-11 03:56:36 +03:00
Significantly clean-up imports
Sure wish I would've automated this.
This commit is contained in:
parent
f75acee7e8
commit
4b2d252fe1
|
@ -1 +1,6 @@
|
|||
from ._impl import tl as _tl
|
||||
from ._impl.client import Client, Config
|
||||
from ._impl.session import Session
|
||||
from .version import __version__
|
||||
|
||||
__all__ = ["_tl", "Client", "Config", "Session"]
|
||||
|
|
0
client/src/telethon/_impl/__init__.py
Normal file
0
client/src/telethon/_impl/__init__.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from .client import Client, Config
|
||||
|
||||
__all__ = ["Client", "Config"]
|
|
@ -0,0 +1,15 @@
|
|||
from .bots import InlineResult, InlineResults
|
||||
from .client import Client
|
||||
from .files import File, InFileLike, MediaLike, OutFileLike
|
||||
from .net import Config
|
||||
|
||||
__all__ = [
|
||||
"InlineResult",
|
||||
"InlineResults",
|
||||
"Client",
|
||||
"File",
|
||||
"InFileLike",
|
||||
"MediaLike",
|
||||
"OutFileLike",
|
||||
"Config",
|
||||
]
|
|
@ -2,13 +2,11 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING, Optional, Union
|
||||
|
||||
from ...mtproto.mtp.types import RpcError
|
||||
from ...session.message_box.defs import Session
|
||||
from ...session.message_box.defs import User as SessionUser
|
||||
from ...mtproto import RpcError
|
||||
from ...session import Session
|
||||
from ...session import User as SessionUser
|
||||
from ...tl import abcs, functions, types
|
||||
from ..types.chat.user import User
|
||||
from ..types.login_token import LoginToken
|
||||
from ..types.password_token import PasswordToken
|
||||
from ..types import LoginToken, PasswordToken, User
|
||||
from .net import connect_sender
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
|
@ -2,10 +2,8 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING, AsyncIterator, List, Optional, Self, Union
|
||||
|
||||
from ...._impl.tl import abcs, functions, types
|
||||
from ..types.chat import ChatLike
|
||||
from ..types.message import Message
|
||||
from ..types.meta import NoPublicConstructor
|
||||
from ...tl import abcs, functions, types
|
||||
from ..types import ChatLike, Message, NoPublicConstructor
|
||||
from ..utils import generate_random_id
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
|
@ -15,19 +15,10 @@ from typing import (
|
|||
Union,
|
||||
)
|
||||
|
||||
from ...mtsender.sender import Sender
|
||||
from ...session.chat.hash_cache import ChatHashCache
|
||||
from ...session.chat.packed import PackedChat
|
||||
from ...session.message_box.defs import Session
|
||||
from ...session.message_box.messagebox import MessageBox
|
||||
from ...tl import abcs
|
||||
from ...tl.core.request import Request
|
||||
from ..types.async_list import AsyncList
|
||||
from ..types.chat import ChatLike
|
||||
from ..types.chat.user import User
|
||||
from ..types.login_token import LoginToken
|
||||
from ..types.message import Message
|
||||
from ..types.password_token import PasswordToken
|
||||
from ...mtsender import Sender
|
||||
from ...session import ChatHashCache, MessageBox, PackedChat, Session
|
||||
from ...tl import Request, abcs
|
||||
from ..types import AsyncList, ChatLike, LoginToken, Message, PasswordToken, User
|
||||
from .account import edit_2fa, end_takeout, takeout
|
||||
from .auth import (
|
||||
bot_sign_in,
|
||||
|
|
|
@ -7,9 +7,7 @@ from pathlib import Path
|
|||
from typing import TYPE_CHECKING, Any, Coroutine, List, Optional, Protocol, Self, Union
|
||||
|
||||
from ...tl import abcs, functions, types
|
||||
from ..types.chat import ChatLike
|
||||
from ..types.message import Message
|
||||
from ..types.meta import NoPublicConstructor
|
||||
from ..types import ChatLike, Message, NoPublicConstructor
|
||||
from ..utils import generate_random_id
|
||||
from .messages import parse_message
|
||||
|
||||
|
|
|
@ -2,25 +2,12 @@ from __future__ import annotations
|
|||
|
||||
import datetime
|
||||
import sys
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Coroutine,
|
||||
Dict,
|
||||
List,
|
||||
Literal,
|
||||
Optional,
|
||||
Tuple,
|
||||
Union,
|
||||
)
|
||||
|
||||
from telethon._impl.client.types.async_list import AsyncList
|
||||
from telethon._impl.session.chat.packed import PackedChat
|
||||
from typing import TYPE_CHECKING, Dict, List, Literal, Optional, Tuple, Union
|
||||
|
||||
from ...session import PackedChat
|
||||
from ...tl import abcs, functions, types
|
||||
from ..parsers import parse_html_message, parse_markdown_message
|
||||
from ..types.chat import ChatLike
|
||||
from ..types.message import Message
|
||||
from ..types import AsyncList, ChatLike, Message
|
||||
from ..utils import generate_random_id
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
|
@ -7,14 +7,12 @@ from dataclasses import dataclass, field
|
|||
from typing import TYPE_CHECKING, Optional, TypeVar
|
||||
|
||||
from ....version import __version__
|
||||
from ...mtproto.mtp.types import RpcError
|
||||
from ...mtproto.transport.full import Full
|
||||
from ...mtsender.sender import Sender
|
||||
from ...mtsender.sender import connect as connect_without_auth
|
||||
from ...mtsender.sender import connect_with_auth
|
||||
from ...session.message_box.defs import DataCenter, Session
|
||||
from ...tl import LAYER, functions
|
||||
from ...tl.core.request import Request
|
||||
from ...mtproto import Full, RpcError
|
||||
from ...mtsender import Sender
|
||||
from ...mtsender import connect as connect_without_auth
|
||||
from ...mtsender import connect_with_auth
|
||||
from ...session import DataCenter, Session
|
||||
from ...tl import LAYER, Request, functions
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .client import Client
|
||||
|
|
|
@ -2,9 +2,9 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from ...session.chat.packed import PackedChat, PackedType
|
||||
from ...session import PackedChat, PackedType
|
||||
from ...tl import abcs, types
|
||||
from ..types.chat import Channel, ChatLike, Group, User
|
||||
from ..types import Channel, ChatLike, Group, User
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .client import Client
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
from .async_list import AsyncList
|
||||
from .chat import Channel, Chat, ChatLike, Group, RestrictionReason, User
|
||||
from .login_token import LoginToken
|
||||
from .message import Message
|
||||
from .meta import NoPublicConstructor
|
||||
from .password_token import PasswordToken
|
||||
|
||||
__all__ = [
|
||||
"AsyncList",
|
||||
"Channel",
|
||||
"Chat",
|
||||
"ChatLike",
|
||||
"Group",
|
||||
"RestrictionReason",
|
||||
"User",
|
||||
"LoginToken",
|
||||
"Message",
|
||||
"NoPublicConstructor",
|
||||
"PasswordToken",
|
||||
]
|
|
@ -1,6 +1,6 @@
|
|||
from typing import Union
|
||||
|
||||
from ....session.chat.packed import PackedChat
|
||||
from ....session import PackedChat
|
||||
from ....tl import abcs
|
||||
from .channel import Channel
|
||||
from .group import Group
|
||||
|
@ -9,4 +9,4 @@ from .user import RestrictionReason, User
|
|||
Chat = Union[Channel, Group, User]
|
||||
ChatLike = Union[Chat, PackedChat, int, str, abcs.InputPeer]
|
||||
|
||||
__all__ = ["Chat", "Channel", "Group", "RestrictionReason", "User"]
|
||||
__all__ = ["Chat", "ChatLike", "Channel", "Group", "RestrictionReason", "User"]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from typing import Optional, Self, Union
|
||||
|
||||
from ....session.chat.packed import PackedChat, PackedType
|
||||
from ....session import PackedChat, PackedType
|
||||
from ....tl import abcs, types
|
||||
from ..meta import NoPublicConstructor
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from typing import Optional, Self, Union
|
||||
|
||||
from ....session.chat.packed import PackedChat, PackedType
|
||||
from ....session import PackedChat, PackedType
|
||||
from ....tl import abcs, types
|
||||
from ..meta import NoPublicConstructor
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from typing import List, Optional, Self
|
||||
|
||||
from ....session.chat.packed import PackedChat, PackedType
|
||||
from ....session import PackedChat, PackedType
|
||||
from ....tl import abcs, types
|
||||
from ..meta import NoPublicConstructor
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from typing import Self
|
||||
|
||||
from telethon._impl.tl import types
|
||||
|
||||
from ...tl import types
|
||||
from .meta import NoPublicConstructor
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import datetime
|
||||
from typing import Optional, Self
|
||||
|
||||
from ...client.types.chat import Chat
|
||||
from ...tl import abcs, types
|
||||
from .chat import Chat
|
||||
from .meta import NoPublicConstructor
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from typing import Self
|
||||
|
||||
from telethon._impl.tl import types
|
||||
|
||||
from ...tl import types
|
||||
from .meta import NoPublicConstructor
|
||||
|
||||
|
||||
|
|
|
@ -1,115 +1,26 @@
|
|||
import os
|
||||
from collections import namedtuple
|
||||
from enum import IntEnum
|
||||
from hashlib import sha1, sha256
|
||||
|
||||
from .aes import ige_decrypt, ige_encrypt
|
||||
from .auth_key import AuthKey
|
||||
from .crypto import (
|
||||
Side,
|
||||
calc_key,
|
||||
decrypt_data_v2,
|
||||
decrypt_ige,
|
||||
encrypt_data_v2,
|
||||
encrypt_ige,
|
||||
generate_key_data_from_nonce,
|
||||
)
|
||||
from .factorize import factorize
|
||||
from .rsa import RSA_KEYS, encrypt_hashed
|
||||
|
||||
|
||||
# "where x = 0 for messages from client to server and x = 8 for those from server to client"
|
||||
class Side(IntEnum):
|
||||
CLIENT = 0
|
||||
SERVER = 8
|
||||
|
||||
|
||||
CalcKey = namedtuple("CalcKey", ("key", "iv"))
|
||||
|
||||
|
||||
# https://core.telegram.org/mtproto/description#defining-aes-key-and-initialization-vector
|
||||
def calc_key(auth_key: AuthKey, msg_key: bytes, side: Side) -> CalcKey:
|
||||
x = int(side)
|
||||
|
||||
# sha256_a = SHA256 (msg_key + substr (auth_key, x, 36))
|
||||
sha256_a = sha256(msg_key + auth_key.data[x : x + 36]).digest()
|
||||
|
||||
# sha256_b = SHA256 (substr (auth_key, 40+x, 36) + msg_key)
|
||||
sha256_b = sha256(auth_key.data[x + 40 : x + 76] + msg_key).digest()
|
||||
|
||||
# aes_key = substr (sha256_a, 0, 8) + substr (sha256_b, 8, 16) + substr (sha256_a, 24, 8)
|
||||
aes_key = sha256_a[:8] + sha256_b[8:24] + sha256_a[24:32]
|
||||
|
||||
# aes_iv = substr (sha256_b, 0, 8) + substr (sha256_a, 8, 16) + substr (sha256_b, 24, 8)
|
||||
aes_iv = sha256_b[:8] + sha256_a[8:24] + sha256_b[24:32]
|
||||
|
||||
return CalcKey(aes_key, aes_iv)
|
||||
|
||||
|
||||
def determine_padding_v2_length(length: int) -> int:
|
||||
return 16 + (16 - (length % 16))
|
||||
|
||||
|
||||
def _do_encrypt_data_v2(
|
||||
plaintext: bytes, auth_key: AuthKey, random_padding: bytes
|
||||
) -> bytes:
|
||||
padded_plaintext = (
|
||||
plaintext + random_padding[: determine_padding_v2_length(len(plaintext))]
|
||||
)
|
||||
|
||||
side = Side.CLIENT
|
||||
x = int(side)
|
||||
|
||||
# msg_key_large = SHA256 (substr (auth_key, 88+x, 32) + plaintext + random_padding)
|
||||
msg_key_large = sha256(auth_key.data[x + 88 : x + 120] + padded_plaintext).digest()
|
||||
|
||||
# msg_key = substr (msg_key_large, 8, 16)
|
||||
msg_key = msg_key_large[8:24]
|
||||
|
||||
key, iv = calc_key(auth_key, msg_key, side)
|
||||
ciphertext = ige_encrypt(padded_plaintext, key, iv)
|
||||
|
||||
return auth_key.key_id + msg_key + ciphertext
|
||||
|
||||
|
||||
def encrypt_data_v2(plaintext: bytes, auth_key: AuthKey) -> bytes:
|
||||
random_padding = os.urandom(32)
|
||||
return _do_encrypt_data_v2(plaintext, auth_key, random_padding)
|
||||
|
||||
|
||||
def decrypt_data_v2(ciphertext: bytes, auth_key: AuthKey) -> bytes:
|
||||
side = Side.SERVER
|
||||
x = int(side)
|
||||
|
||||
if len(ciphertext) < 24 or (len(ciphertext) - 24) % 16 != 0:
|
||||
raise ValueError("invalid ciphertext buffer length")
|
||||
|
||||
# TODO Check salt, session_id and sequence_number
|
||||
key_id = ciphertext[:8]
|
||||
if auth_key.key_id != key_id:
|
||||
raise ValueError("server authkey mismatches with ours")
|
||||
|
||||
msg_key = ciphertext[8:24]
|
||||
key, iv = calc_key(auth_key, msg_key, side)
|
||||
plaintext = ige_decrypt(ciphertext[24:], key, iv)
|
||||
|
||||
# https://core.telegram.org/mtproto/security_guidelines#mtproto-encrypted-messages
|
||||
our_key = sha256(auth_key.data[x + 88 : x + 120] + plaintext).digest()
|
||||
if msg_key != our_key[8:24]:
|
||||
raise ValueError("server msgkey mismatches with ours")
|
||||
|
||||
return plaintext
|
||||
|
||||
|
||||
def generate_key_data_from_nonce(server_nonce: int, new_nonce: int) -> CalcKey:
|
||||
server_bytes = server_nonce.to_bytes(16)
|
||||
new_bytes = new_nonce.to_bytes(32)
|
||||
hash1 = sha1(new_bytes + server_bytes).digest()
|
||||
hash2 = sha1(server_bytes + new_bytes).digest()
|
||||
hash3 = sha1(new_bytes + new_bytes).digest()
|
||||
|
||||
key = hash1 + hash2[:12]
|
||||
iv = hash2[12:20] + hash3 + new_bytes[:4]
|
||||
return CalcKey(key, iv)
|
||||
|
||||
|
||||
def encrypt_ige(plaintext: bytes, key: bytes, iv: bytes) -> bytes:
|
||||
if len(plaintext) % 16 != 0:
|
||||
plaintext += os.urandom((16 - (len(plaintext) % 16)) % 16)
|
||||
return ige_encrypt(plaintext, key, iv)
|
||||
|
||||
|
||||
def decrypt_ige(padded_ciphertext: bytes, key: bytes, iv: bytes) -> bytes:
|
||||
return ige_decrypt(padded_ciphertext, key, iv)
|
||||
|
||||
|
||||
__all__ = ["AuthKey", "encrypt_data_v2", "decrypt_data_v2"]
|
||||
__all__ = [
|
||||
"AuthKey",
|
||||
"Side",
|
||||
"calc_key",
|
||||
"decrypt_data_v2",
|
||||
"decrypt_ige",
|
||||
"encrypt_data_v2",
|
||||
"encrypt_ige",
|
||||
"generate_key_data_from_nonce",
|
||||
"factorize",
|
||||
"RSA_KEYS",
|
||||
"encrypt_hashed",
|
||||
]
|
||||
|
|
112
client/src/telethon/_impl/crypto/crypto.py
Normal file
112
client/src/telethon/_impl/crypto/crypto.py
Normal file
|
@ -0,0 +1,112 @@
|
|||
import os
|
||||
from collections import namedtuple
|
||||
from enum import IntEnum
|
||||
from hashlib import sha1, sha256
|
||||
|
||||
from .aes import ige_decrypt, ige_encrypt
|
||||
from .auth_key import AuthKey
|
||||
|
||||
|
||||
# "where x = 0 for messages from client to server and x = 8 for those from server to client"
|
||||
class Side(IntEnum):
|
||||
CLIENT = 0
|
||||
SERVER = 8
|
||||
|
||||
|
||||
CalcKey = namedtuple("CalcKey", ("key", "iv"))
|
||||
|
||||
|
||||
# https://core.telegram.org/mtproto/description#defining-aes-key-and-initialization-vector
|
||||
def calc_key(auth_key: AuthKey, msg_key: bytes, side: Side) -> CalcKey:
|
||||
x = int(side)
|
||||
|
||||
# sha256_a = SHA256 (msg_key + substr (auth_key, x, 36))
|
||||
sha256_a = sha256(msg_key + auth_key.data[x : x + 36]).digest()
|
||||
|
||||
# sha256_b = SHA256 (substr (auth_key, 40+x, 36) + msg_key)
|
||||
sha256_b = sha256(auth_key.data[x + 40 : x + 76] + msg_key).digest()
|
||||
|
||||
# aes_key = substr (sha256_a, 0, 8) + substr (sha256_b, 8, 16) + substr (sha256_a, 24, 8)
|
||||
aes_key = sha256_a[:8] + sha256_b[8:24] + sha256_a[24:32]
|
||||
|
||||
# aes_iv = substr (sha256_b, 0, 8) + substr (sha256_a, 8, 16) + substr (sha256_b, 24, 8)
|
||||
aes_iv = sha256_b[:8] + sha256_a[8:24] + sha256_b[24:32]
|
||||
|
||||
return CalcKey(aes_key, aes_iv)
|
||||
|
||||
|
||||
def determine_padding_v2_length(length: int) -> int:
|
||||
return 16 + (16 - (length % 16))
|
||||
|
||||
|
||||
def _do_encrypt_data_v2(
|
||||
plaintext: bytes, auth_key: AuthKey, random_padding: bytes
|
||||
) -> bytes:
|
||||
padded_plaintext = (
|
||||
plaintext + random_padding[: determine_padding_v2_length(len(plaintext))]
|
||||
)
|
||||
|
||||
side = Side.CLIENT
|
||||
x = int(side)
|
||||
|
||||
# msg_key_large = SHA256 (substr (auth_key, 88+x, 32) + plaintext + random_padding)
|
||||
msg_key_large = sha256(auth_key.data[x + 88 : x + 120] + padded_plaintext).digest()
|
||||
|
||||
# msg_key = substr (msg_key_large, 8, 16)
|
||||
msg_key = msg_key_large[8:24]
|
||||
|
||||
key, iv = calc_key(auth_key, msg_key, side)
|
||||
ciphertext = ige_encrypt(padded_plaintext, key, iv)
|
||||
|
||||
return auth_key.key_id + msg_key + ciphertext
|
||||
|
||||
|
||||
def encrypt_data_v2(plaintext: bytes, auth_key: AuthKey) -> bytes:
|
||||
random_padding = os.urandom(32)
|
||||
return _do_encrypt_data_v2(plaintext, auth_key, random_padding)
|
||||
|
||||
|
||||
def decrypt_data_v2(ciphertext: bytes, auth_key: AuthKey) -> bytes:
|
||||
side = Side.SERVER
|
||||
x = int(side)
|
||||
|
||||
if len(ciphertext) < 24 or (len(ciphertext) - 24) % 16 != 0:
|
||||
raise ValueError("invalid ciphertext buffer length")
|
||||
|
||||
# TODO Check salt, session_id and sequence_number
|
||||
key_id = ciphertext[:8]
|
||||
if auth_key.key_id != key_id:
|
||||
raise ValueError("server authkey mismatches with ours")
|
||||
|
||||
msg_key = ciphertext[8:24]
|
||||
key, iv = calc_key(auth_key, msg_key, side)
|
||||
plaintext = ige_decrypt(ciphertext[24:], key, iv)
|
||||
|
||||
# https://core.telegram.org/mtproto/security_guidelines#mtproto-encrypted-messages
|
||||
our_key = sha256(auth_key.data[x + 88 : x + 120] + plaintext).digest()
|
||||
if msg_key != our_key[8:24]:
|
||||
raise ValueError("server msgkey mismatches with ours")
|
||||
|
||||
return plaintext
|
||||
|
||||
|
||||
def generate_key_data_from_nonce(server_nonce: int, new_nonce: int) -> CalcKey:
|
||||
server_bytes = server_nonce.to_bytes(16)
|
||||
new_bytes = new_nonce.to_bytes(32)
|
||||
hash1 = sha1(new_bytes + server_bytes).digest()
|
||||
hash2 = sha1(server_bytes + new_bytes).digest()
|
||||
hash3 = sha1(new_bytes + new_bytes).digest()
|
||||
|
||||
key = hash1 + hash2[:12]
|
||||
iv = hash2[12:20] + hash3 + new_bytes[:4]
|
||||
return CalcKey(key, iv)
|
||||
|
||||
|
||||
def encrypt_ige(plaintext: bytes, key: bytes, iv: bytes) -> bytes:
|
||||
if len(plaintext) % 16 != 0:
|
||||
plaintext += os.urandom((16 - (len(plaintext) % 16)) % 16)
|
||||
return ige_encrypt(plaintext, key, iv)
|
||||
|
||||
|
||||
def decrypt_ige(padded_ciphertext: bytes, key: bytes, iv: bytes) -> bytes:
|
||||
return ige_decrypt(padded_ciphertext, key, iv)
|
|
@ -0,0 +1,31 @@
|
|||
from .authentication import CreatedKey, Step1, Step2, Step3, create_key
|
||||
from .authentication import step1 as auth_step1
|
||||
from .authentication import step2 as auth_step2
|
||||
from .authentication import step3 as auth_step3
|
||||
from .mtp import BadMessage, Deserialization, Encrypted, MsgId, Mtp, Plain, RpcError
|
||||
from .transport import Abridged, Full, Intermediate, MissingBytes, Transport
|
||||
from .utils import DEFAULT_COMPRESSION_THRESHOLD
|
||||
|
||||
__all__ = [
|
||||
"CreatedKey",
|
||||
"Step1",
|
||||
"Step2",
|
||||
"Step3",
|
||||
"create_key",
|
||||
"auth_step1",
|
||||
"auth_step2",
|
||||
"auth_step3",
|
||||
"BadMessage",
|
||||
"Deserialization",
|
||||
"Encrypted",
|
||||
"MsgId",
|
||||
"Mtp",
|
||||
"Plain",
|
||||
"RpcError",
|
||||
"Abridged",
|
||||
"Full",
|
||||
"Intermediate",
|
||||
"MissingBytes",
|
||||
"Transport",
|
||||
"DEFAULT_COMPRESSION_THRESHOLD",
|
||||
]
|
|
@ -5,12 +5,16 @@ from dataclasses import dataclass
|
|||
from hashlib import sha1
|
||||
from typing import Tuple
|
||||
|
||||
from telethon._impl.crypto import decrypt_ige, encrypt_ige, generate_key_data_from_nonce
|
||||
from telethon._impl.crypto.auth_key import AuthKey
|
||||
from telethon._impl.crypto.factorize import factorize
|
||||
from telethon._impl.crypto.rsa import RSA_KEYS, encrypt_hashed
|
||||
from telethon._impl.tl.core.reader import Reader
|
||||
|
||||
from ..crypto import (
|
||||
RSA_KEYS,
|
||||
AuthKey,
|
||||
decrypt_ige,
|
||||
encrypt_hashed,
|
||||
encrypt_ige,
|
||||
factorize,
|
||||
generate_key_data_from_nonce,
|
||||
)
|
||||
from ..tl.core import Reader
|
||||
from ..tl.mtproto.abcs import ServerDhInnerData as AbcServerDhInnerData
|
||||
from ..tl.mtproto.abcs import ServerDhParams, SetClientDhParamsAnswer
|
||||
from ..tl.mtproto.functions import req_dh_params, req_pq_multi, set_client_dh_params
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
from .encrypted import Encrypted
|
||||
from .plain import Plain
|
||||
from .types import Deserialization, MsgId, Mtp, RpcError
|
||||
from .types import BadMessage, Deserialization, MsgId, Mtp, RpcError
|
||||
|
||||
__all__ = [
|
||||
"Encrypted",
|
||||
"Plain",
|
||||
"BadMessage",
|
||||
"Deserialization",
|
||||
"MsgId",
|
||||
"Mtp",
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import os
|
||||
import struct
|
||||
import time
|
||||
from typing import List, Optional, Tuple, Union
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
from ...crypto import AuthKey, decrypt_data_v2, encrypt_data_v2
|
||||
from ...tl.core.reader import Reader
|
||||
from ...tl.core import Reader
|
||||
from ...tl.mtproto.abcs import BadMsgNotification as AbcBadMsgNotification
|
||||
from ...tl.mtproto.abcs import DestroySessionRes
|
||||
from ...tl.mtproto.abcs import MsgDetailedInfo as AbcMsgDetailedInfo
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import re
|
||||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass
|
||||
from typing import List, NewType, Optional, Self, Tuple, Union
|
||||
from typing import List, NewType, Optional, Self, Tuple
|
||||
|
||||
from ...tl.mtproto.types import RpcError as GeneratedRpcError
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
from .abcs import Transport
|
||||
from .abcs import MissingBytes, Transport
|
||||
from .abridged import Abridged
|
||||
from .full import Full
|
||||
from .intermediate import Intermediate
|
||||
|
||||
__all__ = ["Transport"]
|
||||
__all__ = ["MissingBytes", "Transport", "Abridged", "Full", "Intermediate"]
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
from .sender import (
|
||||
MAXIMUM_DATA,
|
||||
NO_PING_DISCONNECT,
|
||||
PING_DELAY,
|
||||
Sender,
|
||||
connect,
|
||||
connect_with_auth,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"MAXIMUM_DATA",
|
||||
"NO_PING_DISCONNECT",
|
||||
"PING_DELAY",
|
||||
"Sender",
|
||||
"connect",
|
||||
"connect_with_auth",
|
||||
]
|
|
@ -6,14 +6,20 @@ from asyncio import FIRST_COMPLETED, Event, Future, StreamReader, StreamWriter
|
|||
from dataclasses import dataclass
|
||||
from typing import Generic, List, Optional, Self, TypeVar
|
||||
|
||||
from ..crypto.auth_key import AuthKey
|
||||
from ..mtproto import authentication
|
||||
from ..mtproto.mtp.encrypted import Encrypted
|
||||
from ..mtproto.mtp.plain import Plain
|
||||
from ..mtproto.mtp.types import BadMessage, MsgId, Mtp, RpcError
|
||||
from ..mtproto.transport.abcs import MissingBytes, Transport
|
||||
from ..crypto import AuthKey
|
||||
from ..mtproto import (
|
||||
BadMessage,
|
||||
Encrypted,
|
||||
MissingBytes,
|
||||
MsgId,
|
||||
Mtp,
|
||||
Plain,
|
||||
RpcError,
|
||||
Transport,
|
||||
authentication,
|
||||
)
|
||||
from ..tl import Request as RemoteCall
|
||||
from ..tl.abcs import Updates
|
||||
from ..tl.core.request import Request as RemoteCall
|
||||
from ..tl.mtproto.functions import ping_delay_disconnect
|
||||
|
||||
MAXIMUM_DATA = (1024 * 1024) + (8 * 1024)
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
from .chat import ChatHashCache, PackedChat, PackedType
|
||||
from .message_box import (
|
||||
BOT_CHANNEL_DIFF_LIMIT,
|
||||
NO_UPDATES_TIMEOUT,
|
||||
USER_CHANNEL_DIFF_LIMIT,
|
||||
ChannelState,
|
||||
DataCenter,
|
||||
Gap,
|
||||
MessageBox,
|
||||
PossibleGap,
|
||||
PrematureEndReason,
|
||||
PtsInfo,
|
||||
Session,
|
||||
State,
|
||||
UpdateState,
|
||||
User,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"ChatHashCache",
|
||||
"PackedChat",
|
||||
"PackedType",
|
||||
"BOT_CHANNEL_DIFF_LIMIT",
|
||||
"NO_UPDATES_TIMEOUT",
|
||||
"USER_CHANNEL_DIFF_LIMIT",
|
||||
"ChannelState",
|
||||
"DataCenter",
|
||||
"Gap",
|
||||
"PossibleGap",
|
||||
"PrematureEndReason",
|
||||
"PtsInfo",
|
||||
"Session",
|
||||
"State",
|
||||
"UpdateState",
|
||||
"User",
|
||||
"MessageBox",
|
||||
]
|
|
@ -2,7 +2,7 @@ import struct
|
|||
from enum import Enum
|
||||
from typing import Optional, Self
|
||||
|
||||
from telethon._impl.tl import abcs, types
|
||||
from ...tl import abcs, types
|
||||
|
||||
|
||||
class PackedType(Enum):
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
from .defs import (
|
||||
BOT_CHANNEL_DIFF_LIMIT,
|
||||
NO_UPDATES_TIMEOUT,
|
||||
USER_CHANNEL_DIFF_LIMIT,
|
||||
ChannelState,
|
||||
DataCenter,
|
||||
Gap,
|
||||
PossibleGap,
|
||||
PrematureEndReason,
|
||||
PtsInfo,
|
||||
Session,
|
||||
State,
|
||||
UpdateState,
|
||||
User,
|
||||
)
|
||||
from .messagebox import MessageBox
|
||||
|
||||
__all__ = [
|
||||
"BOT_CHANNEL_DIFF_LIMIT",
|
||||
"NO_UPDATES_TIMEOUT",
|
||||
"USER_CHANNEL_DIFF_LIMIT",
|
||||
"ChannelState",
|
||||
"DataCenter",
|
||||
"Gap",
|
||||
"PossibleGap",
|
||||
"PrematureEndReason",
|
||||
"PtsInfo",
|
||||
"Session",
|
||||
"State",
|
||||
"UpdateState",
|
||||
"User",
|
||||
"MessageBox",
|
||||
]
|
|
@ -1,7 +1,7 @@
|
|||
from typing import Optional
|
||||
|
||||
from ...tl import abcs, types
|
||||
from ..chat.hash_cache import ChatHashCache
|
||||
from ..chat import ChatHashCache
|
||||
from .defs import ENTRY_ACCOUNT, ENTRY_SECRET, NO_SEQ, Gap, PtsInfo
|
||||
|
||||
|
||||
|
|
|
@ -4,9 +4,8 @@ import logging
|
|||
import time
|
||||
from typing import Dict, List, Optional, Set, Tuple
|
||||
|
||||
from ...tl import abcs, functions, types
|
||||
from ...tl.core.request import Request
|
||||
from ..chat.hash_cache import ChatHashCache
|
||||
from ...tl import Request, abcs, functions, types
|
||||
from ..chat import ChatHashCache
|
||||
from .adaptor import adapt, pts_info_from_update
|
||||
from .defs import (
|
||||
BOT_CHANNEL_DIFF_LIMIT,
|
||||
|
|
|
@ -1,4 +1,14 @@
|
|||
from . import abcs, core, functions, mtproto, types
|
||||
from . import abcs, functions, mtproto, types
|
||||
from .core import Request
|
||||
from .layer import LAYER, TYPE_MAPPING
|
||||
|
||||
__all__ = ["abcs", "core", "functions", "mtproto", "types", "LAYER", "TYPE_MAPPING"]
|
||||
__all__ = [
|
||||
"abcs",
|
||||
"core",
|
||||
"functions",
|
||||
"mtproto",
|
||||
"types",
|
||||
"Request",
|
||||
"LAYER",
|
||||
"TYPE_MAPPING",
|
||||
]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from telethon._impl.crypto.auth_key import AuthKey
|
||||
from telethon._impl.crypto import AuthKey
|
||||
|
||||
|
||||
def get_auth_key() -> AuthKey:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from telethon._impl.crypto.auth_key import AuthKey
|
||||
from telethon._impl.crypto import AuthKey
|
||||
from telethon._impl.mtproto.authentication import (
|
||||
CreatedKey,
|
||||
_do_step1,
|
||||
|
|
|
@ -2,10 +2,8 @@ import os
|
|||
import random
|
||||
|
||||
from pytest import mark
|
||||
from telethon._impl.client.client.client import Client
|
||||
from telethon._impl.client.client.net import Config
|
||||
from telethon._impl.session.message_box.defs import Session
|
||||
from telethon._impl.tl.mtproto import functions, types
|
||||
from telethon import Client, Config, Session
|
||||
from telethon import _tl as tl
|
||||
|
||||
|
||||
@mark.api
|
||||
|
@ -27,6 +25,6 @@ async def test_ping_pong() -> None:
|
|||
assert client.connected
|
||||
|
||||
ping_id = random.randrange(-(2**63), 2**63)
|
||||
pong = await client(functions.ping(ping_id=ping_id))
|
||||
assert isinstance(pong, types.Pong)
|
||||
pong = await client(tl.mtproto.functions.ping(ping_id=ping_id))
|
||||
assert isinstance(pong, tl.mtproto.types.Pong)
|
||||
assert pong.ping_id == ping_id
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
from telethon._impl.crypto import (
|
||||
AuthKey,
|
||||
Side,
|
||||
_do_encrypt_data_v2,
|
||||
calc_key,
|
||||
decrypt_data_v2,
|
||||
decrypt_ige,
|
||||
encrypt_ige,
|
||||
generate_key_data_from_nonce,
|
||||
)
|
||||
from telethon._impl.crypto.auth_key import AuthKey
|
||||
from telethon._impl.crypto.crypto import _do_encrypt_data_v2
|
||||
|
||||
|
||||
def get_test_auth_key() -> AuthKey:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from telethon._impl.crypto.factorize import factorize
|
||||
from telethon._impl.crypto import factorize
|
||||
|
||||
|
||||
def test_factorization_1() -> None:
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import struct
|
||||
|
||||
from pytest import raises
|
||||
from telethon._impl.crypto.auth_key import AuthKey
|
||||
from telethon._impl.mtproto.mtp import Encrypted, Plain, RpcError
|
||||
from telethon._impl.crypto import AuthKey
|
||||
from telethon._impl.mtproto import Encrypted, Plain, RpcError
|
||||
from telethon._impl.tl.mtproto.types import RpcError as GeneratedRpcError
|
||||
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ import asyncio
|
|||
import logging
|
||||
|
||||
from pytest import LogCaptureFixture, mark
|
||||
from telethon._impl.mtproto.transport.full import Full
|
||||
from telethon._impl.mtsender.sender import connect
|
||||
from telethon._impl.mtproto import Full
|
||||
from telethon._impl.mtsender import connect
|
||||
from telethon._impl.tl import LAYER, abcs, functions, types
|
||||
|
||||
TELEGRAM_TEST_DC_2 = "149.154.167.40:443"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from telethon._impl.session.chat.packed import PackedChat, PackedType
|
||||
from telethon._impl.session import PackedChat, PackedType
|
||||
|
||||
|
||||
def test_hash_optional() -> None:
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import struct
|
||||
|
||||
from pytest import mark
|
||||
from telethon._impl.tl.core import Reader
|
||||
from telethon._impl.tl.core.serializable import Serializable
|
||||
from telethon._impl.tl.core import Reader, Serializable
|
||||
from telethon._impl.tl.mtproto.types import BadServerSalt
|
||||
from telethon._impl.tl.types import GeoPoint
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from typing import Tuple
|
||||
|
||||
from pytest import raises
|
||||
from telethon._impl.mtproto.transport.abridged import Abridged
|
||||
from telethon._impl.mtproto import Abridged
|
||||
|
||||
|
||||
class Output(bytearray):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from typing import Tuple
|
||||
|
||||
from pytest import raises
|
||||
from telethon._impl.mtproto.transport.full import Full
|
||||
from telethon._impl.mtproto import Full
|
||||
|
||||
|
||||
class Output(bytearray):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from typing import Tuple
|
||||
|
||||
from pytest import raises
|
||||
from telethon._impl.mtproto.transport.intermediate import Intermediate
|
||||
from telethon._impl.mtproto import Intermediate
|
||||
|
||||
|
||||
class Output(bytearray):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from pathlib import Path
|
||||
from typing import Set
|
||||
|
||||
from ..tl_parser.tl.parameter_type import NormalParameter
|
||||
from ..tl_parser import NormalParameter
|
||||
from .fakefs import FakeFs, SourceWriter
|
||||
from .loader import ParsedTl
|
||||
from .serde.common import (
|
||||
|
|
|
@ -2,7 +2,7 @@ import re
|
|||
from dataclasses import dataclass
|
||||
from typing import List, Optional
|
||||
|
||||
from ...tl_parser import Definition, FunctionDef, TypeDef, parse_tl_file
|
||||
from ..tl_parser import Definition, FunctionDef, TypeDef, parse_tl_file
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
from .tl import (
|
||||
BaseParameter,
|
||||
Definition,
|
||||
Flag,
|
||||
FlagsParameter,
|
||||
NormalParameter,
|
||||
Parameter,
|
||||
Type,
|
||||
TypeDefNotImplemented,
|
||||
)
|
||||
from .tl_iterator import FunctionDef, TypeDef
|
||||
from .tl_iterator import iterate as parse_tl_file
|
||||
|
||||
__all__ = [
|
||||
"FunctionDef",
|
||||
"TypeDef",
|
||||
"parse_tl_file",
|
||||
"Definition",
|
||||
"Flag",
|
||||
"Parameter",
|
||||
"TypeDefNotImplemented",
|
||||
"BaseParameter",
|
||||
"FlagsParameter",
|
||||
"NormalParameter",
|
||||
"Type",
|
||||
]
|
|
@ -0,0 +1,16 @@
|
|||
from .definition import Definition
|
||||
from .flag import Flag
|
||||
from .parameter import Parameter, TypeDefNotImplemented
|
||||
from .parameter_type import BaseParameter, FlagsParameter, NormalParameter
|
||||
from .ty import Type
|
||||
|
||||
__all__ = [
|
||||
"Definition",
|
||||
"Flag",
|
||||
"Parameter",
|
||||
"TypeDefNotImplemented",
|
||||
"BaseParameter",
|
||||
"FlagsParameter",
|
||||
"NormalParameter",
|
||||
"Type",
|
||||
]
|
|
@ -1,14 +1,16 @@
|
|||
from .._impl.tl_parser.tl.definition import Definition
|
||||
from .._impl.tl_parser.tl.flag import Flag
|
||||
from .._impl.tl_parser.tl.parameter import Parameter, TypeDefNotImplemented
|
||||
from .._impl.tl_parser.tl.parameter_type import (
|
||||
from .._impl.tl_parser import (
|
||||
BaseParameter,
|
||||
Definition,
|
||||
Flag,
|
||||
FlagsParameter,
|
||||
FunctionDef,
|
||||
NormalParameter,
|
||||
Parameter,
|
||||
Type,
|
||||
TypeDef,
|
||||
TypeDefNotImplemented,
|
||||
parse_tl_file,
|
||||
)
|
||||
from .._impl.tl_parser.tl.ty import Type
|
||||
from .._impl.tl_parser.tl_iterator import FunctionDef, TypeDef
|
||||
from .._impl.tl_parser.tl_iterator import iterate as parse_tl_file
|
||||
|
||||
__all__ = [
|
||||
"Definition",
|
||||
|
|
Loading…
Reference in New Issue
Block a user