Skip to content

Commit fa9b787

Browse files
joostrijneveldsybrenstuvel
authored andcommitted
Remove duplicate hash method definition
There is no need to specify this list in PKCS1_v2 when it is already specified in PKCS1. This does rely on the digest_size attribute being available, but pkcs1.py already depends heavily on the specific API of hashlib.
1 parent 2c1d512 commit fa9b787

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

rsa/pkcs1_v2.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@
2727
transform,
2828
)
2929

30-
HASH_METHOD_TO_BYTE_LENGTH = {
31-
'MD5': 16,
32-
'SHA-1': 20,
33-
'SHA-256': 28,
34-
'SHA-384': 48,
35-
'SHA-512': 64,
36-
}
37-
3830

3931
def mgf1(seed, length, hasher='SHA-1'):
4032
"""
@@ -59,11 +51,11 @@ def mgf1(seed, length, hasher='SHA-1'):
5951
"""
6052

6153
try:
62-
hash_length = HASH_METHOD_TO_BYTE_LENGTH[hasher]
54+
hash_length = pkcs1.HASH_METHODS[hasher]().digest_size
6355
except KeyError:
6456
raise ValueError(
6557
'Invalid `hasher` specified. Please select one of: {hash_list}'.format(
66-
hash_list=', '.join(sorted(HASH_METHOD_TO_BYTE_LENGTH.keys()))
58+
hash_list=', '.join(sorted(pkcs1.HASH_METHODS.keys()))
6759
)
6860
)
6961

0 commit comments

Comments
 (0)