File: //lib/python3/dist-packages/rsa/__pycache__/pem.cpython-38.pyc
U
+�[�
� @ s8 d Z ddlZddlmZmZ dd� Zdd� Zdd � ZdS )
z0Functions that load and write PEM-encoded files.� N)�is_bytes�rangec C s* t | �s| �d�} d| d d| d fS )z:
Returns the start and end PEM markers, as bytes.
�asciis -----BEGIN s -----s -----END )r �encode)�
pem_marker� r �)/usr/lib/python3/dist-packages/rsa/pem.py�_markers s
�r c C s� t | �s| �d�} t|�\}}g }d}| �� D ]^}|�� }|s@q.||kr^|rXtd| ��d}q.|sdq.|rx||krxd} q�d|kr�q.|�|� q.|s�td| ��|r�td| ��d�|�}t� |�S ) a� Loads a PEM file.
:param contents: the contents of the file to interpret
:param pem_marker: the marker of the PEM content, such as 'RSA PRIVATE KEY'
when your file has '-----BEGIN RSA PRIVATE KEY-----' and
'-----END RSA PRIVATE KEY-----' markers.
:return: the base64-decoded content between the start and end markers.
@raise ValueError: when the content is invalid, for example when the start
marker cannot be found.
r FzSeen start marker "%s" twiceT� :zNo PEM start marker "%s" foundzNo PEM end marker "%s" found� )
r r r �
splitlines�strip�
ValueError�append�join�base64Zstandard_b64decode)�contentsr � pem_start�pem_end� pem_linesZin_pem_part�lineZpemr r r �load_pem$ s8
r c C sr t |�\}}t�| ��dd�}|g}tdt|�d�D ]}|||d � }|�|� q4|�|� |�d� d�|�S )aj Saves a PEM file.
:param contents: the contents to encode in PEM format
:param pem_marker: the marker of the PEM content, such as 'RSA PRIVATE KEY'
when your file has '-----BEGIN RSA PRIVATE KEY-----' and
'-----END RSA PRIVATE KEY-----' markers.
:return: the base64-encoded content between the start and end markers, as bytes.
�
r r �@ )r r Zstandard_b64encode�replacer �lenr r )r r r r Zb64r Zblock_start�blockr r r �save_pemf s
r )�__doc__r Zrsa._compatr r r r r r r r r �<module> s
B