
    ,h}                         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y)encodedecode    N)
a2b_base64
b2a_base64hexlify	unhexlify)MD5)padunpad)DESDES3AES)PBKDF1)get_random_bytes)tobytestostrc                 D   |t         }d|z  }|r |d      }t        ||ddt              }|t        ||z   |ddt              z  }t        j                  |t        j
                  |      }|dt        t        |      j                               z  z  }|j                  t        | |j                              } n|t        d      t        dt        |       d      D cg c]  }t        t        | ||dz                 }	}|d	j!                  |	      z  }|d
|z  z  }|S c c}w )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
    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
             O/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/Crypto/IO/PEM.pyr   r   /   s+   0 #
 6
)C{Zr1c2vcJ&aC88#t}}d3F'$-%%'() 	) ~~c$(9(9:;		)**
 QD	2.0 JtAa"f~./ 0F 02776?C&&CJ	0s   !Dc                     dg}|dz   dz  }t        |      D ]?  }t        j                  |d   | z   |z         j                         }|j	                  |       A dj                  |      d | S )N       r   )r   r	   r   digestappendr!   )r"   r'   key_lendm_nds          r,   _EVP_BytesToKeyr8   a   sp    
A	22A1X WWQrUT\D()002	 88A;x  r.   c                 ^   t        j                  d      }|j                  |       }|st        d      |j	                  d      }t        j                  d      }|j                  |       }|r|j	                  d      |k7  rt        d      | j                  dd      j                         }t        |      dk  rt        d	      |d   j                  d
      r|st        d      |d   j                  d      }t        |      dk7  s|d   dk7  rt        d      |d   j                  d      \  }}t        t        |            }d}	|dk(  r4t        ||d      }
t        j                  |
t        j                  |      }nD|dk(  r4t        ||d      }
t!        j                  |
t         j                  |      }n|dk(  r6t        ||dd d      }
t#        j                  |
t"        j                  |      }n|dk(  r6t        ||dd d      }
t#        j                  |
t"        j                  |      }n|dk(  r6t        ||dd d      }
t#        j                  |
t"        j                  |      }nZ|j%                         dk(  r9t        ||dd d      }
t#        j                  |
t"        j&                  |      }d}	nt        d |z        |dd }nd}t)        dj+                  |dd!             }d}|r;	r&t-        |j/                  |      |j0                        }n|j/                  |      }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%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LMMAhnnS!s8q=CFj0CDDV\\#&
d'9!*dA6CWWS#,,5F^#!*dB7CXXc4==$7F]"!*d2Ah;CWWS#,,5F]"!*d2Ah;CWWS#,,5F]"!*d2Ah;CWWS#,,5FZZ\_,!*d2Ah;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.   