U
    <æ{f’  ã                   @   s¤   U d dl Z d dlZd dlZd dlZd dlZd dlmZmZ G dd„ dƒZeƒ Z	ee e
d< ze ¡ ZW n ek
r~   dZY nX edœdd„Zeeed	œd
d„ZdS )é    N)ÚAnyÚOptionalc                   @   sŠ   e Zd Zdee dœdd„Zeddœdd„Zeddœdd	„Zdd
œdd„Ze	d
œdd„Z
e	d
œdd„Ze	d
œdd„Ze	e	e	dœdd„ZdS )ÚEntropyPoolN)Úseedc                 C   sp   d| _ d | _d| _t ¡ | _t ¡ | _d| _	t
d| j	 ƒ| _|d k	r`|  |¡ d| _t ¡ | _nd| _d| _d S )Nr   é   ó    TF)Ú
pool_indexÚdigestÚ	next_byteÚ	threadingÚLockÚlockÚhashlibÚsha1ÚhashÚhash_lenÚ	bytearrayÚpoolÚ_stirÚseededÚosÚgetpidÚseed_pid)Úselfr   © r   úJ/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/dns/entropy.pyÚ__init__    s    


zEntropyPool.__init__)ÚentropyÚreturnc                 C   sJ   |D ]@}| j | jkrd| _ |d@ }| j| j   |N  < |  j d7  _ qd S )Nr   éÿ   é   )r   r   r   )r   r   ÚcÚbr   r   r   r   0   s    zEntropyPool._stirc              	   C   s    | j  |  |¡ W 5 Q R X d S )N)r   r   )r   r   r   r   r   Ústir8   s    zEntropyPool.stir©r   c                 C   s°   | j r| jt ¡ kr¬zt d¡}W n` tk
r‚   z&tdddƒ}| d¡}W 5 Q R X W n$ tk
r|   tt	 	¡ ƒ 
¡ }Y nX Y nX d| _ t ¡ | _d | _t|ƒ}|  |¡ d S )Né   z/dev/urandomÚrbr   T)r   r   r   r   ÚurandomÚ	ExceptionÚopenÚreadÚstrÚtimeÚencoder	   r   r   )r   r   Úrr   r   r   Ú_maybe_seed<   s    
zEntropyPool._maybe_seedc              	   C   s‚   | j r |  ¡  | jd ks&| j| jkrZ| j t| jƒ¡ t	| j ¡ ƒ| _|  
| j¡ d| _| j| j }|  jd7  _W 5 Q R X |S )Nr   r    )r   r/   r	   r
   r   r   ÚupdateÚbytesr   r   r   )r   Úvaluer   r   r   Úrandom_8L   s    zEntropyPool.random_8c                 C   s   |   ¡ d |   ¡  S )Né   )r3   ©r   r   r   r   Ú	random_16X   s    zEntropyPool.random_16c                 C   s   |   ¡ d |   ¡  S )Né   )r6   r5   r   r   r   Ú	random_32[   s    zEntropyPool.random_32©ÚfirstÚlastr   c                 C   sd   || d }|dkrt dƒ‚|dkr0| j}d}n|dkrD| j}d}n
| j}d}|||ƒ  |d   S )	Nr    l        ztoo bigr7   l   ÿÿ r4   iÿÿ  r   )Ú
ValueErrorr8   r6   r3   )r   r:   r;   ÚsizeZrandÚmaxr   r   r   Úrandom_between^   s    zEntropyPool.random_between)N)Ú__name__Ú
__module__Ú__qualname__r   r1   r   r   r#   r/   Úintr3   r6   r8   r?   r   r   r   r   r      s   r   Úsystem_randomr$   c                   C   s    t d k	rt  dd¡S t ¡ S d S )Nr   r7   )rD   Ú	randranger   r6   r   r   r   r   r6   w   s    r6   r9   c                 C   s(   t d k	rt  | |d ¡S t | |¡S d S )Nr    )rD   rE   r   r?   )r:   r;   r   r   r   Úbetween~   s    rF   )r   r   Úrandomr   r,   Útypingr   r   r   r   Ú__annotations__ÚSystemRandomrD   r(   rC   r6   rF   r   r   r   r   Ú<module>   s    T
