
    ,h&                     p   d Z ddlZddlZddlZddlZddlZddlmZmZ ddl	m
Z
mZ ddlmZ d Z G d dej                        Z G d	 d
ej                        Z G d dej                        Z G d dej                        Z G d dej                        Z G d dej                        Zdi fdZd Zy)z&Self-testing for PyCrypto hash modules    N)hexlify	unhexlify)btobytes)strxor_cc                 X    t        j                  ddt        |             }t        |      S )Ns   \s+    )resubr   r   )
hex_stringshorters     ]/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/Crypto/SelfTest/Hash/common.pyt2br   $   s$    ffWc7:#67GWr	   c                       e Zd Zd Zd Zd Zy)HashDigestSizeSelfTestc                 z    t         j                  j                  |        || _        || _        || _        || _        y N)unittestTestCase__init__hashmodexpecteddescriptionextra_params)selfr   r   r   r   s        r   r   zHashDigestSizeSelfTest.__init__+   s4    ""4( &(r	   c                     | j                   S r   r   r   s    r   shortDescriptionz'HashDigestSizeSelfTest.shortDescription2       r	   c                    d| j                   vrU| j                  t        | j                  d             | j	                  | j                  j
                  | j                          | j                  j                  di | j                   }| j                  t        |d             | j	                  |j
                  | j                         y )Ntruncatedigest_size )r   
assertTruehasattrr   assertEqualr#   r   newr   hs     r   runTestzHashDigestSizeSelfTest.runTest5   s    T...OOGDLL-@AT\\55t}}EDLL1t001=126r	   N__name__
__module____qualname__r   r   r+   r$   r	   r   r   r   )   s    ) 7r	   r   c                       e Zd Zd Zd Zd Zy)HashSelfTestc                     t         j                  j                  |        || _        |j	                         | _        || _        || _        || _        y r   )	r   r   r   r   lowerr   inputr   r   )r   r   r   r   r4   r   s         r   r   zHashSelfTest.__init__@   sB    ""4( (
&(r	   c                     | j                   S r   r   r   s    r   r   zHashSelfTest.shortDescriptionH   r    r	   c                     | j                   j                  di | j                  }|j                  | j                         t        j                  |j                               }|j                         } | j                   j                  | j                  fi | j                  }|j                         }t        j                  |j                               }| j                  | j                  |       t        j                  d   dk(  r9| j                  | j                  |       | j                  | j                  |       nT| j                  | j                  j                         |       | j                  | j                  j                         |       | j                  | j                  |       | j                   j                  dvst        |d      rk|j                         }|j                  | j                         t        j                  |j                               }| j                  | j                  |       y y )Nr      )zCrypto.Hash.MD5zCrypto.Hash.SHA1r(   r$   )r   r(   r   updater4   binasciib2a_hexdigest	hexdigestr'   r   sysversion_infodecoder-   r&   )r   r*   out1out2out3out4h2out5s           r   r+   zHashSelfTest.runTestK   s   DLL1t001	
+{{}DLLTZZ=4+<+<={{}
+ 	-A!#T]]D1T]]D1T]]113T:T]]113T:-
 <<  (OOSZ[\^cSdBIIdjj!##BIIK0DT]]D1	 Ter	   Nr,   r$   r	   r   r1   r1   >   s    ) 2r	   r1   c                       e Zd Zd Zd Zy)HashTestOIDc                 l    t         j                  j                  |        || _        || _        || _        y r   )r   r   r   r   oidr   )r   r   rI   r   s       r   r   zHashTestOID.__init__l   s,    ""4((r	   c                      | j                   j                  di | j                  }| j                  |j                  | j                         y )Nr$   )r   r(   r   r'   rI   r)   s     r   r+   zHashTestOID.runTestr   s9    DLL1t001)r	   Nr-   r.   r/   r   r+   r$   r	   r   rG   rG   k   s    )*r	   rG   c                       e Zd Zd Zd Zy)ByteArrayTestc                 ^    t         j                  j                  |        || _        || _        y r   r   r   r   moduler   r   rP   r   s      r   r   zByteArrayTest.__init__y   %    ""4((r	   c                    t        d      }t        |      } | j                  j                  |fi | j                  } | j                  j                  |fi | j                  }d|d d | j                  |j                         |j                                t        |      } | j                  j                  di | j                  } | j                  j                  di | j                  }|j                  |       |j                  |       d|d d | j                  |j                         |j                                y )Nz       r$   )r   	bytearrayrP   r(   r   r'   r;   r8   )r   databah1rD   s        r   r+   zByteArrayTest.runTest~   s      t_T[[__T7T%6%67T[[__R54#4#452Abiik2 t_T[[__1t001T[[__1t001
		$
		"2Abiik2r	   NrK   r$   r	   r   rM   rM   w   s    )
3r	   rM   c                       e Zd Zd Zd Zy)MemoryViewTestc                 ^    t         j                  j                  |        || _        || _        y r   rO   rQ   s      r   r   zMemoryViewTest.__init__   rR   r	   c                    d}d }d }||fD ]M  } ||      } | j                   j                  |fi | j                  } | j                   j                  |fi | j                  }|j                  sd|d d | j	                  |j                         |j                                 ||      } | j                   j                  di | j                  } | j                   j                  di | j                  }|j                  |       |j                  |       |j                  sd|d d | j	                  |j                         |j                                P y )Ns    c                     t        |       S r   )
memoryviewrW   s    r   	get_mv_roz)MemoryViewTest.runTest.<locals>.get_mv_ro   s    d##r	   c                 *    t        t        |             S r   )r_   rV   r`   s    r   	get_mv_rwz)MemoryViewTest.runTest.<locals>.get_mv_rw   s    io..r	   rT   rU   r$   )rP   r(   r   readonlyr'   r;   r8   )r   rW   ra   rc   get_mvmvrY   rD   s           r   r+   zMemoryViewTest.runTest   s'   	$	/  * 	7F B ;):):;B 9t'8'89B;; 2ARYY["))+6 B 54#4#45B 54#4#45BIIdOIIbM;; 2ARYY["))+6)	7r	   NrK   r$   r	   r   r[   r[      s    )
7r	   r[   c                       e Zd Zd Zd Zd Zy)MACSelfTestc                     t         j                  j                  |        || _        t	        |      | _        t	        |      | _        t	        |      | _        || _        || _	        y r   )
r   r   r   rP   r   resultrW   keyparamsr   )r   rP   r   rj   rW   rk   rl   s          r   r   zMACSelfTest.__init__   sM    ""4(&kI	s8&r	   c                     | j                   S r   r   r   s    r   r   zMACSelfTest.shortDescription   r    r	   c                 $   t        | j                        } | j                  j                  | j                  fi | j
                  }|j                  | j                         | j                  | j                  |j                                | j                  t        | j                        j                  d      |j                                |j                  | j                         |j                  |       t        | j                  d      }| j                  t         |j                  |       | j                  t         |j                  d        | j                  j                  | j                  | j                  fi | j
                  }| j                  | j                  |j                                | j                  t        | j                        j                  d      |j                                	  | j                  j                  | j                  | j                  fi | j
                  }|j#                         }|j#                         }|j                  d       | j                  |j                         | j                         |j                  d       | j                  |j                         |j                                | j'                  t)        |j                         t+        d                   | j'                  t)        |j                         t+        d                   |j                  |j                                |j                  |j                         j-                  d             y # t$        $ r Y w xY w)Nascii   4556s   blar	    )r   rj   rP   r(   rk   rl   r8   rW   r'   r;   r?   r<   verify	hexverifyr   assertRaises
