File: //home/arjun/projects/env/lib/python3.10/site-packages/Crypto/IO/__pycache__/PEM.cpython-310.pyc
o
we$ � @ s� d dgZ ddlZddlmZmZmZmZ ddlmZ ddl m
Z
mZ ddlm
Z
mZmZ ddlmZ dd lmZ dd
lmZmZ ddd �Zdd
� Zddd�ZdS )�encode�decode� N)�
a2b_base64�
b2a_base64�hexlify� unhexlify)�MD5)�pad�unpad)�DES�DES3�AES)�PBKDF1)�get_random_bytes)�tobytes�tostrc s� |du rt }d| }|rB|d�}t||ddt�}|t|| |ddt�7 }t�|tj|�}|dtt|��� � 7 }|� t
� |j��� n|durJtd��� fdd �t
d
t� �d�D �}|d�|�7 }|d
| 7 }|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
zEmpty passwordc s$ g | ]}t t� ||d � ���qS )�0 )r r )�.0�i��data� �F/home/arjun/projects/env/lib/python3.10/site-packages/Crypto/IO/PEM.py�
<listcomp>Z s �zencode.<locals>.<listcomp>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�chunksr r r r / s( �
�c C sV dg}|d d }t |�D ]}t�|d | | ��� }|�|� q
d�|�d |� S )N� � r ���)r$ r r �digest�appendr&