
    9i'                         S SK r S SKJrJr  S SKJr  S SKJrJr   " S S\ R                  5      r
 " S S\ R                  5      r0 4S	 jr\S
:X  a  S r\ R                  " SS9  gg)    N)	unhexlifyhexlify)list_test_cases)strxorstrxor_cc                   b    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rSrg)StrxorTests)   c                     [        S5      n[        S5      n[        S5      nU R                  [        X5      U5        U R                  [        X!5      U5        g N   ff339a83e5cd4cdf5649   383d4ba020573314395b   c70ed123c59a7fcb6f12)r   assertEqualr   )selfterm1term2results       `/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/Crypto/SelfTest/Util/test_strxor.pytest1StrxorTests.test1+   sM    121223-v6-v6    c                 >    SnU R                  [        X5      U5        g )Nr   )r   r   )r   ess     r   test2StrxorTests.test22   s    ,r   c                 l    [        S5      nS[        U5      -  nU R                  [        X5      U5        g )Nr       )r   lenr   r   )r   r   	all_zeross      r   test3StrxorTests.test36   s0    12c%j(	-y9r   c                 f    [        S5      n[        S5      nU R                  [        [        X5        g )Nr   s   ff339a83e5cd4cdf564990)r   assertRaises
ValueErrorr   r   r   r   s      r   test_wrong_lengthStrxorTests.test_wrong_length;   s*    1234*fe;r   c                     [        S5      n[        U5      n[        S5      n[        S5      nU R                  [        X#5      U5        g r   )r   	bytearrayr   r   )r   r   term1_bar   r   s        r   test_bytearrayStrxorTests.test_bytearray@   sB    12U#12230&9r   c                     [        S5      n[        U5      n[        S5      n[        S5      nU R                  [        X#5      U5        g r   )r   
memoryviewr   r   )r   r   term1_mvr   r   s        r   test_memoryviewStrxorTests.test_memoryviewH   sB    12e$12230&9r   c                     [        S5      n[        S5      nUSS nUSS n[        S5      n[        [        U5      5      n[        XUS9nU R	                  US5        U R	                  Xe5        U R	                  X5        U R	                  X$5        g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_xorr6   r   s           r   test_output_bytearray!StrxorTests.test_output_bytearrayP   s     1212qq !893u:&V4&.//r   c                 2   [        S5      n[        S5      nUSS nUSS n[        S5      n[        [        [        U5      5      5      n[	        XUS9nU R                  US5        U R                  Xe5        U R                  X5        U R                  X$5        gr4   )r   r/   r*   r   r   r   r7   s           r   test_output_memoryview"StrxorTests.test_output_memoryviewa   s     1212qq !89Ic%j12V4&.//r   c                     [        [        S5      5      n[        S5      nUSS n[        S5      n[        XUS9nU R                  US5        U R                  X5        U R                  X#5        g1Verify result can be stored in overlapping memoryr   r   Nr   r5   )r*   r   r   r   r   r   r   r9   r:   r   s         r   !test_output_overlapping_bytearray-StrxorTests.test_output_overlapping_bytearrayr   sk     )$;<=12q !89U3&-/r   c                     [        [        [        S5      5      5      n[        S5      nUSS n[        S5      n[        XUS9nU R	                  US5        U R	                  X5        U R	                  X#5        grA   )r/   r*   r   r   r   rC   s         r   "test_output_overlapping_memoryview.StrxorTests.test_output_overlapping_memoryview   sp     9Y/F%GHI12q !89U3&-/r   c                 d    [        S5      n[        S5      nU R                  [        [        XUS9  g2Verify result cannot be stored in read-only memoryr   r   r5   N)r   r$   	TypeErrorr   r&   s      r   test_output_ro_bytes StrxorTests.test_output_ro_bytes   s1     1212)VU%Hr   c                 v    [        [        S5      5      n[        S5      nU R                  [        [        XUS9  grJ   )r/   r   r$   rL   r   r&   s      r   test_output_ro_memoryview%StrxorTests.test_output_ro_memoryview   s6     9%<=>12)VU%Hr   c                     [        S5      n[        S5      n[        [        U5      S-
  5      nU R                  [        [
        XUS9  g)<Verify result cannot be stored in memory of incorrect lengthr   r      r5   N)r   r*   r   r$   r%   r   )r   r   r   r6   s       r   test_output_incorrect_length(StrxorTests.test_output_incorrect_length   sC     12123u:>**fe6Jr    N)__name__
__module____qualname____firstlineno__r   r   r!   r'   r,   r1   r;   r>   rD   rG   rM   rP   rU   __static_attributes__rW   r   r   r	   r	   )   sF    7-:
<
::0"0"00IIKr   r	   c                   b    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rSrg)Strxor_cTests   c                 h    [        S5      n[        S5      nU R                  [        US5      U5        g Nr      be72dbc2a48c0d9e1708A   r   r   r   )r   r   r   s      r   r   Strxor_cTests.test1   s/    1223%,f5r   c                 R    [        S5      nU R                  [        US5      U5        g )Nr   r   rd   r   r   s     r   r   Strxor_cTests.test2   s$    12%+U3r   c                 <    U R                  [        SS5      S5        g )Nr   Z   )r   r   )r   s    r   r!   Strxor_cTests.test3   s    #r*C0r   c                     [        S5      nU R                  [        [        US5        U R                  [        [        US5        g )Nr      )r   r$   r%   r   rg   s     r   test_wrong_rangeStrxor_cTests.test_wrong_range   s5    12*hr:*hs;r   c                 ~    [        S5      n[        U5      n[        S5      nU R                  [        US5      U5        g ra   )r   r*   r   r   )r   r   r+   r   s       r   r,   Strxor_cTests.test_bytearray   s9    12U#23(B/8r   c                 ~    [        S5      n[        U5      n[        S5      nU R                  [        US5      U5        g ra   )r   r/   r   r   )r   r   r0   r   s       r   r1   Strxor_cTests.test_memoryview   s9    12e$23(B/8r   c                     [        S5      nUS S  n[        S5      n[        [        U5      5      n[        USUS9nU R	                  US 5        U R	                  XC5        U R	                  X5        g Nr   rb   rc   r5   )r   r*   r   r   r   r   r   r8   expected_resultr6   r   s         r   r;   #Strxor_cTests.test_output_bytearray   si    12q#$;<3u:&%F3&1/r   c                     [        S5      nUS S  n[        S5      n[        [        [        U5      5      5      n[	        USUS9nU R                  US 5        U R                  XC5        U R                  X5        g rv   )r   r/   r*   r   r   r   rw   s         r   r>   $Strxor_cTests.test_output_memoryview   sn    12q#$;<Ic%j12%F3&1/r   c                     [        [        S5      5      n[        S5      n[        USUS9nU R                  US5        U R                  X5        grB   r   rb   rc   r5   N)r*   r   r   r   r   r   r:   r   s       r   rD   /Strxor_cTests.test_output_overlapping_bytearray   sK     )$;<= !89%E2&-r   c                     [        [        [        S5      5      5      n[        S5      n[        USUS9nU R	                  US5        U R	                  X5        gr}   )r/   r*   r   r   r   r~   s       r   rG   0Strxor_cTests.test_output_overlapping_memoryview   sP     9Y/F%GHI !89%E2&-r   c                 P    [        S5      nU R                  [        [        USUS9  g)rK   r   rc   r5   N)r   r$   rL   r   rg   s     r   rM   "Strxor_cTests.test_output_ro_bytes   s(     12)XubGr   c                 x    [        [        S5      5      n[        S5      nU R                  [        [        USUS9  g)rK   r   r   rc   r5   N)r/   r   r$   rL   r   r&   s      r   rP   'Strxor_cTests.test_output_ro_memoryview   s8     9%<=>12)XubGr   c                 ~    [        S5      n[        [        U5      S-
  5      nU R                  [        [
        USUS9  g)rS   r   rT   rc   r5   N)r   r*   r   r$   r%   r   )r   r   r6   s      r   rU   *Strxor_cTests.test_output_incorrect_length  s:     123u:>**hr&Ir   rW   N)rX   rY   rZ   r[   r   r   r!   ro   r,   r1   r;   r>   rD   rG   rM   rP   rU   r\   rW   r   r   r^   r^      sF    6
41<
99
0
0	.	.HHJr   r^   c                 R    / nU[        [        5      -  nU[        [        5      -  nU$ N)r   r	   r^   )configtestss     r   	get_testsr     s*    E	_[))E	_]++ELr   __main__c                  >    [         R                  " [        5       5      $ r   )unittest	TestSuiter   rW   r   r   <lambda>r     s    H&&y{3r   suite)defaultTest)r   binasciir   r   Crypto.SelfTest.st_commonr   Crypto.Util.strxorr   r   TestCaser	   r^   r   rX   r   mainrW   r   r   <module>r      sl   D  ' 5 /|K(## |K~dJH%% dJN   z3EMMg& r   