55from Crypto .Hash import HMAC
66from Crypto .PublicKey import RSA
77from Crypto .Signature import PKCS1_v1_5
8- from .sign_algorithms import SIGN_ALGORITHMS
8+ from .sign_algorithms import SignAlgorithm
99from .utils import *
1010
1111DEFAULT_SIGN_ALGORITHM = "hs2019"
@@ -19,15 +19,12 @@ class Signer(object):
1919 Password-protected keyfiles are not supported.
2020 """
2121
22- def __init__ (self , secret , algorithm = None , sign_algorithm = None ):
22+ def __init__ (self , secret , algorithm = None , sign_algorithm : SignAlgorithm = None ):
2323 if algorithm is None :
2424 algorithm = DEFAULT_SIGN_ALGORITHM
2525
2626 assert algorithm in ALGORITHMS , "Unknown algorithm"
2727
28- if sign_algorithm is not None and sign_algorithm .__class__ .__name__ not in SIGN_ALGORITHMS :
29- raise HttpSigException ("Unsupported digital signature algorithm" )
30-
3128 if algorithm != DEFAULT_SIGN_ALGORITHM :
3229 print ("Algorithm: {} is deprecated please update to {}" .format (algorithm , DEFAULT_SIGN_ALGORITHM ))
3330
@@ -79,7 +76,7 @@ def sign(self, data):
7976 signed = self ._sign_rsa (data )
8077 elif self ._hash :
8178 signed = self ._sign_hmac (data )
82- elif self .sign_algorithm . __class__ . __name__ in SIGN_ALGORITHMS :
79+ elif isinstance ( self .sign_algorithm , SignAlgorithm ) :
8380 signed = self .sign_algorithm .sign (self .secret , data )
8481 if not signed :
8582 raise SystemError ('No valid encryptor found.' )
@@ -98,7 +95,6 @@ class HeaderSigner(Signer):
9895 match the algorithm)
9996 :param algorithm: one of the seven specified algorithms
10097 :param sign_algorithm: required for 'hs2019' algorithm. Sign algorithm for the secret
101- :param sign_algorithm: Custom salt length for 'hs2019' and 'PSS' sign algorithm.
10298 :param headers: a list of http headers to be included in the signing
10399 string, defaulting to ['date'].
104100 :param sign_header: header used to include signature, defaulting to
0 commit comments