
    YiY                        S SK r S SKJr  S SKJr  S SKJrJrJr   S SK	J
r
  S SKJrJr  S SKJr  S SKJr  S S	KJr  S S
KJrJrJrJr  SrS SKJr  S SKJr  S SKJ r   S SK!J"r"  S SK#J$r$  \(       a  S SK%J&r&  \S 5       r'\S 5       r( " S S\5      r) " S S\5      r* " S S\5      r+ " S S\5      r, " S S \5      r- " S! S"\-5      r. " S# S$\-5      r/g! \ a    Sr
Su  rrrrrSu  rrrrSr Nf = f)%    N)	b64decode)Sequence)TYPE_CHECKINGOptionalno_type_check)default_backend)MGF1OAEP)Cipher)AES)CBC)SHA1SHA256SHA512HashT)NNNNN)NNNNF)TelegramObject)parse_sequence_arg)TextEncoding)JSONDict)PassportDecryptionError)Botc                    [         (       d  [        S5      e[        [        5       [	        5       S9nUR                  X-   5        UR                  5       nUSS USS pe[        [        U5      [        U5      [	        5       S9nUR                  5       nUR                  U5      UR                  5       -   n[        [        5       [	        5       S9nUR                  U5        UR                  5       n	X:w  a  [        SU	 SU 35      eX"S   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
             I/app/.venv/lib/python3.13/site-packages/telegram/_passport/credentials.pydecryptr,   3   s    , 0
 	

 &(O$56F
MM&- (',.>rG.LCHc+.8IJF  "ID!I$6$6$88D&(O$56F
MM$!I%(>ykdV&TUUQ	?    c                 |    [         R                  " [        XU5      R                  [        R
                  5      5      $ )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_jsonr3   d   s+     ::gfD1889K9KLMMr-   c            
       ~   ^  \ rS rSrSrSrSS.S\S\S\S	\\   4U 4S
 jjjr	\
S\4S j5       r\
SS j5       rSrU =r$ )EncryptedCredentialsj   a  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U ]  US9  Xl        X l        X0l        U R                  U R                  U R                  4U l        S U l        S U l        U R                  5         g Nr9   )	super__init__r$   r#   r"   	_id_attrsr8   r7   _freeze)selfr$   r#   r"   r:   	__class__s        r+   r>   EncryptedCredentials.__init__   sW     	J/		!))TYY<266:r-   returnc           	      z   U R                   c  [        (       d  [        S5      e U R                  5       R                  R                  [        U R                  5      [        [        [        5       S9[        5       SS95      U l         U R                   $ U R                   $ ! [         a  n[        U5      UeSnAff = f)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)mgfrF   label)r8   r   r   get_botprivate_keyr,   r   r"   r
   r	   r   
ValueErrorr   )rA   	exceptions     r+   decrypted_secret%EncryptedCredentials.decrypted_secret   s     !!)##"8 H)-)C)C)K)Kdkk*TDF3tvTR*& %%%t%%%  H-i8iGHs   A"B 
B:)B55B:c           	          U R                   cd  [        R                  [        U R                  [        U R                  5      [        U R                  5      5      U R                  5       5      U l         U R                   $ )aF  
: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_jsonr3   rM   r   r#   r$   rI   )rA   s    r+   decrypted_data#EncryptedCredentials.decrypted_data   sa     '#.#6#6T22Idii4H)TXT]T]J^_$D  ###r-   )r7   r8   r?   r$   r#   r"   )rD   rP   )__name__
__module____qualname____firstlineno____doc__	__slots__strr   r   r>   propertybytesrM   rR   __static_attributes____classcell__rB   s   @r+   r5   r5   j   sx    6I *.  	 X& * &% & &< $ $r-   r5   c            	          ^  \ rS rSrSrSrSS.SSS\S	\\   4U 4S
 jjjr	\
 SS\\   S\S   S\S    4U 4S jjj5       rSrU =r$ )rP      z
Attributes:
    secure_data (:class:`telegram.SecureData`): Credentials for encrypted data
    nonce (:obj:`str`): Bot-specified nonce
)noncesecure_dataNr9   rc   
SecureDatarb   r:   c                X   > [         TU ]  US9  Xl        X l        U R	                  5         g r<   )r=   r>   rc   rb   r@   )rA   rc   rb   r:   rB   s       r+   r>   Credentials.__init__   s)     	J/'2
r-   r$   botr   rD   c                    > U R                  U5      nU(       d  g[        R                  UR                  S5      US9US'   [        TU ]	  XS9$ ),See :meth:`telegram.TelegramObject.de_json`.Nrc   rg   r$   rg   )_parse_datard   rQ   getr=   clsr$   rg   rB   s      r+   rQ   Credentials.de_json   sM    
 t$(00-1Hc0R]wD22r-   N)rT   rU   rV   rW   rX   rY   rZ   r   r   r>   classmethodrQ   r]   r^   r_   s   @r+   rP   rP      s|     )I *.! 
 X&  >B3H%3,4UO3	-	 3 3r-   rP   c                     ^  \ rS rSrSrSr           SSS.S\S   S\S   S	\S   S
\S   S\S   S\S   S\S   S\S   S\S   S\S   S\S   S\\   4U 4S jjjjr\	 SS\\   S\S   S\S    4U 4S jjj5       r
SrU =r$ )rd      aj
  
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   r|   SecureValuerz   ry   rw   rx   ru   r   rv   r}   r{   r~   r:   c                   > [         TU ]  US9  Xl        Xl        Xl        Xl        Xpl        X`l        XPl        X@l	        X0l
        X l        Xl        U R                  5         g r<   )r=   r>   r~   r{   r}   rv   r   ru   rx   rw   ry   rz   r|   r@   )rA   r|   rz   ry   rw   rx   ru   r   rv   r}   r{   r~   r:   rB   s                r+   r>   SecureData.__init__;  sa      	J/ >T#<Q"7G5C3?.54A5C8I/77Gr-   r$   rg   r   rD   c                   > U R                  U5      nU(       d  g[        R                  UR                  S5      US9US'   [        R                  UR                  S5      US9US'   [        R                  UR                  S5      US9US'   [        R                  UR                  S5      US9US'   [        R                  UR                  S5      US9US'   [        R                  UR                  S5      US9US'   [        R                  UR                  S	5      US9US	'   [        R                  UR                  S
5      US9US
'   [        R                  UR                  S5      US9US'   [        R                  UR                  S5      US9US'   [        R                  UR                  S5      US9US'   [        TU ]	  XS9$ )ri   Nr~   rj   r{   r}   rv   r   ru   rx   rw   ry   rz   r|   rk   )rl   r   rQ   rm   r=   rn   s      r+   rQ   SecureData.de_json\  s   
 t$)4)<)<HH-.C *= *
%& )4(;(;HH,-3 )< )
$% $/#6#6txx@R7SY\#6#] !,!4!4TXX>N5OUX!4!Y*22488N3KQT2U^%--dhhy.As-KY + 3 3DHH_4MSV 3 W_!,!4!4TXX>N5OUX!4!Y$/$7$7AT8U[^$7$_ !&..txx
/C.MZ#.#6#6txx@R7SY\#6#] wD22r-   )NNNNNNNNNNNrq   )rT   rU   rV   rW   rX   rY   r   r   r>   rr   rQ   r]   r^   r_   s   @r+   rd   rd      s7   /bI  59,0592615+/0426489=:> *."=1 =) $M2	
 !/  . -( }- !/ #=1  (6 !) 7 X& B >B3H%3,4UO3	,	3 3r-   rd   c                      ^  \ rS rSrSrSr      SSS.S\S   S\S	   S
\S	   S\S	   S\\S	      S\\S	      S\\   4U 4S jjjjr	\
 SS\\   S\S   S\S    4U 4S jjj5       rSrU =r$ )r   iy  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$   DataCredentialsr   FileCredentialsr   r   r   r   r:   c                   > [         TU ]  US9  Xl        X l        X0l        X@l        [        U5      U l        [        U5      U l        U R                  5         g r<   )
r=   r>   r$   r   r   r   r   r   r   r@   )	rA   r$   r   r   r   r   r   r:   rB   s	           r+   r>   SecureValue.__init__  sL     	J//3	5?7C172DU2K
8J;8Wr-   rg   r   rD   c                   > U R                  U5      nU(       d  g[        R                  UR                  S5      US9US'   [        R                  UR                  S5      US9US'   [        R                  UR                  S5      US9US'   [        R                  UR                  S5      US9US'   [        R                  UR                  S5      US9US'   [        R                  UR                  S5      US9US'   [        TU ]	  XS	9$ )
ri   Nr$   rj   r   r   r   r   r   rk   )rl   r   rQ   rm   r   de_listr=   rn   s      r+   rQ   SecureValue.de_json  s    
 t$&..txx/?S.IV,44TXXl5KQT4U\.66txx7OUX6Y^(00(1C0MX'//0As/KW-55dhh}6MSV5W]wD22r-   )NNNNNNrq   )rT   rU   rV   rW   rX   rY   r   r   r   r>   rr   rQ   r]   r^   r_   s   @r+   r   r   y  s    5n YI -12648.27;=A *.() ./ 01	
 *+ !234 h'89: X& * >B3H%3,4UO3	-	 3 3r-   r   c                   N   ^  \ rS rSrSrSrSS.S\S\S\\   4U 4S	 jjjr	Sr
U =r$ )
_CredentialsBasei  z3Base class for DataCredentials and FileCredentials.)r*   	file_hashr#   r"   Nr9   r#   r"   r:   c                   > [         TU ]  US9  U R                  5          Xl        X l        U R                  U l        U R                  U l        S S S 5        g ! , (       d  f       g = fr<   )r=   r>   	_unfrozenr#   r"   r   r*   )rA   r#   r"   r:   rB   s       r+   r>   _CredentialsBase.__init__  sM     	J/^^!I%K #'))DN"&))DN s   /A
A%rT   rU   rV   rW   rX   rY   rZ   r   r   r>   r]   r^   r_   s   @r+   r   r     s;    =<I *.,, ,
 X&, ,r-   r   c                   N   ^  \ rS rSrSrSrSS.S\S\S\\   4U 4S	 jjjr	Sr
U =r$ )
r   i  aH  
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                B   > [         TU ]  XUS9  U R                  5         g N)r#   r"   r:   r=   r>   r@   )rA   r*   r"   r:   rB   s       r+   r>   DataCredentials.__init__      i:Nr-   r   r_   s   @r+   r   r     6     IX\ # s 8HCU  r-   r   c                   N   ^  \ rS rSrSrSrSS.S\S\S\\   4U 4S	 jjjr	Sr
U =r$ )
r   i  ap  
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                B   > [         TU ]  XUS9  U R                  5         g r   r   )rA   r   r"   r:   rB   s       r+   r>   FileCredentials.__init__  r   r-   r   r_   s   @r+   r   r     r   r-   r   )0r/   base64r   collections.abcr   typingr   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.stringsr   telegram._utils.typesr   telegram.errorr   telegramr   r,   r3   r5   rP   rd   r   r   r   r   r   r-   r+   <module>r      s  (   $ 9 9<L=E@PP 4 > 0 * 2 - -` N N
h$> h$V#3. #3L{3 {3|`3. `3F,~ ,,& *& K  O#A D$S!9D&&$s   .C C/.C/