diff --git a/client/src/telethon/_impl/crypto/auth_key.py b/client/src/telethon/_impl/crypto/auth_key.py index 90afc306..efdc0155 100644 --- a/client/src/telethon/_impl/crypto/auth_key.py +++ b/client/src/telethon/_impl/crypto/auth_key.py @@ -6,15 +6,26 @@ from typing_extensions import Self @dataclass class AuthKey: + """Represents a Telegram's authorization key. + + To generate a new, valid authorization key, one should use the methods + provided by the generation module. + + Authorization key: https://core.telegram.org/mtproto/auth_key + """ + data: bytes aux_hash: bytes key_id: bytes @classmethod def from_bytes(cls, data: bytes) -> Self: + if len(data) != 256: + raise ValueError("Auth key data must be exactly 256 bytes") + sha = sha1(data).digest() aux_hash = sha[:8] - key_id = sha[12:] + key_id = sha[12:20] return cls(data=data, aux_hash=aux_hash, key_id=key_id) def __bytes__(self) -> bytes: