3
uQh_                 @   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-build-2nz6shyl/telethon/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 ,}|jdd| _|j	d |jdd| _W d 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jd|| j }tjt|j 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.
            littleT)r   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 )N)boolr   )r   r	   r	   r
   __bool__;   s    zAuthKey.__bool__c             C   s   t |t| o|j| jkS )N)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   