Refactor AuthKey class documentation and improve key_id extraction logic

This commit is contained in:
Jahongir Qurbonov 2025-09-12 16:33:53 +05:00
parent e3165bc3bf
commit 6e4ee71c32
No known key found for this signature in database
GPG Key ID: 256976CED13D5F2D

View File

@ -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: