
    iX                        d dl Z d dlmZ d dlmZmZmZmZmZ 	 d dl	m
Z
 d dlmZmZ d dlmZ d dlmZ d dlmZ d d	lmZmZmZmZ d
Zn# e$ r dZ
d\  ZZZZZd\  ZZZZdZY nw xY wd dlmZ d dlmZ d dlm Z  d dl!m"Z" erd dl#m$Z$ ed             Z%ed             Z& G d de          Z' G d de          Z( G d de          Z) G d de          Z* G d de          Z+ G d d e+          Z, G d! d"e+          Z-dS )#    N)	b64decode)TYPE_CHECKINGOptionalSequenceTupleno_type_check)default_backend)MGF1OAEP)Cipher)AES)CBC)SHA1SHA256SHA512HashT)NNNNN)NNNNF)TelegramObject)parse_sequence_arg)JSONDict)PassportDecryptionError)Botc                    t           st          d          t          t                      t	                                }|                    | |z              |                                }|dd         |dd         }}t          t          |          t          |          t	                                }|
                                }|                    |          |                                z   }t          t                      t	                                }|                    |           |                                }	|	|k    rt          d|	 d|           ||d         d         S )	a  
    Decrypt per telegram docs at https://core.telegram.org/passport.

    Args:
        secret (:obj:`str` or :obj:`bytes`): The encryption secret, either as bytes or as a
            base64 encoded string.
        hash (:obj:`str` or :obj:`bytes`): The hash, either as bytes or as a
            base64 encoded string.
        data (:obj:`str` or :obj:`bytes`): The data to decrypt, either as bytes or as a
            base64 encoded string.
        file (:obj:`bool`): Force data to be treated as raw data, instead of trying to
            b64decode it.

    Raises:
        :class:`PassportDecryptionError`: Given hash does not match hash of decrypted data.

    Returns:
        :obj:`bytes`: The decrypted data as bytes.

    cTo use Telegram Passports, PTB must be installed via `pip install "python-telegram-bot[passport]"`.)backendN    0   zHashes are not equal! z != r   )CRYPTO_INSTALLEDRuntimeErrorr   r   r	   updatefinalizer   r   r   	decryptorr   r   )
secrethashdatadigestsecret_hash_hashkeyinit_vectorcipherr!   	data_hashs
             d/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/telegram/_passport/credentials.pydecryptr,   1   sY   ,  
0
 
 	

 &((O$5$5666F
MM&4-   ((',.>rG|.LCCHHc+..8I8IJJJF  ""ID!!I$6$6$8$88D&((O$5$5666F
MM$!!ID%&Ty&T&Td&T&TUUUQ		?    c                 n    t          j        t          | ||                              d                    S )zPDecrypts data using secret and hash and then decodes utf-8 string and loads jsonzutf-8)jsonloadsr,   decode)r"   r#   r$   s      r+   decrypt_jsonr2   b   s.     :gfdD1188AABBBr-   c            
       ~     e Zd ZdZdZdddedededee         f fd	Ze	d
e
fd            Ze	dd            Z xZS )EncryptedCredentialsaC  Contains data required for decrypting and authenticating EncryptedPassportElement. See the
    Telegram Passport Documentation for a complete description of the data decryption and
    authentication processes.

    Objects of this class are comparable in terms of equality. Two objects of this class are
    considered equal, if their :attr:`data`, :attr:`hash` and :attr:`secret` are equal.

    Note:
        This object is decrypted only when originating from
        :obj:`telegram.PassportData.decrypted_credentials`.

    Args:
        data (:class:`telegram.Credentials` | :obj:`str`): Decrypted data with unique user's
            nonce, data hashes and secrets used for EncryptedPassportElement decryption and
            authentication or base64 encrypted data.
        hash (:obj:`str`): Base64-encoded data hash for data authentication.
        secret (:obj:`str`): Decrypted or encrypted secret used for decryption.

    Attributes:
        data (:class:`telegram.Credentials` | :obj:`str`): Decrypted data with unique user's
            nonce, data hashes and secrets used for EncryptedPassportElement decryption and
            authentication or base64 encrypted data.
        hash (:obj:`str`): Base64-encoded data hash for data authentication.
        secret (:obj:`str`): Decrypted or encrypted secret used for decryption.

    )_decrypted_data_decrypted_secretr$   r#   r"   N
api_kwargsr$   r#   r"   r8   c                    t                                          |           || _        || _        || _        | j        | j        | j        f| _        d | _        d | _        |                                  d S Nr7   )	super__init__r$   r#   r"   	_id_attrsr6   r5   _freeze)selfr$   r#   r"   r8   	__class__s        r+   r<   zEncryptedCredentials.__init__   sj     	J///		!)TY<266:r-   returnc           	         | j         t          st          d          	 |                                 j                            t          | j                  t          t          t                                t                      d                    | _         n"# t          $ r}t          |          |d}~ww xY w| j         S )z
        :obj:`bytes`: Lazily decrypt and return secret.

        Raises:
            telegram.error.PassportDecryptionError: Decryption failed. Usually due to bad
                private/public key but can also suggest malformed/tampered data.
        Nr   )	algorithm)mgfrC   label)r6   r   r   get_botprivate_keyr,   r   r"   r   r
   r   
ValueErrorr   )r?   	exceptions     r+   decrypted_secretz%EncryptedCredentials.decrypted_secret   s     !)# "8  H)-)C)K)Kdk**TDFF333tvvTRRR* *&&  H H H-i88iGH %%s   A:B 
B9$B44B9Credentialsc           	          | j         jt                              t          | j        t          | j                  t          | j                            |                                           | _         | j         S )a~  
        :class:`telegram.Credentials`: Lazily decrypt and return credentials data. This object
            also contains the user specified nonce as
            `decrypted_data.nonce`.

        Raises:
            telegram.error.PassportDecryptionError: Decryption failed. Usually due to bad
                private/public key but can also suggest malformed/tampered data.
        )	r5   rK   de_jsonr2   rJ   r   r#   r$   rF   )r?   s    r+   decrypted_dataz#EncryptedCredentials.decrypted_data   sc     '#.#6#6T2Idi4H4H)TXT]J^J^__$ $D  ##r-   )rA   rK   )__name__
