
    f                        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Z	 ddeeej                  f   ded
eeeef      deeef   fdZdeeej                  f   deeee   f   fdZddeeej                  f   deeef   fdZg dZy)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.

key_filenamebanner
public_key
secret_keymetadataencodingreturnc           	         t        |t              r|j                  |      }t        |t              r|j                  |      }t        | dd      5 }|j	                  |j                  t        j                  j                                      |j	                  d       |rr|j                         D ]_  \  }}t        |t              r|j                  |      }t        |t              r|j                  |      }|j	                  d| d| d       a |j	                  d       |j	                  d	| d
       |r|j	                  d| d
       ddd       y# 1 sw Y   yxY w)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vs	            I/var/www/cvtools/html/venv/lib/python3.12/site-packages/zmq/auth/certs.py_write_key_filer      s0    *e$&&x0
*e$&&x0
	lC&	1 <Q	h//33567	 ( ,1a'*Aa'*A$qcQCr*+, 	
		%j\67GG)*T:;!< < <s   C?EE"key_dirnamec                 N   t        j                         \  }}t        j                  j	                  | |      }| d}| d}t
        j
                  j                         }t        |t        j                  |      |       t        |t        j                  |      |||       ||fS )zeCreate zmq certificates.

    Returns the file paths to the public and secret certificate files.
    z.key_secretz.key)r
   r   )zmqcurve_keypairospathjoinr   r   r   _cert_public_bannerr   _cert_secret_banner)	r    r!   r   r	   r
   base_filenamesecret_key_filepublic_key_filer   s	            r   create_certificatesr-   =   s     !..0J
GGLL$/M&{3O&t,O





!CO%8%?%?%DjQ""3' O++    filenamec                    d}d}t         j                  j                  |       st        d|        t	        | d      5 }|D ]  }|j                         }|j                  d      r%|j                  d      r$|j                  dd      d   j                  d      }|j                  d	      r$|j                  dd      d   j                  d      }|s|s n ddd       |t        d
|        ||fS # 1 sw Y   xY w)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   lines        r   load_certificater<   Y   s    JJ77>>(#28*=>>	h	 
 		D::<Dt$}-!ZZa0399)D
}-!ZZa0399)D
j		
 28*=>>z!!
 
s   BC5C5C55C>	directoryc                    i }t         j                  j                  |       st        d|        t         j                  j	                  | d      }t        j
                  |      }|D ]  }t        |      \  }}|sd||<    |S )z5Load public keys from all certificates in a directoryzInvalid certificate directory: z*.keyT)r%   r&   isdirr6   r'   globr<   )r=   certsglob_string
cert_files	cert_filer	   _s          r   load_certificatesrF   |   s}    E77==#7	{CDD'',,y'2K;'J %	(3
A $E*% Lr.   )r-   r<   rF   )NNzutf-8)N).)__doc__r   r@   r%   typingr   r   r   r   r#   r)   r(   strPathLiker   r   r-   r<   boolrF   __all__ r.   r   <module>rO      sf   7
   	 / / 
   /3)-<R[[()<< c5j!< sEz*+	<
 tCH~&< < 
<F *.,3#$,
, tCH~&, 38_	,8 "C$% "
5(5/!" "FsBKK'7!8 4tCT   Kr.   