55from __future__ import annotations
66
77import abc
8+ import typing
89
910from cryptography .hazmat .bindings ._rust import openssl as rust_openssl
1011from cryptography .utils import Buffer
3637
3738
3839class HashAlgorithm (metaclass = abc .ABCMeta ):
40+ @abc .abstractmethod
41+ def __eq__ (self , other : typing .Any ) -> bool :
42+ """
43+ Implement equality checking.
44+ """
45+ ...
46+
3947 @property
4048 @abc .abstractmethod
4149 def name (self ) -> str :
@@ -103,66 +111,99 @@ class SHA1(HashAlgorithm):
103111 digest_size = 20
104112 block_size = 64
105113
114+ def __eq__ (self , other : typing .Any ) -> bool :
115+ return isinstance (other , SHA1 )
116+
106117
107118class SHA512_224 (HashAlgorithm ): # noqa: N801
108119 name = "sha512-224"
109120 digest_size = 28
110121 block_size = 128
111122
123+ def __eq__ (self , other : typing .Any ) -> bool :
124+ return isinstance (other , SHA512_224 )
125+
112126
113127class SHA512_256 (HashAlgorithm ): # noqa: N801
114128 name = "sha512-256"
115129 digest_size = 32
116130 block_size = 128
117131
132+ def __eq__ (self , other : typing .Any ) -> bool :
133+ return isinstance (other , SHA512_256 )
134+
118135
119136class SHA224 (HashAlgorithm ):
120137 name = "sha224"
121138 digest_size = 28
122139 block_size = 64
123140
141+ def __eq__ (self , other : typing .Any ) -> bool :
142+ return isinstance (other , SHA224 )
143+
124144
125145class SHA256 (HashAlgorithm ):
126146 name = "sha256"
127147 digest_size = 32
128148 block_size = 64
129149
150+ def __eq__ (self , other : typing .Any ) -> bool :
151+ return isinstance (other , SHA256 )
152+
130153
131154class SHA384 (HashAlgorithm ):
132155 name = "sha384"
133156 digest_size = 48
134157 block_size = 128
135158
159+ def __eq__ (self , other : typing .Any ) -> bool :
160+ return isinstance (other , SHA384 )
161+
136162
137163class SHA512 (HashAlgorithm ):
138164 name = "sha512"
139165 digest_size = 64
140166 block_size = 128
141167
168+ def __eq__ (self , other : typing .Any ) -> bool :
169+ return isinstance (other , SHA512 )
170+
142171
143172class SHA3_224 (HashAlgorithm ): # noqa: N801
144173 name = "sha3-224"
145174 digest_size = 28
146175 block_size = None
147176
177+ def __eq__ (self , other : typing .Any ) -> bool :
178+ return isinstance (other , SHA3_224 )
179+
148180
149181class SHA3_256 (HashAlgorithm ): # noqa: N801
150182 name = "sha3-256"
151183 digest_size = 32
152184 block_size = None
153185
186+ def __eq__ (self , other : typing .Any ) -> bool :
187+ return isinstance (other , SHA3_256 )
188+
154189
155190class SHA3_384 (HashAlgorithm ): # noqa: N801
156191 name = "sha3-384"
157192 digest_size = 48
158193 block_size = None
159194
195+ def __eq__ (self , other : typing .Any ) -> bool :
196+ return isinstance (other , SHA3_384 )
197+
160198
161199class SHA3_512 (HashAlgorithm ): # noqa: N801
162200 name = "sha3-512"
163201 digest_size = 64
164202 block_size = None
165203
204+ def __eq__ (self , other : typing .Any ) -> bool :
205+ return isinstance (other , SHA3_512 )
206+
166207
167208class SHAKE128 (HashAlgorithm , ExtendableOutputFunction ):
168209 name = "shake128"
@@ -177,6 +218,12 @@ def __init__(self, digest_size: int):
177218
178219 self ._digest_size = digest_size
179220
221+ def __eq__ (self , other : typing .Any ) -> bool :
222+ return (
223+ isinstance (other , SHAKE128 )
224+ and self ._digest_size == other ._digest_size
225+ )
226+
180227 @property
181228 def digest_size (self ) -> int :
182229 return self ._digest_size
@@ -195,6 +242,12 @@ def __init__(self, digest_size: int):
195242
196243 self ._digest_size = digest_size
197244
245+ def __eq__ (self , other : typing .Any ) -> bool :
246+ return (
247+ isinstance (other , SHAKE256 )
248+ and self ._digest_size == other ._digest_size
249+ )
250+
198251 @property
199252 def digest_size (self ) -> int :
200253 return self ._digest_size
@@ -205,6 +258,9 @@ class MD5(HashAlgorithm):
205258 digest_size = 16
206259 block_size = 64
207260
261+ def __eq__ (self , other : typing .Any ) -> bool :
262+ return isinstance (other , MD5 )
263+
208264
209265class BLAKE2b (HashAlgorithm ):
210266 name = "blake2b"
@@ -218,6 +274,12 @@ def __init__(self, digest_size: int):
218274
219275 self ._digest_size = digest_size
220276
277+ def __eq__ (self , other : typing .Any ) -> bool :
278+ return (
279+ isinstance (other , BLAKE2b )
280+ and self ._digest_size == other ._digest_size
281+ )
282+
221283 @property
222284 def digest_size (self ) -> int :
223285 return self ._digest_size
@@ -235,6 +297,12 @@ def __init__(self, digest_size: int):
235297
236298 self ._digest_size = digest_size
237299
300+ def __eq__ (self , other : typing .Any ) -> bool :
301+ return (
302+ isinstance (other , BLAKE2s )
303+ and self ._digest_size == other ._digest_size
304+ )
305+
238306 @property
239307 def digest_size (self ) -> int :
240308 return self ._digest_size
@@ -244,3 +312,6 @@ class SM3(HashAlgorithm):
244312 name = "sm3"
245313 digest_size = 32
246314 block_size = 64
315+
316+ def __eq__ (self , other : typing .Any ) -> bool :
317+ return isinstance (other , SM3 )
0 commit comments