o
    Zh                     @   s2  d Z ddlZddlZddlZddlmZmZmZmZ ddl	Z	dZ
dZ			ddeeejf ded	eeef d
eeeef  deeeef  deddfddZ	ddeeejf dedeeeef  deeef fddZdeeejf deeee f fddZddeeejf deeef fddZg dZdS )z10MQ authentication related functions and classes.    N)DictOptionalTupleUnionz#   ****  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-8key_filenamebanner
public_key
secret_keymetadataencodingreturnc           	   	   C   s  t |tr
||}t |tr||}t| ddde}||tj  |d |rW| D ]$\}}t |tr@||}t |trJ||}|d| d| d q2|d |d	| d
 |rx|d| d
 W d   dS W d   dS 1 sw   Y  dS )zCreate a certificate filewutf8)r   z	metadata
z    z = 
zcurve
z    public-key = "z"
z    secret-key = "N)	
isinstancebytesdecodeopenwriteformatdatetimenowitems)	r   r   r	   r
   r   r   fkv r   E/var/www/html/lang_env/lib/python3.10/site-packages/zmq/auth/certs.py_write_key_file   s*   
	








"r   key_dirnamec           	      C   sj   t  \}}tj| |}| d}| d}tj }t|t	|| t|t
	||||d ||fS )zeCreate zmq certificates.

    Returns the file paths to the public and secret certificate files.
    z.key_secretz.key)r
   r   )zmqZcurve_keypairospathjoinr   r   r   _cert_public_bannerr   _cert_secret_banner)	r    r!   r   r	   r
   base_filenameZsecret_key_fileZpublic_key_filer   r   r   r   create_certificates=   s   	


r)   filenamec                 C   s   d}d}t j| std|  t| d=}|D ]2}| }|dr%q|dr5|ddd d}|d	rE|ddd d}|rK|rK nqW d   n1 sVw   Y  |du rftd
|  ||fS )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.
    NzInvalid certificate file: rb   #s
   public-key   =   s    	'"s
   secret-keyzNo public key found in )	r#   r$   existsOSErrorr   strip
startswithsplit
ValueError)r*   r	   r
   r   liner   r   r   load_certificateY   s(   


r6   .	directoryc                 C   s\   i }t j| std|  t j| d}t|}|D ]}t|\}}|r+d||< q|S )z5Load public keys from all certificates in a directoryzInvalid certificate directory: z*.keyT)r#   r$   isdirr0   r%   globr6   )r8   certsZglob_stringZ
cert_files	cert_filer	   _r   r   r   load_certificates|   s   
r>   )r)   r6   r>   )NNr   )N)r7   )__doc__r   r:   r#   typingr   r   r   r   r"   r'   r&   strPathLiker   r   r)   r6   boolr>   __all__r   r   r   r   <module>   sV    

#


&#