
    5i}                         S S/r SSKrSSKJrJrJrJr  SSKJr  SSK	J
r
Jr  SSKJrJrJr  SSKJr  SS	KJr  SS
KJrJr  SS jrS rSS jrg)encodedecode    N)
a2b_base64
b2a_base64hexlify	unhexlify)MD5)padunpad)DESDES3AES)PBKDF1)get_random_bytes)tobytestostrc                 R   Uc  [         nSU-  nU(       a  U" S5      n[        X%SS[        5      nU[        Xb-   USS[        5      -  n[        R                  " U[        R
                  U5      nUS[        [        U5      R                  5       5      -  -  nUR                  [        XR                  5      5      n OUb  [        S5      e[        S[        U 5      S5       Vs/ s H  n[        [        XUS-    5      5      PM     n	nUS	R!                  U	5      -  nUS
U-  -  nU$ s  snf )a  Encode a piece of binary data into PEM format.

Args:
  data (byte string):
    The piece of binary data to encode.
  marker (string):
    The marker for the PEM block (e.g. "PUBLIC KEY").
    Note that there is no official master list for all allowed markers.
    Still, you can refer to the OpenSSL_ source code.
  passphrase (byte string):
    If given, the PEM block will be encrypted. The key is derived from
    the passphrase.
  randfunc (callable):
    Random number generation function; it accepts an integer N and returns
    a byte string of random data, N bytes long. If not given, a new one is
    instantiated.

Returns:
  The PEM block, as a string.

.. _OpenSSL: https://github.com/openssl/openssl/blob/master/include/openssl/pem.h
z-----BEGIN %s-----
         z2Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,%s

zEmpty passwordr   0    z-----END %s-----)r   r   r	   r   newMODE_CBCr   r   upperencryptr
   
block_size
ValueErrorrangelenr   join)
datamarker
passphraserandfuncoutsaltkeyobjencichunkss
             [/var/www/html/BTCUSD/btcusdt_trading_app/venv/lib/python3.13/site-packages/Crypto/IO/PEM.pyr   r   /   s&   0 #
 6
)C{Zr1c2vc&aC88#t}}d3F'$-%%'() 	) ~~c$(9(9:;		)**
 QD	2.0.! Jta"f~./.  02776?C&&CJ	0s   !#D$c                     S/nUS-   S-  n[        U5       HA  n[        R                  " US   U -   U-   5      R                  5       nUR	                  U5        MC     SR                  U5      S U $ )N       r   )r   r	   r   digestappendr!   )r"   r'   key_lendm_nds          r,   _EVP_BytesToKeyr8   a   sk    
A	22A1XWWQrUT\D()002	  88A;x  r.   c                    [         R                  " S5      nUR                  U 5      nU(       d  [        S5      eUR	                  S5      n[         R                  " S5      nUR                  U 5      nU(       a  UR	                  S5      U:w  a  [        S5      eU R                  SS5      R                  5       n[        U5      S:  a  [        S	5      eUS   R                  S
5      (       Ga  U(       d  [        S5      eUS   R                  S5      n[        U5      S:w  d	  US   S:w  a  [        S5      eUS   R                  S5      u  px[        [        U5      5      nSn	US:X  a4  [        XS5      n
[        R                  " U
[        R                  U5      nGOFUS:X  a4  [        XS5      n
[         R                  " U
[         R                  U5      nGOUS:X  a6  [        XSS S5      n
["        R                  " U
["        R                  U5      nOUS:X  a6  [        XSS S5      n
["        R                  " U
["        R                  U5      nOUS:X  a6  [        XSS S5      n
["        R                  " U
["        R                  U5      nOXUR%                  5       S:X  a6  [        XSS S5      n
["        R                  " U
["        R&                  US9nSn	O[        S U-  5      eUSS nOSn[)        SR+                  USS! 5      5      nSnU(       a@  W	(       a&  [-        UR/                  U5      UR0                  5      nOUR/                  U5      nSnXU4$ )"a  Decode a PEM block into binary.

Args:
  pem_data (string):
    The PEM block.
  passphrase (byte string):
    If given and the PEM block is encrypted,
    the key will be derived from the passphrase.

Returns:
  A tuple with the binary data, the marker string, and a boolean to
  indicate if decryption was performed.

Raises:
  ValueError: if decoding fails, if the PEM file is encrypted and no passphrase has
              been provided or if the passphrase is incorrect.
z\s*-----BEGIN (.*)-----\s+zNot a valid PEM pre boundaryr   z-----END (.*)-----\s*$zNot a valid PEM post boundary r      z%A PEM file must have at least 3 lineszProc-Type:4,ENCRYPTEDz-PEM is encrypted, but no passphrase available   :r   zDEK-Infoz$PEM encryption format not supported.,TzDES-CBCr   zDES-EDE3-CBC   zAES-128-CBCNr   zAES-192-CBCzAES-256-CBC    zid-aes256-gcm)nonceFz(Unsupport PEM encryption algorithm (%s).r0   )recompilematchr   groupsearchreplacesplitr    
startswithr   r   r8   r   r   r   r   r   lowerMODE_GCMr   r!   r   decryptr   )pem_datar$   rr5   r#   linesDEKalgor'   paddingr(   objdecr"   enc_flags                 r,   r   r   j   s   ( 	

01A	A788WWQZF 	

,-A	A
f$899 S"%++-E
5zA~@AA Qx233LMMAhnnS!s8q=CFj0CDDV\\#&
'9!*A6CWWS#,,5F^#!*B7CXXc4==$7F]"!*2Ah;CWWS#,,5F]"!*2Ah;CWWS#,,5F]"!*2Ah;CWWS#,,5FZZ\_,!*2Ah;CWWS#,,d;FGG$NOOab	 bggeAbk*+DH-v/@/@AD >>$'D(##r.   )NN)N)__all__rB   binasciir   r   r   r   Crypto.Hashr	   Crypto.Util.Paddingr
   r   Crypto.Cipherr   r   r   Crypto.Protocol.KDFr   Crypto.Randomr   Crypto.Util.py3compatr   r   r   r8   r    r.   r,   <module>r^      sA   D X
 	 ? ?  * ( ( & * 0/d!U$r.   