U
    we                     @   sJ   d Z ddlZddlmZ ddlmZ ddlmZ dd ZG dd	 d	Z	dS )
z,
Utility functions for dealing with primes.
    N)util)	byte_mask)SSHExceptionc                 C   st   t | d }|d d }td|d d }t|}|dkrXt|d ||dd  }t |d}|| k r,qpq,|S )z returns a random # from 0 to N-1            r   N)r   
bit_lengthpowosurandomr   inflate_long)nbits
byte_countZ
hbyte_maskxnum r   n/mounts/lovelace/software/anaconda3/envs/qiime2-amplicon-2024.2/lib/python3.8/site-packages/paramiko/primes.py_roll_random   s    	
r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )ModulusPackzx
    convenience object for holding the contents of the /etc/ssh/moduli file,
    on systems that have such a file.
    c                 C   s   i | _ g | _d S )N)pack	discarded)selfr   r   r   __init__:   s    zModulusPack.__init__c           
      C   s   |  \}}}}}}}t|}t|}t|}t|}t|}t|d}|dk sp|dk sp|d@ r|dk r|dk r| j|df d S |dkrd}t|}	|	|kr|	|d kr| j|d	|f d S |	| jkrg | j|	< | j|	 ||f d S )
N   r      r   d   z does not meet basic requirementsr   r   z"incorrectly reported bit length {})splitintr   appendr   r	   formatr   )
r   line	timestampmod_typetestsZtriessize	generatormodulusZblr   r   r   _parse_modulus?   sP    	



zModulusPack._parse_modulusc              	   C   sl   i | _ t|dR}|D ]F}| }t|dks|d dkr<qz| | W q   Y qY qX qW 5 Q R X dS )zM
        :raises IOError: passed from any file operations that fail.
        rr   #N)r   openstriplenr)   )r   filenamefr"   r   r   r   	read_filem   s    zModulusPack.read_filec                 C   s   t | j }t|dkr"tdd}|D ](}||kr*||kr*||k sN|dkr*|}q*|dkr|D ] }||kr`||kr`||kr`|}q`|dkr|d }||kr|d }tt| j| }| j| | S )Nr   zno moduli available)sortedr   keysr.   r   r   )r   minZprefermaxZbitsizesgoodbr   r   r   r   get_modulus|   s"     zModulusPack.get_modulusN)__name__
__module____qualname____doc__r   r)   r1   r9   r   r   r   r   r   4   s
   .r   )
r=   r   paramikor   paramiko.commonr   paramiko.ssh_exceptionr   r   r   r   r   r   r   <module>   s   