From fa9b7875c561d7bc566ebaf143805cdf747b0420 Mon Sep 17 00:00:00 2001 From: Joost Rijneveld Date: Fri, 13 Oct 2017 11:39:54 +0200 Subject: [PATCH] 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. --- rsa/pkcs1_v2.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/rsa/pkcs1_v2.py b/rsa/pkcs1_v2.py index 4ae69b3..d6d2423 100644 --- a/rsa/pkcs1_v2.py +++ b/rsa/pkcs1_v2.py @@ -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'): """ @@ -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())) ) )