o
    9F9`	                     @   s   d Z ddlZddlmZ ddlZddlZdededdfddZ	ded	edefd
dZ
dgZedkr^ed ddlZedD ]Ze \ZZerI ned dkrWerWede  q=ed dS dS )zFunctions for parallel computation on multiple cores.

Introduced in Python-RSA 3.1.

.. note::

    Requires Python 2.6 or newer.

    N)
Connectionnbitspipereturnc                 C   s*   	 t j| }t j|r|| d S q)N)rsaZrandnumZread_random_odd_intZprimeZis_primesend)r   r   Zinteger r   ,lib/python3.10/site-packages/rsa/parallel.py_find_prime    s   
r
   poolsizec                    s   t jdd\}z# fddt|D }|D ]}|  q| }W |    n	|    w |D ]}|  q7|S )aU  Returns a prime number that can be stored in 'nbits' bits.

    Works in multiple threads at the same time.

    >>> p = getprime(128, 3)
    >>> rsa.prime.is_prime(p-1)
    False
    >>> rsa.prime.is_prime(p)
    True
    >>> rsa.prime.is_prime(p+1)
    False

    >>> from rsa import common
    >>> common.bit_size(p) == 128
    True

    F)Zduplexc                    s   g | ]}t jt fd qS ))targetargs)mpZProcessr
   ).0_r   Z	pipe_sendr   r	   
<listcomp>A   s    zgetprime.<locals>.<listcomp>)r   ZPiperangestartZrecvcloseZ	terminate)r   r   Z	pipe_recvZprocspresultr   r   r	   getprime*   s   




r   __main__z'Running doctests 1000x or until failured   
   z%i timeszDoctests done)__doc__Zmultiprocessingr   Zmultiprocessing.connectionr   Z	rsa.primer   Zrsa.randnumintr
   r   __all____name__printZdoctestr   countZtestmodZfailuresZtestsr   r   r   r	   <module>   s(   

)