File tree Expand file tree Collapse file tree 2 files changed +11
-7
lines changed
Expand file tree Collapse file tree 2 files changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,6 @@ def test_bad_types(self):
4444
4545 def test_bool (self ):
4646 # Test that compare_digest returns a bool.
47- print (secrets .compare_digest ("abc" , "abc" ))
4847 self .assertIsInstance (secrets .compare_digest ("abc" , "abc" ), bool )
4948 self .assertIsInstance (secrets .compare_digest ("abc" , "xyz" ), bool )
5049
Original file line number Diff line number Diff line change @@ -307,12 +307,17 @@ pub mod _hashlib {
307307 b : ArgStrOrBytesLike ,
308308 vm : & VirtualMachine ,
309309 ) -> PyResult < PyObjectRef > {
310- if a. get_enum_int ( ) != b. get_enum_int ( ) {
311- return Err ( vm. new_type_error ( format ! (
312- "different types in compare_digest {} and {} " ,
313- a. get_enum( ) ,
314- b. get_enum( )
315- ) ) ) ;
310+
311+ fn is_str ( arg : & ArgStrOrBytesLike ) -> bool {
312+ matches ! ( arg, ArgStrOrBytesLike :: Str ( _) )
313+ }
314+
315+ if is_str ( & a) != is_str ( & b) {
316+ let err_msg = format ! (
317+ "a bytes-like object is required, not '{}'" ,
318+ b. as_object( ) . class( ) . name( )
319+ ) ;
320+ return Err ( vm. new_type_error ( err_msg) ) ;
316321 }
317322
318323 let a_hash = a. borrow_bytes ( ) . to_vec ( ) ;
You can’t perform that action at this time.
0 commit comments