o
    Xzj_  ã                   @   s6   d Z ddlZddlmZ ddlmZ G dd„ dƒZdS )z&
This module holds the AuthKey class.
é    N)Úsha1é   )ÚBinaryReaderc                   @   sJ   e Zd ZdZdd„ Zedd„ ƒZejdd„ ƒZdd„ Zd	d
„ Z	dd„ Z
dS )ÚAuthKeyzt
    Represents an authorization key, used to encrypt and decrypt
    messages sent to Telegram's data centers.
    c                 C   s
   || _ dS )z|
        Initializes a new authorization key.

        :param data: the data in bytes that represent this auth key.
        N)Úkey)ÚselfÚdata© r	   úR/var/www/kodo/tsheker/venv/lib/python3.10/site-packages/telethon/crypto/authkey.pyÚ__init__   s   
zAuthKey.__init__c                 C   s   | j S ©N)Ú_key©r   r	   r	   r
   r      s   zAuthKey.keyc                 C   s¬   |sd  | _  | _| _d S t|t| ƒƒr$|j |j|j| _ | _| _d S || _ tt| j ƒ ¡ ƒ�}|jdd�| _| 	d¡ |jdd�| _W d   ƒ d S 1 sOw   Y  d S )NF©Úsignedé   )
r   Úaux_hashÚkey_idÚ
isinstanceÚtyper   r   ÚdigestÚ	read_longÚread)r   ÚvalueÚreaderr	   r	   r
   r      s   ÿ
"ýc                 C   sD   |j dddd�}|t d|| j¡ }tjt|ƒ ¡ dd… ddd�S )zô
        Calculates the new nonce hash based on the current attributes.

        :param new_nonce: the new nonce to be hashed.
        :param number: number to prepend before the hash.
        :return: the hash for the given new nonce.
        é    ÚlittleTr   z<BQr   é   )Úto_bytesÚstructÚpackr   ÚintÚ
from_bytesr   r   )r   Ú	new_nonceÚnumberr   r	   r	   r
   Úcalc_new_nonce_hash-   s    zAuthKey.calc_new_nonce_hashc                 C   s
   t | jƒS r   )Úboolr   r   r	   r	   r
   Ú__bool__;   s   
zAuthKey.__bool__c                 C   s   t |t| ƒƒo|j| jkS r   )r   r   r   r   )r   Úotherr	   r	   r
   Ú__eq__>   s   zAuthKey.__eq__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   Úsetterr%   r'   r)   r	   r	   r	   r
   r   
   s    

r   )r-   r   Úhashlibr   Ú
extensionsr   r   r	   r	   r	   r
   Ú<module>   s
    