U
    luf&  ã                   @   s^   d Z ddlmZmZmZ ddlmZ ddlmZ dd„ Z	dd	„ Z
d
d„ Zdd„ Zdd	dgZdS )z miscellaneous zmq_utils wrappingé    )ÚInterruptedSystemCallÚ	_check_rcÚ_check_versioné   )Úffi)Úlibc                 C   s,   t ddƒ t| tƒr|  d¡} tt | ¡ƒS )zxCheck for zmq capability by name (e.g. 'ipc', 'curve')

    .. versionadded:: libzmq-4.1
    .. versionadded:: 14.1
    )é   r   zzmq.hasÚutf8)r   Ú
isinstanceÚstrÚencodeÚboolÚCZzmq_has)Z
capability© r   ú:/tmp/pip-unpacked-wheel-h6ekxre8/zmq/backend/cffi/utils.pyÚhas   s    


r   c                  C   sV   t ddƒ t d¡} t d¡}t | |¡}t|ƒ t | ¡dd… t |¡dd… fS )u  generate a Z85 key pair for use with zmq.CURVE security

    Requires libzmq (â‰¥ 4.0) to have been built with CURVE support.

    Returns
    -------
    (public, secret) : two bytestrings
        The public and private key pair as 40 byte z85-encoded bytestrings.
    )é   é   Úcurve_keypairúchar[64]Né(   )r   r   Únewr   Zzmq_curve_keypairr   Úbuffer)ÚpublicÚprivateÚrcr   r   r   r      s    



r   c                 C   sN   t | tƒr|  d¡} tddƒ t d¡}t || ¡}t|ƒ t 	|¡dd… S )un  Compute the public key corresponding to a private key for use
    with zmq.CURVE security

    Requires libzmq (â‰¥ 4.2) to have been built with CURVE support.

    Parameters
    ----------
    private
        The private key as a 40 byte z85-encoded bytestring
    Returns
    -------
    bytestring
        The public key as a 40 byte z85-encoded bytestring.
    r	   )r   r   Úcurve_publicr   Nr   )
r
   r   r   r   r   r   r   Zzmq_curve_publicr   r   )r   r   r   r   r   r   r   *   s    



r   c                 O   s6   | |Ž }zt |ƒ W q2 tk
r,   Y q Y q X q2q dS )z/make a call, retrying if interrupted with EINTRN)r   r   )ÚfÚargsÚkwargsr   r   r   r   Ú_retry_sys_callB   s    
r    N)Ú__doc__Z	zmq.errorr   r   r   Z_cffir   r   r   r   r   r   r    Ú__all__r   r   r   r   Ú<module>   s   