o
     j'                     @   s   d dl Z d dlmZmZ d dlmZ d dlmZmZ G dd de j	Z
G dd de j	Zi fd	d
ZedkrBdd Ze jdd dS dS )    N)	unhexlifyhexlify)list_test_cases)strxorstrxor_cc                   @   t   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd ZdS )StrxorTestsc                 C   s@   t d}t d}t d}| t||| | t||| d S N   ff339a83e5cd4cdf5649   383d4ba020573314395b   c70ed123c59a7fcb6f12)r   assertEqualr   )selfterm1term2result r   a/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/Crypto/SelfTest/Util/test_strxor.pytest1+   s
   zStrxorTests.test1c                 C   s   d}|  t||| d S )N    )r   r   )r   esr   r   r   test22   s   zStrxorTests.test2c                 C   s*   t d}dt| }| t||| d S )Nr
       )r   lenr   r   )r   r   Z	all_zerosr   r   r   test36   s   zStrxorTests.test3c                 C   s$   t d}t d}| tt|| d S )Nr
   s   ff339a83e5cd4cdf564990)r   assertRaises
ValueErrorr   r   r   r   r   r   r   test_wrong_length;   s   zStrxorTests.test_wrong_lengthc                 C   6   t d}t|}t d}t d}| t||| d S r	   )r   	bytearrayr   r   )r   r   term1_bar   r   r   r   r   test_bytearray@   
   zStrxorTests.test_bytearrayc                 C   r   r	   )r   
memoryviewr   r   )r   r   term1_mvr   r   r   r   r   test_memoryviewH   r#   zStrxorTests.test_memoryviewc                 C   s~   t d}t d}|dd }|dd }t d}tt|}t|||d}| |d | || | || | || dS z3Verify result can be stored in pre-allocated memoryr
   r   Nr   output)r   r    r   r   r   r   r   r   original_term1original_term2expected_xorr)   r   r   r   r   test_output_bytearrayP   s   z!StrxorTests.test_output_bytearrayc                 C   s   t d}t d}|dd }|dd }t d}ttt|}t|||d}| |d | || | || | || dS r'   )r   r$   r    r   r   r   r*   r   r   r   test_output_memoryviewa   s   z"StrxorTests.test_output_memoryviewc                 C   s^   t td}td}|dd }td}t|||d}| |d | || | || dS 1Verify result can be stored in overlapping memoryr
   r   Nr   r(   )r    r   r   r   r   r   r   r,   r-   r   r   r   r   !test_output_overlapping_bytearrayr   s   z-StrxorTests.test_output_overlapping_bytearrayc                 C   sb   t ttd}td}|dd }td}t|||d}| |d | || | || dS r0   )r$   r    r   r   r   r2   r   r   r   "test_output_overlapping_memoryview   s   z.StrxorTests.test_output_overlapping_memoryviewc                 C   s(   t d}t d}| jtt|||d dS 2Verify result cannot be stored in read-only memoryr
   r   r(   N)r   r   	TypeErrorr   r   r   r   r   test_output_ro_bytes   s   z StrxorTests.test_output_ro_bytesc                 C   s,   t td}td}| jtt|||d dS r5   )r$   r   r   r7   r   r   r   r   r   test_output_ro_memoryview      z%StrxorTests.test_output_ro_memoryviewc                 C   s8   t d}t d}tt|d }| jtt|||d dS )<Verify result cannot be stored in memory of incorrect lengthr
   r      r(   N)r   r    r   r   r   r   )r   r   r   r)   r   r   r   test_output_incorrect_length   s   z(StrxorTests.test_output_incorrect_lengthN)__name__
__module____qualname__r   r   r   r   r"   r&   r.   r/   r3   r4   r8   r9   r=   r   r   r   r   r   )   s    r   c                   @   r   )Strxor_cTestsc                 C   s&   t d}t d}| t|d| d S Nr
      be72dbc2a48c0d9e1708A   r   r   r   )r   r   r   r   r   r   r      s   zStrxor_cTests.test1c                 C   s   t d}| t|d| d S )Nr
   r   rE   r   r   r   r   r   r      s   zStrxor_cTests.test2c                 C   s   |  tddd d S )Nr   Z   )r   r   )r   r   r   r   r      s   zStrxor_cTests.test3c                 C   s,   t d}| tt|d | tt|d d S )Nr
      )r   r   r   r   rF   r   r   r   test_wrong_range   s   zStrxor_cTests.test_wrong_rangec                 C   .   t d}t|}t d}| t|d| d S rB   )r   r    r   r   )r   r   r!   r   r   r   r   r"         zStrxor_cTests.test_bytearrayc                 C   rK   rB   )r   r$   r   r   )r   r   r%   r   r   r   r   r&      rL   zStrxor_cTests.test_memoryviewc                 C   s^   t d}|d d  }t d}tt|}t|d|d}| |d  | || | || d S Nr
   rC   rD   r(   )r   r    r   r   r   r   r   r+   Zexpected_resultr)   r   r   r   r   r.      s   z#Strxor_cTests.test_output_bytearrayc                 C   sb   t d}|d d  }t d}ttt|}t|d|d}| |d  | || | || d S rM   )r   r$   r    r   r   r   rN   r   r   r   r/      s   z$Strxor_cTests.test_output_memoryviewc                 C   s>   t td}td}t|d|d}| |d | || dS r1   r
   rC   rD   r(   N)r    r   r   r   r   r   r-   r   r   r   r   r3      s
   z/Strxor_cTests.test_output_overlapping_bytearrayc                 C   sB   t ttd}td}t|d|d}| |d | || dS rO   )r$   r    r   r   r   rP   r   r   r   r4      s
   z0Strxor_cTests.test_output_overlapping_memoryviewc                 C   s    t d}| jtt|d|d dS )r6   r
   rD   r(   N)r   r   r7   r   rF   r   r   r   r8      s   z"Strxor_cTests.test_output_ro_bytesc                 C   s,   t td}td}| jtt|d|d dS )r6   r
   r   rD   r(   N)r$   r   r   r7   r   r   r   r   r   r9      r:   z'Strxor_cTests.test_output_ro_memoryviewc                 C   s0   t d}tt|d }| jtt|d|d dS )r;   r
   r<   rD   r(   N)r   r    r   r   r   r   )r   r   r)   r   r   r   r=     s   z*Strxor_cTests.test_output_incorrect_lengthN)r>   r?   r@   r   r   r   rJ   r"   r&   r.   r/   r3   r4   r8   r9   r=   r   r   r   r   rA      s    rA   c                 C   s    g }|t t7 }|t t7 }|S N)r   r   rA   )configZtestsr   r   r   	get_tests  s   rS   __main__c                   C   s   t t S rQ   )unittestZ	TestSuiterS   r   r   r   r   <lambda>  s    rV   suite)ZdefaultTest)rU   binasciir   r   ZCrypto.SelfTest.st_commonr   ZCrypto.Util.strxorr   r   ZTestCaser   rA   rS   r>   rW   mainr   r   r   r   <module>   s   !g