5
5
from __future__ import annotations
6
6
7
7
import abc
8
+ import typing
8
9
9
10
from cryptography .hazmat .bindings ._rust import openssl as rust_openssl
10
11
from cryptography .utils import Buffer
36
37
37
38
38
39
class HashAlgorithm (metaclass = abc .ABCMeta ):
40
+ @abc .abstractmethod
41
+ def __eq__ (self , other : typing .Any ) -> bool :
42
+ """
43
+ Implement equality checking.
44
+ """
45
+ ...
46
+
39
47
@property
40
48
@abc .abstractmethod
41
49
def name (self ) -> str :
@@ -103,66 +111,99 @@ class SHA1(HashAlgorithm):
103
111
digest_size = 20
104
112
block_size = 64
105
113
114
+ def __eq__ (self , other : typing .Any ) -> bool :
115
+ return isinstance (other , SHA1 )
116
+
106
117
107
118
class SHA512_224 (HashAlgorithm ): # noqa: N801
108
119
name = "sha512-224"
109
120
digest_size = 28
110
121
block_size = 128
111
122
123
+ def __eq__ (self , other : typing .Any ) -> bool :
124
+ return isinstance (other , SHA512_224 )
125
+
112
126
113
127
class SHA512_256 (HashAlgorithm ): # noqa: N801
114
128
name = "sha512-256"
115
129
digest_size = 32
116
130
block_size = 128
117
131
132
+ def __eq__ (self , other : typing .Any ) -> bool :
133
+ return isinstance (other , SHA512_256 )
134
+
118
135
119
136
class SHA224 (HashAlgorithm ):
120
137
name = "sha224"
121
138
digest_size = 28
122
139
block_size = 64
123
140
141
+ def __eq__ (self , other : typing .Any ) -> bool :
142
+ return isinstance (other , SHA224 )
143
+
124
144
125
145
class SHA256 (HashAlgorithm ):
126
146
name = "sha256"
127
147
digest_size = 32
128
148
block_size = 64
129
149
150
+ def __eq__ (self , other : typing .Any ) -> bool :
151
+ return isinstance (other , SHA256 )
152
+
130
153
131
154
class SHA384 (HashAlgorithm ):
132
155
name = "sha384"
133
156
digest_size = 48
134
157
block_size = 128
135
158
159
+ def __eq__ (self , other : typing .Any ) -> bool :
160
+ return isinstance (other , SHA384 )
161
+
136
162
137
163
class SHA512 (HashAlgorithm ):
138
164
name = "sha512"
139
165
digest_size = 64
140
166
block_size = 128
141
167
168
+ def __eq__ (self , other : typing .Any ) -> bool :
169
+ return isinstance (other , SHA512 )
170
+
142
171
143
172
class SHA3_224 (HashAlgorithm ): # noqa: N801
144
173
name = "sha3-224"
145
174
digest_size = 28
146
175
block_size = None
147
176
177
+ def __eq__ (self , other : typing .Any ) -> bool :
178
+ return isinstance (other , SHA3_224 )
179
+
148
180
149
181
class SHA3_256 (HashAlgorithm ): # noqa: N801
150
182
name = "sha3-256"
151
183
digest_size = 32
152
184
block_size = None
153
185
186
+ def __eq__ (self , other : typing .Any ) -> bool :
187
+ return isinstance (other , SHA3_256 )
188
+
154
189
155
190
class SHA3_384 (HashAlgorithm ): # noqa: N801
156
191
name = "sha3-384"
157
192
digest_size = 48
158
193
block_size = None
159
194
195
+ def __eq__ (self , other : typing .Any ) -> bool :
196
+ return isinstance (other , SHA3_384 )
197
+
160
198
161
199
class SHA3_512 (HashAlgorithm ): # noqa: N801
162
200
name = "sha3-512"
163
201
digest_size = 64
164
202
block_size = None
165
203
204
+ def __eq__ (self , other : typing .Any ) -> bool :
205
+ return isinstance (other , SHA3_512 )
206
+
166
207
167
208
class SHAKE128 (HashAlgorithm , ExtendableOutputFunction ):
168
209
name = "shake128"
@@ -177,6 +218,12 @@ def __init__(self, digest_size: int):
177
218
178
219
self ._digest_size = digest_size
179
220
221
+ def __eq__ (self , other : typing .Any ) -> bool :
222
+ return (
223
+ isinstance (other , SHAKE128 )
224
+ and self ._digest_size == other ._digest_size
225
+ )
226
+
180
227
@property
181
228
def digest_size (self ) -> int :
182
229
return self ._digest_size
@@ -195,6 +242,12 @@ def __init__(self, digest_size: int):
195
242
196
243
self ._digest_size = digest_size
197
244
245
+ def __eq__ (self , other : typing .Any ) -> bool :
246
+ return (
247
+ isinstance (other , SHAKE256 )
248
+ and self ._digest_size == other ._digest_size
249
+ )
250
+
198
251
@property
199
252
def digest_size (self ) -> int :
200
253
return self ._digest_size
@@ -205,6 +258,9 @@ class MD5(HashAlgorithm):
205
258
digest_size = 16
206
259
block_size = 64
207
260
261
+ def __eq__ (self , other : typing .Any ) -> bool :
262
+ return isinstance (other , MD5 )
263
+
208
264
209
265
class BLAKE2b (HashAlgorithm ):
210
266
name = "blake2b"
@@ -218,6 +274,12 @@ def __init__(self, digest_size: int):
218
274
219
275
self ._digest_size = digest_size
220
276
277
+ def __eq__ (self , other : typing .Any ) -> bool :
278
+ return (
279
+ isinstance (other , BLAKE2b )
280
+ and self ._digest_size == other ._digest_size
281
+ )
282
+
221
283
@property
222
284
def digest_size (self ) -> int :
223
285
return self ._digest_size
@@ -235,6 +297,12 @@ def __init__(self, digest_size: int):
235
297
236
298
self ._digest_size = digest_size
237
299
300
+ def __eq__ (self , other : typing .Any ) -> bool :
301
+ return (
302
+ isinstance (other , BLAKE2s )
303
+ and self ._digest_size == other ._digest_size
304
+ )
305
+
238
306
@property
239
307
def digest_size (self ) -> int :
240
308
return self ._digest_size
@@ -244,3 +312,6 @@ class SM3(HashAlgorithm):
244
312
name = "sm3"
245
313
digest_size = 32
246
314
block_size = 64
315
+
316
+ def __eq__ (self , other : typing .Any ) -> bool :
317
+ return isinstance (other , SM3 )
0 commit comments