L i(YddlZddlmZddlmZddlmZmZmZ ddl m Z ddl m Z m Z ddlmZddlmZdd lmZdd lmZmZmZmZd ZddlmZddlmZmZm Z ddl!m"Z"ddl#m$Z$ddl%m&Z&erddl'm(Z(edZ)edZ*GddeZ+GddeZ,GddeZ-GddeZ.Gdd eZ/Gd!d"e/Z0Gd#d$e/Z1y#e$rdZ d \Z Z ZZZd \ZZZZdZYwxYw)%N) b64decode)Sequence) TYPE_CHECKINGOptional no_type_check)default_backend)MGF1OAEP)Cipher)AES)CBC)SHA1SHA256SHA512HashT)NNNNN)NNNNF)TelegramObject)de_json_optionalde_list_optionalparse_sequence_arg) TextEncoding)JSONDict)PassportDecryptionError)Botc&ts tdttt }|j ||z|j }|dd|dd}}tt|t|t }|j}|j ||j z}ttt }|j ||j } | |k7rtd| d|||ddS) 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 0zHashes are not equal! z != r) CRYPTO_INSTALLED RuntimeErrorrrrupdatefinalizer r r decryptorrr) secrethashdatadigestsecret_hash_hashkey init_vectorcipherr# data_hashs d/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/telegram/_passport/credentials.pydecryptr.3s,  0  &(O$5 6F MM&4- (',.>rG.LC CHc+.8I JF  "I   D !I$6$6$8 8D &(O$5 6F MM$!ID%(>ykdV&TUU Q ?c|tjt|||jtj S)zPDecrypts data using secret and hash and then decodes utf-8 string and loads json)jsonloadsr.decoderUTF_8)r$r%r&s r- decrypt_jsonr5ds- ::gfdD1889K9KL MMr/c leZdZdZdZdddedededeeffd Ze d e fd Z e d d Z xZ S)EncryptedCredentialsaDContains 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;ct||||_||_||_|j|j|jf|_d|_d|_|jyNr:) super__init__r&r%r$ _id_attrsr9r8_freeze)selfr&r%r$r; __class__s r-r?zEncryptedCredentials.__init__s] J/  ! ))TYY <266: r/returnc x|jts td |jjj t |jttttd|_|jS|jS#t$r}t||d}~wwxYw)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)mgfrFlabel) r9rr get_bot private_keyr.rr$r r r ValueErrorr)rB exceptions r-decrypted_secretz%EncryptedCredentials.decrypted_secrets  ! ! )#"8 H)-)C)C)K)Kdkk*TDF3tvTR*&%%%t%%% H-i8iG HsA(B B9( B44B9c |jdtjt|jt |j t |j|j|_|jS)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. ) r8 Credentialsde_jsonr5rMrr%r&rI)rBs r-decrypted_dataz#EncryptedCredentials.decrypted_datasa    '#.#6#6T22Idii4H)TXT]T]J^_ $D ###r/)rDrO)__name__ __module__ __qualname____doc__ __slots__strrrr?propertybytesrMrQ __classcell__rCs@r-r7r7jss6I*.   X& *&%&&<$$r/r7cjeZdZdZdZdddddedeeffd Ze dd ed ed d dffd Z xZ S)rOz Attributes: secure_data (:class:`telegram.SecureData`): Credentials for encrypted data nonce (:obj:`str`): Bot-specified nonce )nonce secure_dataNr:r^ SecureDatar]r;cbt||||_||_|j yr=)r>r?r^r]rA)rBr^r]r;rCs r-r?zCredentials.__init__s- J/'2  r/r&botrrDc|j|}t|jdt||d<t|||S),See :meth:`telegram.TelegramObject.de_json`.r^r&ra) _parse_datargetr_r>rPclsr&rarCs r-rPzCredentials.de_jsonsCt$.txx /F TWX]wDc22r/N) rRrSrTrUrVrWrrr? classmethodrPrZr[s@r-rOrOsg )I*. !   X& 383(5/3]33r/rOceZdZdZdZ ddddeddeddedd edd edd edd edd eddeddeddeddeeffdZeddededddffd Z xZ 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. ) addressbank_statementdriver_license identity_cardinternal_passportpassportpassport_registrationpersonal_detailsrental_agreementtemporary_registration utility_billNr:rs SecureValuerqrprnrorlrvrmrtrrrur;c t || | |_| |_| |_||_||_||_||_||_ ||_ ||_ ||_ |jyr=)r>r?rurrrtrmrvrlrornrprqrsrA)rBrsrqrprnrorlrvrmrtrrrur;rCs r-r?zSecureData.__init__6sw J/>T#rPrgs r-rPzSecureData.de_jsonWs~t$)9 HH- . S*  %&)9 HH, -{C)  $%$4DHH=O4PR]_b#c  !1$((;K2Lk[^!_ /0H+WZ[^*488I+> SQY 0/1JKY\ ]_!1$((;K2Lk[^!_ $4 HH( );%  !,DHHZ,@+sSZ#3DHH=O4PR]_b#c  wDc22r/) NNNNNNNNNNNri) rRrSrTrUrVrrr?rjrPrZr[s@r-r_r_s"/b I 59,0592615+/0426489=:>*."=1=)$M2  !/   . -(}-!/#=1 ( 6!) 7X&B383(5/3\33r/r_ceZdZdZdZ ddddeddedd edd edd eedd eedd eeffdZe ddededddffd Z xZ S)rwa? 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_sideselfie translationNr:r&DataCredentialsr|FileCredentialsr}r~r{rr;ct||||_||_||_||_t ||_t ||_|jyr=) r>r?r&r|r}r~rr{rrA) rBr&r|r}r~r{rr;rCs r-r?zSecureValue.__init__sT J//3 5?7C17 2DU2K 8J;8W r/rarrDc|j|}t|jdt||d<t|jdt||d<t|jdt||d<t|jdt||d<t |jdt||d<t |jdt||d<t |||S)rcr&r|r}r~r{rrd)rerrfrrrr>rPrgs r-rPzSecureValue.de_jsonst$'(8/3OV -dhh|.DoWZ[\/0H/[^_^)$((8*r? _unfrozenr%r$rr,)rBr%r$r;rCs r-r?z_CredentialsBase.__init__sZ J/ ^^  ,!DI%DK#'))DN"&))DN  , , ,s 1AA% rRrSrTrUrVrWrrr?rZr[s@r-rrs;=r?rA)rBr,r$r;rCs r-r?zDataCredentials.__init__  i:N r/rr[s@r-rr6 IX\#s8HCUr/rc@eZdZdZdZdddededeeffdZxZ S) ra 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 rNr:rr$r;cJt|||||jyrr)rBrr$r;rCs r-r?zFileCredentials.__init__ rr/rr[s@r-rrrr/r)2r1base64rcollections.abcrtypingrrrcryptography.hazmat.backendsr1cryptography.hazmat.primitives.asymmetric.paddingr r &cryptography.hazmat.primitives.ciphersr 1cryptography.hazmat.primitives.ciphers.algorithmsr ,cryptography.hazmat.primitives.ciphers.modesr %cryptography.hazmat.primitives.hashesrrrrr ImportErrortelegram._telegramobjectrtelegram._utils.argumentparsingrrrtelegram._utils.stringsrtelegram._utils.typesrtelegram.errorrtelegramrr.r5r7rOr_rwrrrrr/r-rs( $99<L=E@PP4bb0*2--`NN h$>h$V3.3Bx3x3v[3.[3|,~,,&*&qO#A D$S!9D&&$ s.CC-,C-