
    'iX                        d dl Z d dlmZ d dlmZ d dl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d dlmZ d dlmZmZ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.      Z0y# e$ r dZ	d\  ZZZZZd\  ZZZZdZY w xY w)%    N)	b64decode)Sequence)TYPE_CHECKINGno_type_check)default_backend)MGF1OAEP)Cipher)AES)CBC)SHA1SHA256SHA512HashT)NNNNN)NNNNF)TelegramObject)de_json_optionalde_list_optionalparse_sequence_arg)TextEncoding)JSONDict)PassportDecryptionError)Botc                 &   t         st        d      t        t               t	                     }|j                  | |z          |j                         }|dd |dd }}t        t        |      t        |      t	                     }|j                         }|j                  |      |j                         z   }t        t               t	                     }|j                  |       |j                         }	|	|k7  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
             h/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/telegram/_passport/credentials.pydecryptr-   3   s   , 0
 	

 &(O$56F
MM&4- (',.>rG.LCCHc+.8IJF  "ID!I$6$6$88D&(O$56F
MM$!ID%(>ykdV&TUUQ	?    c                 |    t        j                  t        | ||      j                  t        j
                              S )zPDecrypts data using secret and hash and then decodes utf-8 string and loads json)jsonloadsr-   decoder   UTF_8)r#   r$   r%   s      r,   decrypt_jsonr4   d   s-     ::gfdD1889K9KLMMr.   c            
       l     e Zd ZdZdZdddededededz  f fd	Zed
e	fd       Z
edd       Z xZS )EncryptedCredentialsaD  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
        :attr:`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#   r:   c                    t         |   |       || _        || _        || _        | j                  | j                  | j                  f| _        d | _        d | _        | j                          y Nr9   )	super__init__r%   r$   r#   	_id_attrsr8   r7   _freeze)selfr%   r$   r#   r:   	__class__s        r,   r>   zEncryptedCredentials.__init__   s]     	J/		!))TYY</337r.   returnc           	      x   | j                   t        st        d      	 | j                         j                  j                  t        | j                        t        t        t                     t               d            | _         | j                   S | j                   S # t        $ r}t        |      |d}~ww xY w)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)mgfrE   label)r8   r   r   get_botprivate_keyr-   r   r#   r	   r   r   
ValueErrorr   )rA   	exceptions     r,   decrypted_secretz%EncryptedCredentials.decrypted_secret   s     !!)#"8 H)-)C)C)K)Kdkk*TDF3tvTR*& %%%t%%%  H-i8iGHs   A(B 	B9(B44B9c           	          | j                   dt        j                  t        | j                  t        | j                        t        | j                              | 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.
        )	r7   Credentialsde_jsonr4   rL   r   r$   r%   rH   )rA   s    r,   decrypted_dataz#EncryptedCredentials.decrypted_data   sa     '#.#6#6T22Idii4H)TXT]T]J^_$D  ###r.   )rC   rN   )__name__
__module____qualname____doc__	__slots__strr   r>   propertybytesrL   rP   __classcell__rB   s   @r,   r6   r6   j   sr    6I '+  	 tO* &% & &< $ $r.   r6   c                   d     e Zd ZdZdZdddddededz  f fd	Zedd
edddd f fd       Z	 xZ
S )rN   z
    Attributes:
        secure_data (:class:`telegram.SecureData`): Credentials for encrypted data
        nonce (:obj:`str`): Bot-specified nonce
    )noncesecure_dataNr9   r]   
SecureDatar\   r:   c                b    t         |   |       || _        || _        | j	                          y r<   )r=   r>   r]   r\   r@   )rA   r]   r\   r:   rB   s       r,   r>   zCredentials.__init__   s-     	J/'2
r.   r%   bot
Bot | NonerC   c                     | j                  |      }t        |j                  d      t        |      |d<   t        |   ||      S ),See :meth:`telegram.TelegramObject.de_json`.r]   r%   r`   )_parse_datar   getr^   r=   rO   clsr%   r`   rB   s      r,   rO   zCredentials.de_json   sC     t$.txx/F
TWX]wDc22r.   N)rQ   rR   rS   rT   rU   rV   r   r>   classmethodrO   rY   rZ   s   @r,   rN   rN      sb     )I '+! 
 tO 38 3, 3- 3 3r.   rN   c                        e Zd ZdZdZ	 	 	 	 	 	 	 	 	 	 	 dddddddddd	dd
ddddddddddddddedz  f fdZeddeddd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_billNr9   rs   zSecureValue | Nonerq   rp   rn   ro   rl   rv   rm   rt   rr   ru   r:   c                    t         |   |       || _        |
| _        |	| _        || _        || _        || _        || _        || _	        || _
        || _        || _        | j                          y r<   )r=   r>   ru   rr   rt   rm   rv   rl   ro   rn   rp   rq   rs   r@   )rA   rs   rq   rp   rn   ro   rl   rv   rm   rt   rr   ru   r:   rB   s                r,   r>   zSecureData.__init__6  sw      	J/ ;Q#9N"4D2@0<+21>2@5F,44Dr.   r%   r`   ra   rC   c                 J   | j                  |      }t        |j                  d      t        |      |d<   t        |j                  d      t        |      |d<   t        |j                  d      t        |      |d<   t        |j                  d      t        |      |d<   t        |j                  d      t        |      |d<   t        |j                  d      t        |      |d<   t        |j                  d      t        |      |d<   t        |j                  d      t        |      |d<   t        |j                  d	      t        |      |d	<   t        |j                  d
      t        |      |d
