File: //lib64/python3.6/site-packages/zmq/auth/__pycache__/certs.cpython-36.opt-1.pyc
3
VS�_S � @ s� d Z ddlZddlZddlZddlZddlZddlmZmZm Z m
Z
e
d�Ze
d�Zddd�Z
dd d
�Zdd� Zddd�Zd
ddgZdS )z10MQ authentication related functions and classes.� N)�bytes�unicode�b�uz�# **** Generated on {0} by pyzmq ****
# ZeroMQ CURVE **Secret** Certificate
# DO NOT PROVIDE THIS FILE TO OTHER USERS nor change its permissions.
a
# **** Generated on {0} by pyzmq ****
# ZeroMQ CURVE Public Certificate
# Exchange securely, or use a secure mechanism to verify the contents
# of this file after exchange. Store public certificates in your home
# directory, in the .curve subdirectory.
�utf-8c C s� t |t�r|j|�}t |t�r(|j|�}tj| ddd���}|j|jtjj� �� |jt d�� |r�xR|j
� D ]F\}}t |t�r�|j|�}t |t�r�|j|�}|jt d�j||�� qlW |jt d�� |jt d�j|�� |r�|jt d�j|�� W d Q R X d S )
zCreate a certificate file�w�utf8)�encodingz metadata
z {0} = {1}
zcurve
z public-key = "{0}"
z secret-key = "{0}"
N)�
isinstancer �decode�io�open�write�format�datetime�nowr �items) Zkey_filenameZbanner�
public_key�
secret_key�metadatar �f�k�v� r �/usr/lib64/python3.6/certs.py�_write_key_file s$
r c C sj t j� \}}tjj| |�}dj|�}dj|�}tjj� }t|t j|�|� t|t
j|�|||d� ||fS )ziCreate zmq certificates.
Returns the file paths to the public and secret certificate files.
z{0}.key_secretz{0}.key)r r )�zmqZ
curve_keypair�os�path�joinr r r r �_cert_public_banner�_cert_secret_banner) Zkey_dir�namer r r �
base_filenameZsecret_key_fileZpublic_key_filer r r r �create_certificates6 s
r$ c C s� d}d}t jj| �s"tdj| ���t| d��r}xj|D ]b}|j� }|jd�rLq4|jd�rl|jdd�d jd�}|jd �r�|jdd�d jd�}|r4|r4P q4W W dQ R X |dkr�t d
| ��||fS )a Load public and secret key from a zmq certificate.
Returns (public_key, secret_key)
If the certificate file only contains the public key,
secret_key will be None.
If there is no public key found in the file, ValueError will be raised.
NzInvalid certificate file: {0}�rb� #s
public-key� =� s '"s
secret-keyzNo public key found in %s)
r r �exists�IOErrorr r
�strip�
startswith�split�
ValueError)�filenamer r r �liner r r �load_certificateN s$
r1 �.c C s` i }t jj| �stdj| ���t jj| d�}tj|�}x$|D ]}t|�\}}|r<d||<