mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-09-19 02:12:40 +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
|
@dataclass
|
||||||
class AuthKey:
|
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
|
data: bytes
|
||||||
aux_hash: bytes
|
aux_hash: bytes
|
||||||
key_id: bytes
|
key_id: bytes
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_bytes(cls, data: bytes) -> Self:
|
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()
|
sha = sha1(data).digest()
|
||||||
aux_hash = sha[:8]
|
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)
|
return cls(data=data, aux_hash=aux_hash, key_id=key_id)
|
||||||
|
|
||||||
def __bytes__(self) -> bytes:
|
def __bytes__(self) -> bytes:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user