<   t        |j                  d      t        |      |d<   t        |   ||      S )rc   ru   rr   rt   rm   rv   rl   ro   rn   rp   rq   rs   rd   )re   r   rf   SecureValuer=   rO   rg   s      r,   rO   zSecureData.de_jsonW  s~    t$)9HH-.S*
%& )9HH,-{C)
$% $4DHH=O4PR]_b#c !1$((;K2Lk[^!_/0H+WZ[^*488I+>SQY 0/1JKY\ ]_!1$((;K2Lk[^!_$4HH();%
 ! ,DHHZ,@+sSZ#3DHH=O4PR]_b#c wDc22r.   )NNNNNNNNNNNri   )
rQ   rR   rS   rT   rU   r   r>   rj   rO   rY   rZ   s   @r,   r^   r^      s    /bI  26)-26/3.2(,-1/3156:7; '+. ' 0	
 - , & + - /  4 !5 tOB 38 3, 3, 3 3r.   r^   c                        e Zd ZdZdZ	 	 	 	 	 	 dddddddd	dd
dded   dz  ded   dz  dedz  f fdZeddedddd f fd       Z	 xZ
S )ry   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translationNr9   r%   zDataCredentials | Noner|   zFileCredentials | Noner}   r~   r{   FileCredentialsr   r:   c                    t         |   |       || _        || _        || _        || _        t        |      | _        t        |      | _        | j                          y r<   )
r=   r>   r%   r|   r}   r~   r   r{   r   r@   )	rA   r%   r|   r}   r~   r{   r   r:   rB   s	           r,   r>   zSecureValue.__init__  sT     	J/,0	2<4@.42DU2K
8J;8Wr.   r`   ra   rC   c                    | j                  |      }t        |j                  d      t        |      |d<   t        |j                  d      t        |      |d<   t        |j                  d      t        |      |d<   t        |j                  d      t        |      |d<   t        |j                  d      t        |      |d<   t        |j                  d      t        |      |d<   t        |   ||      S )rc   r%   r|   r}   r~   r{   r   rd   )re   r   rf   DataCredentialsr   r   r=   rO   rg   s      r,   rO   zSecureValue.de_json  s     t$'(8/3OV-dhh|.DoWZ[\/0H/[^_^)$((8*<osSX('):OSQW.txx/FY\]]wDc22r.   )NNNNNNri   )rQ   rR   rS   rT   rU   r   r   r>   rj   rO   rY   rZ   s   @r,   ry   ry   q  s    5n YI *./315+/48:> '+& - /	
 ) )*T1 /047 tO* 38 3, 3- 3 3r.   ry   c                   @     e Zd ZdZdZdddedededz  f fdZ xZS )	_CredentialsBasez3Base class for DataCredentials and FileCredentials.)r+   	file_hashr$   r#   Nr9   r$   r#   r:   c                    t         |   |       | j                         5  || _        || _        | j                  | _        | j                  | _        d d d        y # 1 sw Y   y xY wr<   )r=   r>   	_unfrozenr$   r#   r   r+   )rA   r$   r#   r:   rB   s       r,   r>   z_CredentialsBase.__init__  sZ     	J/^^ 	,!DI%DK #'))DN"&))DN	, 	, 	,s   1AA%	rQ   rR   rS   rT   rU   rV   r   r>   rY   rZ   s   @r,   r   r     s:    =<I '+,, ,
 tO, ,r.   r   c                   @     e Zd ZdZdZdddedededz  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
     Nr9   r+   r#   r:   c                J    t         |   |||       | j                          y N)r$   r#   r:   r=   r>   r@   )rA   r+   r#   r:   rB   s       r,   r>   zDataCredentials.__init__       i:Nr.   r   rZ   s   @r,   r   r     5     IUY # s 8d?  r.   r   c                   @     e Zd ZdZdZdddedededz  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   Nr9   r   r#   r:   c                J    t         |   |||       | j                          y r   r   )rA   r   r#   r:   rB   s       r,   r>   zFileCredentials.__init__
  r   r.   r   rZ   s   @r,   r   r     r   r.   r   )1r0   base64r   collections.abcr   typingr   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   r   r   telegram._utils.stringsr   telegram._utils.typesr   telegram.errorr   telegramr   r-   r4   r6   rN   r^   ry   r   r   r   r   r.   r,   <module>r      s  (   $ /<L=E@PP 4 b b 0 * 2 - -` N N
h$> h$V3. 3Bx3 x3v[3. [3|,~ ,,& *& q  O#A D$S!9D&&$s   .C C+*C+