__module____qualname____doc__	__slots__strr   r   r<   propertybytesrJ   rN   __classcell__r@   s   @r+   r4   r4   h   s         6I *.    	 X&     * &% & & & X&< $ $ $ X$ $ $ $ $r-   r4   c                        e Zd ZdZdZdddddedee         f fd	Ze	d
ee         ddded          f fd            Z
 xZS )rK   z
    Attributes:
        secure_data (:class:`telegram.SecureData`): Credentials for encrypted data
        nonce (:obj:`str`): Bot-specified nonce
    )noncesecure_dataNr7   r[   
SecureDatarZ   r8   c                    t                                          |           || _        || _        |                                  d S r:   )r;   r<   r[   rZ   r>   )r?   r[   rZ   r8   r@   s       r+   r<   zCredentials.__init__   s@     	J///'2
r-   r$   botr   rA   c                     |                      |          }|sdS t                              |                    d          |          |d<   t	                                          ||          S ),See :meth:`telegram.TelegramObject.de_json`.Nr[   r^   r$   r^   )_parse_datar\   rM   getr;   clsr$   r^   r@   s      r+   rM   zCredentials.de_json   sf     t$$ 	4(00-1H1Hc0RR]wwDc222r-   )rO   rP   rQ   rR   rS   rT   r   r   r<   classmethodrM   rW   rX   s   @r+   rK   rK      s          )I *.  ! 
 X&      	38H- 	3E 	3h}>U 	3 	3 	3 	3 	3 [	3 	3 	3 	3 	3r-   rK   c                   F    e Zd ZdZdZ	 	 	 	 	 	 	 	 	 	 	 dddded         ded         ded         d	ed         d
ed         ded         ded         ded         ded         ded         ded         dee         f fdZedee         ddded          f fd            Z	 xZ
S )r\   a  
    This object represents the credentials that were used to decrypt the encrypted data.
    All fields are optional and depend on fields that were requested.

    Args:
        personal_details (:class:`telegram.SecureValue`, optional): Credentials for encrypted
            personal details.
        passport (:class:`telegram.SecureValue`, optional): Credentials for encrypted passport.
        internal_passport (:class:`telegram.SecureValue`, optional): Credentials for encrypted
            internal passport.
        driver_license (:class:`telegram.SecureValue`, optional): Credentials for encrypted
            driver license.
        identity_card (:class:`telegram.SecureValue`, optional): Credentials for encrypted ID card
        address (:class:`telegram.SecureValue`, optional): Credentials for encrypted
            residential address.
        utility_bill (:class:`telegram.SecureValue`, optional): Credentials for encrypted
            utility bill.
        bank_statement (:class:`telegram.SecureValue`, optional): Credentials for encrypted
            bank statement.
        rental_agreement (:class:`telegram.SecureValue`, optional): Credentials for encrypted
            rental agreement.
        passport_registration (:class:`telegram.SecureValue`, optional): Credentials for encrypted
            registration from internal passport.
        temporary_registration (:class:`telegram.SecureValue`, optional): Credentials for encrypted
            temporary registration.

    Attributes:
        personal_details (:class:`telegram.SecureValue`): Optional. Credentials for encrypted
            personal details.
        passport (:class:`telegram.SecureValue`): Optional. Credentials for encrypted passport.
        internal_passport (:class:`telegram.SecureValue`): Optional. Credentials for encrypted
            internal passport.
        driver_license (:class:`telegram.SecureValue`): Optional. Credentials for encrypted
            driver license.
        identity_card (:class:`telegram.SecureValue`): Optional. Credentials for encrypted ID card
        address (:class:`telegram.SecureValue`): Optional. Credentials for encrypted
            residential address.
        utility_bill (:class:`telegram.SecureValue`): Optional. Credentials for encrypted
            utility bill.
        bank_statement (:class:`telegram.SecureValue`): Optional. Credentials for encrypted
            bank statement.
        rental_agreement (:class:`telegram.SecureValue`): Optional. Credentials for encrypted
            rental agreement.
        passport_registration (:class:`telegram.SecureValue`): Optional. Credentials for encrypted
            registration from internal passport.
        temporary_registration (:class:`telegram.SecureValue`): Optional. Credentials for encrypted
            temporary registration.
    )addressbank_statementdriver_licenseidentity_cardinternal_passportpassportpassport_registrationpersonal_detailsrental_agreementtemporary_registrationutility_billNr7   rp   SecureValuern   rm   rk   rl   ri   rs   rj   rq   ro   rr   r8   c                   t                                          |           || _        |
| _        |	| _        || _        || _        || _        || _        || _	        || _
        || _        || _        |                                  d S r:   )r;   r<   rr   ro   rq   rj   rs   ri   rl   rk   rm   rn   rp   r>   )r?   rp   rn   rm   rk   rl   ri   rs   rj   rq   ro   rr   r8   r@   s                r+   r<   zSecureData.__init__7  s      	J/// >T#<Q"7G5C3?.54A5C8I/77Gr-   r$   r^   r   rA   c                    |                      |          }|sdS t                              |                    d          |          |d<   t                              |                    d          |          |d<   t                              |                    d          |          |d<   t                              |                    d          |          |d<   t                              |                    d          |          |d<   t                              |                    d          |          |d<   t                              |                    d	          |          |d	<   t                              |                    d
          |          |d
