o
    Ìn~b0  ã                   @   sb   d dl mZ d dlmZmZmZmZmZmZm	Z	 eddƒZ
G dd„ dƒZdd„ Zd	Zed
dƒZdS )é    )Úb)Úload_pycryptodome_raw_libÚVoidPointerÚcreate_string_bufferÚget_raw_bufferÚSmartPointerÚc_size_tÚc_uint8_ptrzCryptodome.Cipher._ARC4al  
                    int ARC4_stream_encrypt(void *rc4State, const uint8_t in[],
                                            uint8_t out[], size_t len);
                    int ARC4_stream_init(uint8_t *key, size_t keylen,
                                         void **pRc4State);
                    int ARC4_stream_destroy(void *rc4State);
                    c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú
ARC4CipherzgARC4 cipher object. Do not create it directly. Use
    :func:`Cryptodome.Cipher.ARC4.new` instead.
    c                 O   sÄ   t |ƒdkr|d }|dd… }n| dd¡}t |ƒtvr%tdt |ƒ ƒ‚tƒ | _t t|ƒt	t |ƒƒ| j 
¡ ¡}|dkrCtd| ƒ‚t| j ¡ tjƒ| _|dkrX|  d| ¡ d| _t |ƒ| _dS )zOInitialize an ARC4 cipher object

        See also `new()` at the module level.r   é   NZdropz$Incorrect ARC4 key length (%d bytes)z'Error %d while creating the ARC4 cipheró    )ÚlenÚpopÚkey_sizeÚ
ValueErrorr   Ú_stateÚ_raw_arc4_libZARC4_stream_initr	   r   Z
address_ofr   ÚgetZARC4_stream_destroyÚencryptÚ
block_size)ÚselfÚkeyÚargsÚkwargsZndropÚresult© r   úA/usr/local/lib/python3.10/dist-packages/Cryptodome/Cipher/ARC4.pyÚ__init__,   s0   ÿ

þÿ
ÿzARC4Cipher.__init__c                 C   sF   t t|ƒƒ}t | j ¡ t|ƒ|tt|ƒƒ¡}|rtd| ƒ‚t	|ƒS )zíEncrypt a piece of data.

        :param plaintext: The data to encrypt, of any size.
        :type plaintext: bytes, bytearray, memoryview
        :returns: the encrypted byte string, of equal length as the
          plaintext.
        z"Error %d while encrypting with RC4)
r   r   r   ZARC4_stream_encryptr   r   r	   r   r   r   )r   Ú	plaintextÚ
ciphertextr   r   r   r   r   N   s   	
ýzARC4Cipher.encryptc              
   C   s:   z|   |¡W S  ty } z
tt|ƒ dd¡ƒ‚d}~ww )zðDecrypt a piece of data.

        :param ciphertext: The data to decrypt, of any size.
        :type ciphertext: bytes, bytearray, memoryview
        :returns: the decrypted byte string, of equal length as the
          ciphertext.
        ÚencÚdecN)r   r   ÚstrÚreplace)r   r   Úer   r   r   Údecrypt`   s   	€ÿzARC4Cipher.decryptN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r%   r   r   r   r   r
   '   s
    "r
   c                 O   s   t | g|¢R i |¤ŽS )a¹  Create a new ARC4 cipher.

    :param key:
        The secret key to use in the symmetric cipher.
        Its length must be in the range ``[5..256]``.
        The recommended length is 16 bytes.
    :type key: bytes, bytearray, memoryview

    :Keyword Arguments:
        *   *drop* (``integer``) --
            The amount of bytes to discard from the initial part of the keystream.
            In fact, such part has been found to be distinguishable from random
            data (while it shouldn't) and also correlated to key.

            The recommended value is 3072_ bytes. The default value is 0.

    :Return: an `ARC4Cipher` object

    .. _3072: http://eprint.iacr.org/2002/067.pdf
    )r
   )r   r   r   r   r   r   Únewo   s   r*   r   é   i  N)ZCryptodome.Util.py3compatr   ZCryptodome.Util._raw_apir   r   r   r   r   r   r	   r   r
   r*   r   Úranger   r   r   r   r   Ú<module>   s   $
	H