ValueErrorcopyNotImplementedErrorr%   
isinstancetypeencode)r   
result_hexr*   	wrong_macrD   h3s         r   r+   zMACSelfTest.runTest   se   T[[)
 DKKOODHH44	ahhj1-44W=q{{}M 	
	J T[[#.	*ahh	:*akk6: DKKOODHHdii?4;;?ahhj1-44W=q{{}M	$))Ct{{CABB IIfRYY[$++6 HHVQXXZ5
 	
188:tCy9:
1;;=$r(;< 	
AKKM"	AKKM((12 # 		s   ;CN 	NNNr,   r$   r	   r   rh   rh      s    ' .3r	   rh   c           
      
   g }t        t        |            D ]e  }||   }t        t        |dd       \  }	}
t        |      dk  rt	        |
      }n|d   }d||dz   |fz  }|j                  t        | ||	|
|             g d|t        |      dz   fz  }|j                  t        | |||             ||j                  t        | ||             |j                  t        | |             |j                  t        | |             |S )Nr   r7      
%s #%d: %srU   z%s #%d: digest_size)rangelenmapr   reprappendr1   r   rG   rM   r[   )rP   module_name	test_datar#   rI   r   testsirowr   r4   r   names                r   make_hash_testsr      s   E3y>" PlAa15s8a<u+Ka&K{AaC==\&$%NOP !KY!1C#DDD	LL'k<PQ
[l;<	LLv|45	LL56Lr	   c                     g }t        |      D ][  \  }}t        |      dk(  rt        |      i gz   \  }}}}	}
n|\  }}}}	}
d||dz   |	fz  }|j                  t	        | |||||
             ] |S )N   r   rU   )	enumerater   listr   rh   )rP   r   r   r   r   r   rk   rW   resultsr   rl   r   s               r   make_mac_testsr     s    EI& L3s8q=8<S	bF8J5S$f8;5S$f{AaC==[wc6JKL Lr	   )__doc__r
   r=   r   r9   Crypto.HashCryptor   r   Crypto.Util.py3compatr   r   Crypto.Util.strxorr   r   r   r   r1   rG   rM   r[   rh   r   r   r$   r	   r   <module>r      s   2 - 	 
    ' , '
7X.. 7**28$$ *2Z	*(## 	*3H%% 3>%7X&& %7P<3(## <3~ FJ!#4	r	   