
    ¿ig<                         d dgZ ddlZddl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mZmZ ddlmZ dd	lmZ dd
lmZmZ ddZd ZddZdS )encodedecode    N)
a2b_base64
b2a_base64hexlify	unhexlify)MD5)padunpad)DESDES3AES)PBKDF1)get_random_bytes)tobytestostrc                 Z    |t           }d|z  }|r |d          }t          ||ddt                    }|t          ||z   |ddt                    z  }t          j        |t          j        |          }|dt          t          |                                                    z  z  }|	                    t           |j                             n|t          d           fdt          d	t                     d
          D             }|d                    |          z  }|d|z  z  }|S )a4  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
    Nz-----BEGIN %s-----
         z2Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,%s

zEmpty passwordc           
      ^    g | ])}t          t          ||d z                                *S )0   )r   r   ).0idatas     M/var/www/html/afkarena/venv/lib/python3.11/site-packages/Cryptodome/IO/PEM.py
<listcomp>zencode.<locals>.<listcomp>Z   sE     0 0 0 JtAa"fH~..// 0 0 0    r   r    z-----END %s-----)r   r   r	   r   newMODE_CBCr   r   upperencryptr
   
block_size
ValueErrorrangelenjoin)	r   marker
passphraserandfuncoutsaltkeyobjencchunkss	   `        r   r   r   /   sA   0 #
 6
)C +x{{Zr1c22vcJ&aC888#t}d33F'$--%%''(() 	) ~~c$(9::;;		)***0 0 0 0QD		2..0 0 0F2776??C&&CJr   c                    dg}|dz   dz  }t          |          D ]I}t          j        |d         | z   |z                                             }|                    |           Jd                    |          d |         S )Nr      r   )r&   r	   r    digestappendr(   )r   r-   key_lendm_nds          r   _EVP_BytesToKeyr;   a   s~    
A	22A1XX  WQrUT\D())0022	88A;;xx  r   c                 0   t          j        d          }|                    |           }|st          d          |                    d          }t          j        d          }|                    |           }|r|                    d          |k    rt          d          |                     dd                                          }|d                             d          r:|st          d	          |d
                             d          }t          |          d
k    s|d         dk    rt          d          |d                             d          \  }}t          t          |                    }d}	|dk    r3t          ||d          }
t          j        |
t          j        |          }n`|dk    r3t          ||d          }
t!          j        |
t           j        |          }n'|dk    r:t          ||dd         d          }
t#          j        |
t"          j        |          }n|dk    r:t          ||dd         d          }
t#          j        |
t"          j        |          }n|dk    r:t          ||dd         d          }
t#          j        |
t"          j        |          }ng|                                dk    r=t          ||dd         d          }
t#          j        |
t"          j        |          }d}	nt          d|z            |d
d         }nd}t)          d                    |dd                             }d}|rB|	r)t-          |                    |          |j                  }n|                    |          }d}|||fS ) 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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).r3   )recompilematchr%   groupsearchreplacesplit
startswithr'   r   r   r;   r   r    r!   r   r   lowerMODE_GCMr   r(   r   decryptr$   )pem_datar*   rr8   r)   linesDEKalgor-   paddingr.   objdecr   enc_flags                 r   r   r   j   sj   ( 	
011A	A 97888WWQZZF 	
,--A	A :

f$$8999 S"%%++--E Qx233 " 	NLMMMAhnnS!!s88q==CFj00CDDDV\\#&&
d''9!*dA66CWS#,55FF^##!*dB77CXc4=$77FF]""!*d2A2h;;CWS#,55FF]""!*d2A2h;;CWS#,55FF]""!*d2A2h;;CWS#,55FFZZ\\_,,!*d2A2h;;CWS#,d;;;FGGG$NOOOabb	 bggeAbDk**++DH  	(--v/@AADD >>$''D&(##r   )NN)N)__all__rD   binasciir   r   r   r   Cryptodome.Hashr	   Cryptodome.Util.Paddingr
   r   Cryptodome.Cipherr   r   r   Cryptodome.Protocol.KDFr   Cryptodome.Randomr   Cryptodome.Util.py3compatr   r   r   r;   r    r   r   <module>r`      s  D X
 				 ? ? ? ? ? ? ? ? ? ? ? ?       . . . . . . . . , , , , , , , , , , * * * * * * . . . . . . 4 4 4 4 4 4 4 4/ / / /d! ! !S$ S$ S$ S$ S$ S$r   