o
    Mf'                     @   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/humari/django-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   	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 r1   )r%   r!   r   r   r   r3   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 r6   )r%   r   r   r8   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/   r0   r4   r5   r9   r:   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   rF   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   rG   r   r   r   test_wrong_range   s   zStrxor_cTests.test_wrong_rangec                 C   .   t d}t|}t d}| t|d| d S rC   )r   r!   r   r   )r   r   r"   r   r   r   r   r#         zStrxor_cTests.test_bytearrayc                 C   rL   rC   )r   r%   r   r   )r   r   r&   r   r   r   r   r'      rM   zStrxor_cTests.test_memoryviewc                 C   s^   t d}|d d  }t d}tt|}t|d|d}| |d  | || | || d S Nr
   rD   rE   r)   )r   r!   r   r   r   r   r   r,   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 rN   )r   r%   r!   r   r   r   rO   r   r   r   r0      s   z$Strxor_cTests.test_output_memoryviewc                 C   s>   t td}td}t|d|d}| |d | || dS r2   r
   rD   rE   r)   N)r!   r   r   r   r   r   r.   r   r   r   r   r4      s
   z/Strxor_cTests.test_output_overlapping_bytearrayc                 C   sB   t ttd}td}t|d|d}| |d | || dS rQ   )r%   r!   r   r   r   rR   r   r   r   r5      s
   z0Strxor_cTests.test_output_overlapping_memoryviewc                 C   s    t d}| jtt|d|d dS )r7   r
   rE   r)   N)r   r   r8   r   rG   r   r   r   r9      s   z"Strxor_cTests.test_output_ro_bytesc                 C   s,   t td}td}| jtt|d|d dS )r7   r
   r   rE   r)   N)r%   r   r   r8   r   r   r   r   r   r:      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=   rE   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@   rA   r   r   r   rK   r#   r'   r/   r0   r4   r5   r9   r:   r>   r   r   r   r   rB      s    rB   c                 C   s    g }|t t7 }|t t7 }|S N)r   r   rB   )configtestsr   r   r   	get_tests  s   rV   __main__c                   C   s   t t S rS   )unittest	TestSuiterV   r   r   r   r   <lambda>  s    rZ   suite)defaultTest)rX   binasciir   r   Crypto.SelfTest.st_commonr   Crypto.Util.strxorr   r   TestCaser   rB   rV   r?   r[   mainr   r   r   r   <module>   s   !g