
    7g$                     d    d Z ddlZddlmZ ddlmZ ddlmZmZm	Z	 ddl
mZ  G d d          ZdS )	z&
Implementation of an SSH2 "message".
    N)BytesIO)util)	zero_bytemax_byteone_byte)uc                       e Zd ZdZdZd!dZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d  Z!dS )"Messagea~  
    An SSH2 message is a stream of bytes that encodes some combination of
    strings, integers, bools, and infinite-precision integers.  This class
    builds or breaks down such a byte stream.

    Normally you don't need to deal with anything this low-level, but it's
    exposed for people implementing custom extensions, or features that
    paramiko doesn't support yet.
    l      ~ Nc                 \    |t          |          | _        dS t                      | _        dS )z
        Create a new SSH2 message.

        :param bytes content:
            the byte stream to use as the message content (passed in only when
            decomposing a message).
        N)r   packet)selfcontents     J/var/www/html/syslog/venv/lib/python3.11/site-packages/paramiko/message.py__init__zMessage.__init__,   s,     !'**DKKK!))DKKK    c                 *    |                                  S N)asbytesr   s    r   	__bytes__zMessage.__bytes__9   s    ||~~r   c                 Z    dt          | j                                                  z   dz   S )zP
        Returns a string representation of this object, for debugging.
        zparamiko.Message())reprr   getvaluer   s    r   __repr__zMessage.__repr__<   s*     #T$+*>*>*@*@%A%AACGGr   c                 4    | j                                         S )zO
        Return the byte stream content of this Message, as a `bytes`.
        )r   r   r   s    r   r   zMessage.asbytesC   s     {##%%%r   c                 :    | j                             d           dS )zk
        Rewind the message to the beginning as if no items had been parsed
        out of it yet.
        r   N)r   seekr   s    r   rewindzMessage.rewindI   s     
 	r   c                     | j                                         }| j                                         }| j                             |           |S )zk
        Return the `bytes` of this message that haven't already been parsed and
        returned.
        )r   tellreadr   )r   position	remainders      r   get_remainderzMessage.get_remainderP   sF    
 ;##%%K$$&&	"""r   c                     | j                                         }|                                  | j                             |          S )z
        Returns the `bytes` of this message that have been parsed and
        returned. The string passed into a message's constructor can be
        regenerated by concatenating ``get_so_far`` and `get_remainder`.
        )r   r!   r   r"   )r   r#   s     r   
get_so_farzMessage.get_so_farZ   s:     ;##%%{)))r   c                     | j                             |          }d}t          |          |cxk     r|k     r n n|t          |t          |          z
  z  z   S |S )a	  
        Return the next ``n`` bytes of the message, without decomposing into an
        int, decoded string, etc.  Just the raw bytes are returned. Returns a
        string of ``n`` zero bytes if there weren't ``n`` bytes remaining in
        the message.
        i   )r   r"   lenr   )r   nbmax_pad_sizes       r   	get_byteszMessage.get_bytesd   se     KQq66A$$$$$$$$$yAAJ///r   c                 ,    |                      d          S )a  
        Return the next byte of the message, without decomposing it.  This
        is equivalent to `get_bytes(1) <get_bytes>`.

        :return:
            the next (`bytes`) byte of the message, or ``b' '`` if there
            aren't any bytes remaining.
           )r-   r   s    r   get_bytezMessage.get_byteq   s     ~~a   r   c                 B    |                      d          }|t          k    S )z2
        Fetch a boolean from the stream.
        r/   )r-   r   r   r+   s     r   get_booleanzMessage.get_boolean|   s     NN1I~r   c                     |                      d          }|t          k    r&t          j        |                                           S ||                      d          z  }t          j        d|          d         S )zZ
        Fetch an int from the stream.

        :return: a 32-bit unsigned `int`.
        r/      >Ir   )r-   r   r   inflate_long
get_binarystructunpack)r   bytes     r   get_adaptive_intzMessage.get_adaptive_int   sh     ~~a  8$T__%6%6777q!!!}T4((++r   c                 ^    t          j        d|                     d                    d         S )z/
        Fetch an int from the stream.
        r6      r   r9   r:   r-   r   s    r   get_intzMessage.get_int   s'     }T4>>!#4#455a88r   c                 ^    t          j        d|                     d                    d         S )zj
        Fetch a 64-bit int from the stream.

        :return: a 64-bit unsigned integer (`int`).
        >Q   r   r?   r   s    r   	get_int64zMessage.get_int64   s'     }T4>>!#4#455a88r   c                 N    t          j        |                                           S )zr
        Fetch a long int (mpint) from the stream.

        :return: an arbitrary-length integer (`int`).
        )r   r7   r8   r   s    r   	get_mpintzMessage.get_mpint   s      !2!2333r   c                 P    |                      |                                           S )z
        Fetch a "string" from the stream.  This will actually be a `bytes`
        object, and may contain unprintable characters.  (It's not unheard of
        for a string to contain another byte-stream message.)
        r-   r@   r   s    r   
