mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-09-18 18:02:51 +03:00
Refactor AuthKey class documentation and improve key_id extraction logic
This commit is contained in:
parent
e3165bc3bf
commit
6e4ee71c32
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue
Block a user