Ë
    S"“j  ã                   ó`   — d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
 ddlmZ  G d„ d	«      Zy
)z3
This module holds the CdnDecrypter utility class.
é    )Úsha256é   )ÚGetCdnFileRequestÚReuploadCdnFileRequest)ÚCdnFileReuploadNeededÚCdnFile)Ú
AESModeCTR)ÚCdnFileTamperedErrorc                   ó<   — e Zd ZdZd„ Zed„ «       Zd„ Zed„ «       Zy)ÚCdnDecrypterzÕ
    Used when downloading a file results in a 'FileCdnRedirect' to
    both prepare the redirect, decrypt the file as it downloads, and
    ensure the file hasn't been tampered. https://core.telegram.org/cdn
    c                 ó<   — || _         || _        || _        || _        y)a.  
        Initializes the CDN decrypter.

        :param cdn_client: a client connected to a CDN.
        :param file_token: the token of the file to be used.
        :param cdn_aes: the AES CTR used to decrypt the file.
        :param cdn_file_hashes: the hashes the decrypted file must match.
        N)ÚclientÚ
file_tokenÚcdn_aesÚcdn_file_hashes)ÚselfÚ
cdn_clientr   r   r   s        ú]/var/www/api.ozpay.ru/ozpay/venv/lib/python3.12/site-packages/telethon/crypto/cdndecrypter.pyÚ__init__zCdnDecrypter.__init__   s!   € ð !ˆŒØ$ˆŒØˆŒØ.ˆÕó    c              ƒ   óÎ  K  — t        |j                  |j                  dd t        d«      z   ¬«      }t	        ||j
                  ||j                  «      } |t        |j
                  |j                  d   j                  |j                  d   j                  ¬«      «      ƒ d{  –—† }t        |t        «      rC | t        |j
                  |j                  ¬«      «      ƒ d{  –—†  |j                  «       }||fS |j                  j!                  |j                  «      |_        |j                  j#                  d«      }|j%                  |j                  |«       ||fS 7 Œ¼7 Œ­w)a9  
        Prepares a new CDN decrypter.

        :param client: a TelegramClient connected to the main servers.
        :param cdn_client: a new client connected to the CDN.
        :param cdn_redirect: the redirect file object that caused this call.
        :return: (CdnDecrypter, first chunk file data)
        Né   é   )ÚkeyÚivr   )r   ÚoffsetÚlimit)r   Úrequest_token)r	   Úencryption_keyÚencryption_ivÚbytesr   r   r   r   r   r   Ú
isinstancer   r   r   Úget_filer   ÚencryptÚpopÚcheck)r   r   Úcdn_redirectr   Ú	decrypterÚcdn_fileÚcdn_hashs          r   Úprepare_decrypterzCdnDecrypter.prepare_decrypter    sR  è ø€ ô Ø×+Ñ+à×)Ñ)¨#¨2Ð.´°q³Ñ9ô
ˆô !Ø˜×/Ñ/Ø�\×1Ñ1ó
ˆ	ñ
 $Ô$5Ø#×.Ñ.Ø×/Ñ/°Ñ2×9Ñ9Ø×.Ñ.¨qÑ1×7Ñ7ô%
ó ÷ ˆô
 �hÔ 5Ô6áÔ/Ø'×2Ñ2Ø&×4Ñ4ôó ÷ ð ð !×)Ñ)Ó+ˆHð ˜(Ð"Ð"ð	 '×.Ñ.×6Ñ6°x·~±~ÓFˆHŒNØ ×0Ñ0×4Ñ4°QÓ7ˆHØ�O‰O˜HŸN™N¨HÔ5à˜(Ð"Ð"ð'øðús%   ‚B"E%Â$E!Â%>E%Ã#E#Ã$A>E%Å#E%c                 ó€  — | j                   r�| j                   j                  d«      }| j                  t        | j                  |j
                  |j                  «      «      }| j                  j                  |j                  «      |_	        | j                  |j                  |«       |S t        t        d«      «      }|S )z 
        Calls GetCdnFileRequest and decrypts its bytes.
        Also ensures that the file hasn't been tampered.

        :return: the CdnFile result.
        r   )r   r%   r   r   r   r   r   r   r$   r!   r&   r   )r   r*   r)   s      r   r#   zCdnDecrypter.get_fileL   s–   € ð ×ÒØ×+Ñ+×/Ñ/°Ó2ˆHØ—{‘{Ô#4Ø—‘ §¡°(·.±.ó$ó ˆHð "Ÿ\™\×1Ñ1°(·.±.ÓAˆHŒNØ�J‰J�x—~‘~ xÔ0ð ˆô œu Q›xÓ(ˆHàˆr   c                 ód   — t        | «      j                  «       |j                  k7  r
t        «       ‚y)zÔ
        Checks the integrity of the given data.
        Raises CdnFileTamperedError if the integrity check fails.

        :param data: the data to be hashed.
        :param cdn_hash: the expected hash.
        N)r   ÚdigestÚhashr
   )Údatar*   s     r   r&   zCdnDecrypter.check_   s+   € ô �$‹<×ÑÓ  H§M¡MÒ1Ü&Ó(Ð(ð 2r   N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ústaticmethodr+   r#   r&   © r   r   r   r      s:   „ ñò
/ð ñ)#ó ð)#òVð& ñ	)ó ñ	)r   r   N)r4   Úhashlibr   Útl.functions.uploadr   r   Útl.types.uploadr   r   Úcryptor	   Úerrorsr
   r   r6   r   r   ú<module>r<      s'   ðñõ ç Kß <Ý Ý )÷])ò ])r   