U
    ˆjÏ  ã                   @  sò   d Z ddl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dœdd„Zd%ddddœdd	„Zdddœdd
„Zedddœdd„ƒZeddddœdd„ƒZd&ddddœdd„Zdd„ Ze
ed d!d"dƒƒd#d$„ ƒZdS )'z'
Common functions for the SSH classes.
é    )ÚannotationsN)ÚSequenceÚoverload)Úint_to_bytes)Ú
deprecated)ÚVersionÚNSÚgetNSÚMPÚgetMPÚffszbytes | strÚbytes)ÚtÚreturnc                 C  s(   t | tƒr|  d¡} t dt| ƒ¡|  S )z
    net string
    zutf-8ú!L)Ú
isinstanceÚstrÚencodeÚstructÚpackÚlen)r   © r   ú</tmp/pip-unpacked-wheel-j5h_c8_q/twisted/conch/ssh/common.pyr      s    

é   ÚintzSequence[bytes])ÚsÚcountr   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)r   r   ÚnsÚcÚiÚlr   r   r   r	      s    )Únumberr   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   )r&   Zbnr   r   r   r
   +   s    ztuple[int, bytes])Údatar   c                 C  s   d S ©Nr   )r,   r   r   r   r   5   s    zSequence[int | bytes])r,   r   r   c                 C  s   d S r-   r   )r,   r   r   r   r   r   :   s    c              	   C  sx   g }d}t |ƒD ]P}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   ÚbigN)r   r   r   r    r   Ú
from_bytesr!   )r,   r   Úmpr#   r$   Úlengthr   r   r   r   ?   s    &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   P   s    ZTwistedé   é   c                   C  s   d S r-   r   r   r   r   r   ÚinstallZ   s    r4   )r   )r   )Ú__doc__Ú
__future__r   r   Útypingr   r   Zcryptography.utilsr   Ztwisted.python.deprecater   Ztwisted.python.versionsr   Ú__all__r   r	   r
   r   r   r4   r   r   r   r   Ú<module>   s$   	

