Skip to content
This repository was archived by the owner on Apr 13, 2024. It is now read-only.

Commit a639fb8

Browse files
committed
Merge branch 'hs2019-support'
2 parents 0c62e49 + f419b34 commit a639fb8

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

httpsig/sign_algorithms.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ def __init__(self, hash_algorithm=DEFAULT_HASH_ALGORITHM, salt_length=None, mgfu
3535
self.salt_length = salt_length
3636
self.mgfunc = mgfunc
3737

38-
def _create_pss(self, key, salt_length):
38+
if self.salt_length is None:
39+
self.salt_length = self.hash_algorithm.digest_size
40+
41+
def _create_pss(self, key):
3942
try:
4043
rsa_key = RSA.importKey(key)
41-
pss = PKCS1_PSS.new(rsa_key, saltLen=salt_length, mgfunc=self.mgfunc)
44+
pss = PKCS1_PSS.new(rsa_key, saltLen=self.salt_length, mgfunc=self.mgfunc)
4245
except ValueError:
4346
raise HttpSigException("Invalid key.")
4447
return pss
@@ -50,22 +53,14 @@ def sign(self, private_key, data):
5053
h = self.hash_algorithm.new()
5154
h.update(data)
5255

53-
salt_length = self.salt_length
54-
if salt_length is None:
55-
salt_length = h.digest_size
56-
57-
pss = self._create_pss(private_key, salt_length)
56+
pss = self._create_pss(private_key)
5857

5958
return pss.sign(h)
6059

6160
def verify(self, public_key, data, signature):
6261
h = self.hash_algorithm.new()
6362
h.update(data)
6463

65-
salt_length = self.salt_length
66-
if salt_length is None:
67-
salt_length = h.digest_size
68-
69-
pss = self._create_pss(public_key, salt_length)
64+
pss = self._create_pss(public_key)
7065

7166
return pss.verify(h, base64.b64decode(signature))

0 commit comments

Comments
 (0)