@@ -166,27 +166,34 @@ def __init__(self, hash_type: HashTypes):
166166 from dirty_equals import IsHash
167167
168168 assert 'f1e069787ece74531d112559945c6871' == IsHash('md5')
169+ assert b'f1e069787ece74531d112559945c6871' == IsHash('md5')
169170 assert 'f1e069787ece74531d112559945c6871' != IsHash('sha-256')
170171 assert 'F1E069787ECE74531D112559945C6871' == IsHash('md5')
171172 assert '40bd001563085fc35165329ea1ff5c5ecbdbbeef' == IsHash('sha-1')
172173 assert 'a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3' == IsHash('sha-256')
173174 ```
174175 """
175176
176- allowed_hashes = 'md5' , 'sha-1' , 'sha-256'
177- if hash_type not in HashTypes . __args__ : # type: ignore[attr-defined]
177+ allowed_hashes = HashTypes . __args__ # type: ignore[attr-defined]
178+ if hash_type not in allowed_hashes :
178179 raise ValueError (f"Hash type must be one of the following values: { ', ' .join (allowed_hashes )} " )
179180
180181 self .hash_type = hash_type
181182 super ().__init__ (hash_type )
182183
183184 def equals (self , other : Any ) -> bool :
185+ if isinstance (other , str ):
186+ s = other
187+ elif isinstance (other , (bytes , bytearray )):
188+ s = other .decode ()
189+ else :
190+ return False
184191 hash_type_regex_patterns = {
185192 'md5' : r'[a-fA-F\d]{32}' ,
186193 'sha-1' : r'[a-fA-F\d]{40}' ,
187194 'sha-256' : r'[a-fA-F\d]{64}' ,
188195 }
189- return bool (re .fullmatch (hash_type_regex_patterns [self .hash_type ], other ))
196+ return bool (re .fullmatch (hash_type_regex_patterns [self .hash_type ], s ))
190197
191198
192199IP = TypeVar ('IP' , IPv4Address , IPv4Network , IPv6Address , IPv6Network , Union [str , int , bytes ])
0 commit comments