
    ,h                     z    d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
 d dlmZ  edd      Z G d d      Zdd	Zd
ZdZy)    )_copy_bytes)load_pycryptodome_raw_libcreate_string_bufferget_raw_bufferVoidPointerSmartPointerc_size_tc_uint8_ptris_writeable_buffer)get_random_byteszCrypto.Cipher._Salsa20a  
                    int Salsa20_stream_init(uint8_t *key, size_t keylen,
                                            uint8_t *nonce, size_t nonce_len,
                                            void **pSalsaState);
                    int Salsa20_stream_destroy(void *salsaState);
                    int Salsa20_stream_encrypt(void *salsaState,
                                               const uint8_t in[],
                                               uint8_t out[], size_t len);
                    c                   &    e Zd ZdZd ZddZddZy)Salsa20CipherzSalsa20 cipher object. Do not create it directly. Use :py:func:`new`
    instead.

    :var nonce: The nonce with length 8
    :vartype nonce: byte string
    c           
      d   t        |      t        vrt        dt        |      z        t        |      dk7  rt        dt        |      z        t        dd|      | _        t               | _        t        j                  t        |      t        t        |            t        |      t        t        |            | j                  j                               }|rt        d      t        | j                  j                         t        j                        | _        d| _        t        |      | _        y)zQInitialize a Salsa20 cipher object

        See also `new()` at the module level.z+Incorrect key length for Salsa20 (%d bytes)   z-Incorrect nonce length for Salsa20 (%d bytes)Nz'Error %d instantiating a Salsa20 cipher   )lenkey_size
ValueErrorr   noncer   _state_raw_salsa20_libSalsa20_stream_initr
   r	   
address_ofr   getSalsa20_stream_destroy
block_size)selfkeyr   results       W/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/Crypto/Cipher/Salsa20.py__init__zSalsa20Cipher.__init__6   s    
 s88#JSQTXUVVu:?L Z( ) ) !tU3
!m!55#C( S*#E* U,..02 FGG"4;;??#4#3#J#JL C    Nc           
         |t        t        |            }nF|}t        |      st        d      t        |      t        |      k7  rt	        dt        |      z        t
        j                  | j                  j                         t        |      t        |      t        t        |                  }|rt	        d|z        |t        |      S y)a  Encrypt a piece of data.

        Args:
          plaintext(bytes/bytearray/memoryview): The data to encrypt, of any size.
        Keyword Args:
          output(bytes/bytearray/memoryview): The location where the ciphertext
            is written to. If ``None``, the ciphertext is returned.
        Returns:
          If ``output`` is ``None``, the ciphertext is returned as ``bytes``.
          Otherwise, ``None``.
        Nz4output must be a bytearray or a writeable memoryviewz9output must have the same length as the input  (%d bytes)z&Error %d while encrypting with Salsa20)r   r   r   	TypeErrorr   r   Salsa20_stream_encryptr   r   r
   r	   r   )r   	plaintextoutput
ciphertextr   s        r    encryptzSalsa20Cipher.encryptS   s     >-c)n=JJ&v. VWW9~V,  "025i."A B B "88)-):)4Y)?)4Z)@)1#i.)A	C
 ENOO>!*--r"   c                     	 | j                  ||      S # t        $ r)}t        t        |      j                  dd            d}~ww xY w)a  Decrypt a piece of data.
        
        Args:
          ciphertext(bytes/bytearray/memoryview): The data to decrypt, of any size.
        Keyword Args:
          output(bytes/bytearray/memoryview): The location where the plaintext
            is written to. If ``None``, the plaintext is returned.
        Returns:
          If ``output`` is ``None``, the plaintext is returned as ``bytes``.
          Otherwise, ``None``.
        )r'   encdecN)r)   r   strreplace)r   r(   r'   es       r    decryptzSalsa20Cipher.decrypty   sD    	;<<
6<:: 	;SV^^E59::	;s    	A$AAN)__name__
__module____qualname____doc__r!   r)   r0    r"   r    r   r   .   s    !:$L;r"   r   Nc                 4    |t        d      }t        | |      S )a%  Create a new Salsa20 cipher

    :keyword key: The secret key to use. It must be 16 or 32 bytes long.
    :type key: bytes/bytearray/memoryview

    :keyword nonce:
        A value that must never be reused for any other encryption
        done with this key. It must be 8 bytes long.

        If not provided, a random byte string will be generated (you can read
        it back via the ``nonce`` attribute of the returned object).
    :type nonce: bytes/bytearray/memoryview

    :Return: a :class:`Crypto.Cipher.Salsa20.Salsa20Cipher` object
    r   )r   r   )r   r   s     r    newr8      s     " } #e$$r"   r   )       r1   )Crypto.Util.py3compatr   Crypto.Util._raw_apir   r   r   r   r   r	   r
   r   Crypto.Randomr   r   r   r8   r   r   r6   r"   r    <module>r>      sT   2 .D D D +,-E	 [; [;|%. 
 r"   