U
    
W[}  ã                   @   s°   d Z ddlmZmZ ddlZddlmZmZ ddlm	Z	 ddl
mZ ddlmZ dd	d
ddgZdd„ Zddd	„Zdd
„ Zddd„Zdd„ Zdd„ Zeeddddƒƒdd„ ƒZdS )z@
Common functions for the SSH classes.

Maintainer: Paul Swartz
é    )Úabsolute_importÚdivisionN)Úint_from_bytesÚint_to_bytes)Úunicode)Ú
deprecated)ÚVersionÚNSÚgetNSÚMPÚgetMPÚffsc                 C   s(   t | tƒr|  d¡} t dt| ƒ¡|  S )z
    net string
    zutf-8ú!L)Ú
isinstancer   ÚencodeÚstructÚpackÚlen)Út© r   ú:/usr/lib/python3/dist-packages/twisted/conch/ssh/common.pyr	      s    

é   c                 C   sp   g }d}t |ƒD ]H}t d| ||d … ¡\}| | |d d| | … ¡ |d| 7 }qt|ƒ| |d… f S )z
    get net string
    r   r   é   N)Úranger   ÚunpackÚappendÚtuple)ÚsÚcountÚnsÚcÚiÚlr   r   r   r
   #   s    c                 C   sP   | dkrdS | dkst ‚t| ƒ}t|dd… ƒd@ r<d| }t dt|ƒ¡| S )Nr   s       r   é€   ó    ú>L)ÚAssertionErrorr   Úordr   r   r   )ZnumberZbnr   r   r   r   1   s    c                 C   sv   g }d}t |ƒD ]N}t d| ||d … ¡\}| t| |d |d | … dƒ¡ |d| 7 }qt|ƒ| |d… f S )a=  
    Get multiple precision integer out of the string.  A multiple precision
    integer is stored as a 4-byte length followed by length bytes of the
    integer.  If count is specified, get count integers out of the string.
    The return value is a tuple of count integers followed by the rest of
    the data.
    r   r%   r   ZbigN)r   r   r   r   r   r   )Údatar   Zmpr    r!   Zlengthr   r   r   r   <   s    $c                 C   s   t t| ||ƒƒS )z3
    Return the MP version of C{(x ** y) % z}.
    )r   Úpow)ÚxÚyÚzr   r   r   Ú_MPpowN   s    r-   c                 C   s   | D ]}||kr|  S qdS )zs
    first from second
    goes through the first list, looking for items in the second, returns the first one
    Nr   )r    r   r!   r   r   r   r   V   s    ZTwistedé   é   c                   C   s   d S )Nr   r   r   r   r   Úinstalla   s    r0   )r   )r   )Ú__doc__Z
__future__r   r   r   Zcryptography.utilsr   r   Ztwisted.python.compatr   Ztwisted.python.deprecater   Ztwisted.python.versionsr   Ú__all__r	   r
   r   r   r-   r   r0   r   r   r   r   Ú<module>   s   


