U
    h_                     @   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	   ;/tmp/pip-unpacked-wheel-c81u5j2r/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| rH|j |j|j  | _ | _| _d S || _ tt| j  ,}|jdd| _|	d |jdd| _W 5 Q R X d S )NFsigned   )
r   aux_hashZkey_id
isinstancetyper   r   digestZ	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   Z	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   