<   t                              |                    d          |          |d<   t                              |                    d          |          |d<   t                              |                    d          |          |d<   t	                                          ||          S )r`   Nrr   ra   ro   rq   rj   rs   ri   rl   rk   rm   rn   rp   rb   )rc   rt   rM   rd   r;   re   s      r+   rM   zSecureData.de_jsonX  s&    t$$ 	4)4)<)<HH-..C *= *
 *
%& )4(;(;HH,--3 )< )
 )
$% $/#6#6txx@R7S7SY\#6#]#] !,!4!4TXX>N5O5OUX!4!Y!Y*22488N3K3KQT2UU^%--dhhy.A.As-KKY + 3 3DHH_4M4MSV 3 W W_!,!4!4TXX>N5O5OUX!4!Y!Y$/$7$7AT8U8U[^$7$_$_ !&..txx
/C/C.MMZ#.#6#6txx@R7S7SY\#6#]#] wwDc222r-   )NNNNNNNNNNN)rO   rP   rQ   rR   rS   r   r   r<   rg   rM   rW   rX   s   @r+   r\   r\      s       / /bI  59,0592615+/0426489=:> *.  "=1 =) $M2	
 !/  . -( }- !/ #=1  (6 !) 7 X&     B 38H- 3E 3h|>T 3 3 3 3 3 [3 3 3 3 3r-   r\   c                       e Zd ZdZdZ	 	 	 	 	 	 dddded         ded         d	ed         d
ed         deed                  deed                  dee         f fdZe	dee         ddded          f fd            Z
 xZS )rt   a?  
    This object represents the credentials that were used to decrypt the encrypted value.
    All fields are optional and depend on the type of field.

    Args:
        data (:class:`telegram.DataCredentials`, optional): Credentials for encrypted Telegram
            Passport data. Available for "personal_details", "passport", "driver_license",
            "identity_card", "identity_passport" and "address" types.
        front_side (:class:`telegram.FileCredentials`, optional): Credentials for encrypted
            document's front side. Available for "passport", "driver_license", "identity_card"
            and "internal_passport".
        reverse_side (:class:`telegram.FileCredentials`, optional): Credentials for encrypted
            document's reverse side. Available for "driver_license" and "identity_card".
        selfie (:class:`telegram.FileCredentials`, optional): Credentials for encrypted selfie
            of the user with a document. Can be available for "passport", "driver_license",
            "identity_card" and "internal_passport".
        translation (List[:class:`telegram.FileCredentials`], optional): Credentials for an
            encrypted translation of the document. Available for "passport", "driver_license",
            "identity_card", "internal_passport", "utility_bill", "bank_statement",
            "rental_agreement", "passport_registration" and "temporary_registration".
        files (List[:class:`telegram.FileCredentials`], optional): Credentials for encrypted
            files. Available for "utility_bill", "bank_statement", "rental_agreement",
            "passport_registration" and "temporary_registration" types.

    Attributes:
        data (:class:`telegram.DataCredentials`): Optional. Credentials for encrypted Telegram
            Passport data. Available for "personal_details", "passport", "driver_license",
            "identity_card", "identity_passport" and "address" types.
        front_side (:class:`telegram.FileCredentials`): Optional. Credentials for encrypted
            document's front side. Available for "passport", "driver_license", "identity_card"
            and "internal_passport".
        reverse_side (:class:`telegram.FileCredentials`): Optional. Credentials for encrypted
            document's reverse side. Available for "driver_license" and "identity_card".
        selfie (:class:`telegram.FileCredentials`): Optional. Credentials for encrypted selfie
            of the user with a document. Can be available for "passport", "driver_license",
            "identity_card" and "internal_passport".
        translation (Tuple[:class:`telegram.FileCredentials`]): Optional. Credentials for an
            encrypted translation of the document. Available for "passport", "driver_license",
            "identity_card", "internal_passport", "utility_bill", "bank_statement",
            "rental_agreement", "passport_registration" and "temporary_registration".

            .. versionchanged:: 20.0
                |tupleclassattrs|

        files (Tuple[:class:`telegram.FileCredentials`]): Optional. Credentials for encrypted
            files. Available for "utility_bill", "bank_statement", "rental_agreement",
            "passport_registration" and "temporary_registration" types.

            .. versionchanged:: 20.0

                * |tupleclassattrs|
                * |alwaystuple|

    )r$   files
front_sidereverse_sideselfietranslationNr7   r$   DataCredentialsry   FileCredentialsrz   r{   rx   r|   r8   c                    t                                          |           || _        || _        || _        || _        t          |          | _        t          |          | _        | 	                                 d S r:   )
r;   r<   r$   ry   rz   r{   r   rx   r|   r>   )	r?   r$   ry   rz   r{   rx   r|   r8   r@   s	           r+   r<   zSecureValue.__init__  sm     	J////3	5?7C172DU2K2K
8J;8W8Wr-   r^   r   rA   c                    |                      |          }|sdS t                              |                    d          |          |d<   t                              |                    d          |          |d<   t                              |                    d          |          |d<   t                              |                    d          |          |d<   t                              |                    d          |          |d<   t                              |                    d          |          |d<   t                                          ||	          S )
r`   Nr$   ra   ry   rz   r{   rx   r|   rb   )rc   r}   rM   rd   r~   de_listr;   re   s      r+   rM   zSecureValue.de_json  s3    t$$ 	4&..txx/?/?S.IIV,44TXXl5K5KQT4UU\.66txx7O7OUX6YY^(00(1C1C0MMX'//0A0As/KKW-55dhh}6M6MSV5WW]wwDc222r-   )NNNNNN)rO   rP   rQ   rR   rS   r   r   r   r<   rg   rM   rW   rX   s   @r+   rt   rt   s  s8       5 5n YI -12648.27;=A *.  () ./ 01	
 *+ !234 h'89: X&     * 38H- 3E 3h}>U 3 3 3 3 3 [3 3 3 3 3r-   rt   c                   F     e Zd ZdZdZdddededee         f fdZ xZ	S )	_CredentialsBasez3Base class for DataCredentials and FileCredentials.)r*   	file_hashr#   r"   Nr7   r#   r"   r8   c                    t                                          |           |                                 5  || _        || _        | j        | _        | j        | _        d d d            d S # 1 swxY w Y   d S r:   )r;   r<   	_unfrozenr#   r"   r   r*   )r?   r#   r"   r8   r@   s       r+   r<   z_CredentialsBase.__init__  s     	J///^^ 	, 	,!DI%DK #')DN"&)DN	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s   'A,,A03A0
rO   rP   rQ   rR   rS   rT   r   r   r<   rW   rX   s   @r+   r   r     sx        ==<I *., , ,, ,
 X&, , , , , , , , , ,r-   r   c                   F     e Zd ZdZdZdddededee         f fdZ xZ	S )	r}   al  
    These credentials can be used to decrypt encrypted data from the data field in
    EncryptedPassportData.

    Args:
        data_hash (:obj:`str`): Checksum of encrypted data
        secret (:obj:`str`): Secret of encrypted data

    Attributes:
        hash (:obj:`str`): Checksum of encrypted data
        secret (:obj:`str`): Secret of encrypted data
     Nr7   r*   r"   r8   c                x    t                                          |||           |                                  d S N)r#   r"   r8   r;   r<   r>   )r?   r*   r"   r8   r@   s       r+   r<   zDataCredentials.__init__  3    i:NNNr-   r   rX   s   @r+   r}   r}     u          IX\   # s 8HCU          r-   r}   c                   F     e Zd ZdZdZdddededee         f fdZ xZ	S )	r~   a  
    These credentials can be used to decrypt encrypted files from the front_side,
    reverse_side, selfie and files fields in EncryptedPassportData.

    Args:
        file_hash (:obj:`str`): Checksum of encrypted file
        secret (:obj:`str`): Secret of encrypted file

    Attributes:
        hash (:obj:`str`): Checksum of encrypted file
        secret (:obj:`str`): Secret of encrypted file
    r   Nr7   r   r"   r8   c                x    t                                          |||           |                                  d S r   r   )r?   r   r"   r8   r@   s       r+   r<   zFileCredentials.__init__  r   r-   r   rX   s   @r+   r~   r~     r   r-   r~   ).r/   base64r   typingr   r   r   r   r   cryptography.hazmat.backendsr	   1cryptography.hazmat.primitives.asymmetric.paddingr
   r   &cryptography.hazmat.primitives.ciphersr   1cryptography.hazmat.primitives.ciphers.algorithmsr   ,cryptography.hazmat.primitives.ciphers.modesr   %cryptography.hazmat.primitives.hashesr   r   r   r   r   ImportErrortelegram._telegramobjectr   telegram._utils.argumentparsingr   telegram._utils.typesr   telegram.errorr   telegramr   r,   r2   r4   rK   r\   rt   r   r}   r~   r   r-   r+   <module>r      s  (        J J J J J J J J J J J J J J<<<<<<LLLLLLLL======EEEEEE@@@@@@PPPPPPPPPPPP   O#A D$S!9D&&$ 4 3 3 3 3 3 > > > > > > * * * * * * 2 2 2 2 2 2  - - -` C C C
h$ h$ h$ h$ h$> h$ h$ h$V!3 !3 !3 !3 !3. !3 !3 !3Hy3 y3 y3 y3 y3 y3 y3 y3x^3 ^3 ^3 ^3 ^3. ^3 ^3 ^3B, , , , ,~ , , ,,    &   *    &     s   .A	 	A$#A$