o
    Þý°jI  ã                   @   sJ   d dl mZmZmZmZmZmZ eddƒZddd„Zddd„Z	d	d
„ Z
dS )é    )Úload_pycryptodome_raw_libÚc_size_tÚcreate_string_bufferÚget_raw_bufferÚc_uint8_ptrÚis_writeable_bufferzCryptodome.Util._strxoray  
                    void strxor(const uint8_t *in1,
                                const uint8_t *in2,
                                uint8_t *out, size_t len);
                    void strxor_c(const uint8_t *in,
                                  uint8_t c,
                                  uint8_t *out,
                                  size_t len);
                    Nc                 C   sš   t | ƒt |ƒkrtdƒ‚|du rtt | ƒƒ}n|}t|ƒs!tdƒ‚t | ƒt |ƒkr1tdt | ƒ ƒ‚t t| ƒt|ƒt|ƒtt | ƒƒ¡ |du rKt	|ƒS dS )až  From two byte strings of equal length,
    create a third one which is the byte-by-byte XOR of the two.

    Args:
      term1 (bytes/bytearray/memoryview):
        The first byte string to XOR.
      term2 (bytes/bytearray/memoryview):
        The second byte string to XOR.
      output (bytearray/memoryview):
        The location where the result will be written to.
        It must have the same length as ``term1`` and ``term2``.
        If ``None``, the result is returned.
    :Return:
        If ``output`` is ``None``, a new byte string with the result.
        Otherwise ``None``.

    .. note::
        ``term1`` and ``term2`` must have the same length.
    z.Only byte strings of equal length can be xoredNú4output must be a bytearray or a writeable memoryviewú9output must have the same length as the input  (%d bytes))
ÚlenÚ
ValueErrorr   r   Ú	TypeErrorÚ_raw_strxorÚstrxorr   r   r   )Úterm1Úterm2ÚoutputÚresult© r   ú‰/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/Cryptodome/Util/strxor.pyr   0   s&   ÿ

ýr   c                 C   s¢   d|  krdk st dƒ‚ t dƒ‚|du rtt| ƒƒ}n|}t|ƒs'tdƒ‚t| ƒt|ƒkr7t dt| ƒ ƒ‚t t| ƒ|t|ƒtt| ƒƒ¡ |du rOt	|ƒS dS )a~  From a byte string, create a second one of equal length
    where each byte is XOR-red with the same value.

    Args:
      term(bytes/bytearray/memoryview):
        The byte string to XOR.
      c (int):
        Every byte in the string will be XOR-ed with this value.
        It must be between 0 and 255 (included).
      output (None or bytearray/memoryview):
        The location where the result will be written to.
        It must have the same length as ``term``.
        If ``None``, the result is returned.

    Return:
        If ``output`` is ``None``, a new ``bytes`` string with the result.
        Otherwise ``None``.
    r   é   zc must be in range(256)Nr   r	   )
r   r   r
   r   r   r   Ústrxor_cr   r   r   )ÚtermÚcr   r   r   r   r   r   `   s*   ÿÿ

ýr   c                 C   s   t  | ||tt| ƒƒ¡ dS )z!Very fast XOR - check conditions!N)r   r   r   r
   )r   r   r   r   r   r   Ú_strxor_direct�   s   r   )N)ÚCryptodome.Util._raw_apir   r   r   r   r   r   r   r   r   r   r   r   r   r   Ú<module>   s    þ

00