Skip to content

Commit

Permalink
Remove duplicate hash method definition
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joostrijneveld authored and sybrenstuvel committed Feb 5, 2018
1 parent 2c1d512 commit fa9b787
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions rsa/pkcs1_v2.py
Expand Up @@ -27,14 +27,6 @@
transform,
)

HASH_METHOD_TO_BYTE_LENGTH = {
'MD5': 16,
'SHA-1': 20,
'SHA-256': 28,
'SHA-384': 48,
'SHA-512': 64,
}


def mgf1(seed, length, hasher='SHA-1'):
"""
Expand All @@ -59,11 +51,11 @@ def mgf1(seed, length, hasher='SHA-1'):
"""

try:
hash_length = HASH_METHOD_TO_BYTE_LENGTH[hasher]
hash_length = pkcs1.HASH_METHODS[hasher]().digest_size
except KeyError:
raise ValueError(
'Invalid `hasher` specified. Please select one of: {hash_list}'.format(
hash_list=', '.join(sorted(HASH_METHOD_TO_BYTE_LENGTH.keys()))
hash_list=', '.join(sorted(pkcs1.HASH_METHODS.keys()))
)
)

Expand Down

0 comments on commit fa9b787

Please sign in to comment.