@@ -216,6 +216,24 @@ def shake_constructors(self):
216216 def is_fips_mode (self ):
217217 return get_fips_mode ()
218218
219+ def match_digest (self , h1 , h2 , * , shake_size = 16 ):
220+ self .assertIs (type (h1 ), type (h2 ))
221+ self .assertEqual (h1 .name , h2 .name )
222+
223+ if h1 .name in self .shakes :
224+ d1 , h1 = h1 .digest (shake_size ), h1 .hexdigest (shake_size )
225+ d2 , h2 = h2 .digest (shake_size ), h2 .hexdigest (shake_size )
226+ else :
227+ d1 , h1 = h1 .digest (), h1 .hexdigest ()
228+ d2 , h2 = h2 .digest (), h2 .hexdigest ()
229+
230+ self .assertIsInstance (d1 , bytes )
231+ self .assertIsInstance (h1 , str )
232+ self .assertEqual (d1 .hex (), h1 )
233+
234+ self .assertEqual (d1 , d2 )
235+ self .assertEqual (h1 , h2 )
236+
219237 def test_hash_array (self ):
220238 a = array .array ("b" , range (10 ))
221239 for cons in self .hash_constructors :
@@ -371,6 +389,14 @@ def test_get_builtin_constructor(self):
371389 self .assertIs (constructor , _md5 .md5 )
372390 self .assertEqual (sorted (builtin_constructor_cache ), ['MD5' , 'md5' ])
373391
392+ def test_copy (self ):
393+ for cons in self .hash_constructors :
394+ h1 = cons (usedforsecurity = False )
395+ h1 .update (os .urandom (16 ))
396+ h2 = h1 .copy ()
397+ self .assertIs (type (h1 ), type (h2 ))
398+ self .match_digest (h1 , h2 )
399+
374400 def test_hexdigest (self ):
375401 for cons in self .hash_constructors :
376402 h = cons (usedforsecurity = False )
0 commit comments