get_stringzMessage.get_string   s     ~~dllnn---r   c                 D    t          |                                           S )z
        Fetch a Unicode string from the stream.

        This currently operates by attempting to encode the next "string" as
        ``utf-8``.
        )r   rI   r   s    r   get_textzMessage.get_text   s     ""###r   c                 P    |                      |                                           S )z@
        Alias for `get_string` (obtains a bytestring).
        rH   r   s    r   r8   zMessage.get_binary   s     ~~dllnn---r   c                 P    |                                                      d          S )z
        Fetch a list of `strings <str>` from the stream.

        These are trivially encoded as comma-separated values in a string.
        ,)rK   splitr   s    r   get_listzMessage.get_list   s      }}$$S)))r   c                 :    | j                             |           | S )zj
        Write bytes to the stream, without any formatting.

        :param bytes b: bytes to add
        r   writer2   s     r   	add_byteszMessage.add_bytes        	!r   c                 :    | j                             |           | S )zq
        Write a single byte to the stream, without any formatting.

        :param bytes b: byte to add
        rR   r2   s     r   add_bytezMessage.add_byte   rU   r   c                     |r | j                             t                     n| j                             t                     | S )za
        Add a boolean value to the stream.

        :param bool b: boolean value to add
        )r   rS   r   r   r2   s     r   add_booleanzMessage.add_boolean   s@      	)Kh''''Ki(((r   c                 `    | j                             t          j        d|                     | S zU
        Add an integer to the stream.

        :param int n: integer to add
        r6   r   rS   r9   packr   r*   s     r   add_intzMessage.add_int   +     	&+dA..///r   c                    |t           j        k    rG| j                            t                     |                     t          j        |                     n-| j                            t          j	        d|                     | S r[   )
r
   big_intr   rS   r   
add_stringr   deflate_longr9   r]   r^   s     r   add_adaptive_intzMessage.add_adaptive_int   sn     Kh'''OOD-a001111Kfk$22333r   c                 `    | j                             t          j        d|                     | S )zX
        Add a 64-bit int to the stream.

        :param int n: long int to add
        rB   r\   r^   s     r   	add_int64zMessage.add_int64   r`   r   c                 T    |                      t          j        |                     | S )z
        Add a long int to the stream, encoded as an infinite-precision
        integer.  This method only works on positive numbers.

        :param int z: long int to add
        )rc   r   rd   )r   zs     r   	add_mpintzMessage.add_mpint  s&     	)!,,---r   c                     t          j        |          }|                     t          |                     | j                            |           | S )z[
        Add a bytestring to the stream.

        :param byte s: bytestring to add
        )r   r   r_   r)   r   rS   )r   ss     r   rc   zMessage.add_string  sD     LOOSVV!r   c                 V    |                      d                    |                     | S )z
        Add a list of strings to the stream.  They are encoded identically to
        a single string of values separated by commas.  (Yes, really, that's
        how SSH2 does it.)

        :param l: list of strings to add
        rN   )rc   join)r   ls     r   add_listzMessage.add_list  s%     	$$$r   c                 ,   t          |          t          u r|                     |          S t          |t                    r|                     |          S t          |          t          u r|                     |          S |                     |          S r   )	typeboolrY   
isinstanceintre   listrp   rc   )r   is     r   _addzMessage._add'  s~    77d??##A&&&3 	&((+++!WW__==###??1%%%r   c                 :    |D ]}|                      |           dS )a  
        Add a sequence of items to the stream.  The values are encoded based
        on their type: bytes, str, int, bool, or list.

        .. warning::
            Longs are encoded non-deterministically.  Don't use this method.

        :param seq: the sequence of items
        N)rx   )r   seqitems      r   addzMessage.add3  s.      	 	DIIdOOOO	 	r   r   )"__name__
__module____qualname____doc__rb   r   r   r   r   r   r%   r'   r-   r0   r3   r<   r@   rD   rF   rI   rK   r8   rP   rT   rW   rY   r_   re   rg   rj   rc   rp   rx   r|    r   r   r
   r
      s         G$ $ $ $  H H H& & &    * * *  	! 	! 	!  
, 
, 
,9 9 99 9 94 4 4. . .$ $ $. . .* * *    
 
 
        	 	 		 	 	& & &    r   r
   )r   r9   ior   paramikor   paramiko.commonr   r   r   paramiko.utilr   r
   r   r   r   <module>r      s   &               9 9 9 9 9 9 9 9 9 9      _ _ _ _ _ _ _ _ _ _r   