Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Commit

Permalink
Rename default sign algorithm to default algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
fulder committed Aug 25, 2020
1 parent 2060e83 commit dc2b90b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions httpsig/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .sign_algorithms import SignAlgorithm
from .utils import *

DEFAULT_SIGN_ALGORITHM = "hs2019"
DEFAULT_ALGORITHM = "hs2019"


class Signer(object):
Expand All @@ -21,15 +21,15 @@ class Signer(object):

def __init__(self, secret, algorithm=None, sign_algorithm=None):
if algorithm is None:
algorithm = DEFAULT_SIGN_ALGORITHM
algorithm = DEFAULT_ALGORITHM

assert algorithm in ALGORITHMS, "Unknown algorithm"

if sign_algorithm is not None and not issubclass(type(sign_algorithm), SignAlgorithm):
raise HttpSigException("Unsupported digital signature algorithm")

if algorithm != DEFAULT_SIGN_ALGORITHM:
print("Algorithm: {} is deprecated please update to {}".format(algorithm, DEFAULT_SIGN_ALGORITHM))
if algorithm != DEFAULT_ALGORITHM:
print("Algorithm: {} is deprecated please update to {}".format(algorithm, DEFAULT_ALGORITHM))

if isinstance(secret, six.string_types):
secret = secret.encode("ascii")
Expand Down Expand Up @@ -106,7 +106,7 @@ class HeaderSigner(Signer):

def __init__(self, key_id, secret, algorithm=None, sign_algorithm=None, headers=None, sign_header='authorization'):
if algorithm is None:
algorithm = DEFAULT_SIGN_ALGORITHM
algorithm = DEFAULT_ALGORITHM

super(HeaderSigner, self).__init__(secret=secret, algorithm=algorithm, sign_algorithm=sign_algorithm)
self.headers = headers or ['date']
Expand Down
2 changes: 1 addition & 1 deletion httpsig/tests/test_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

sign.DEFAULT_SIGN_ALGORITHM = "hs2019"
sign.DEFAULT_ALGORITHM = "hs2019"


class TestSign(unittest.TestCase):
Expand Down
10 changes: 5 additions & 5 deletions httpsig/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import base64
import six

from .sign import Signer, DEFAULT_SIGN_ALGORITHM
from .sign import Signer, DEFAULT_ALGORITHM
from .sign_algorithms import SignAlgorithm
from .utils import *

Expand Down Expand Up @@ -90,10 +90,10 @@ def __init__(self, headers, secret, required_headers=None, method=None,
self.path = path
self.host = host

if self.auth_dict['algorithm'] != DEFAULT_SIGN_ALGORITHM:
print("Algorithm: {} is deprecated please update to {}".format(self.auth_dict['algorithm'], DEFAULT_SIGN_ALGORITHM))
elif self.auth_dict['algorithm'] == DEFAULT_SIGN_ALGORITHM and sign_algorithm is None:
raise HttpSigException("Required sign algorithm for {} algorithm not set".format(DEFAULT_SIGN_ALGORITHM))
if self.auth_dict['algorithm'] != DEFAULT_ALGORITHM:
print("Algorithm: {} is deprecated please update to {}".format(self.auth_dict['algorithm'], DEFAULT_ALGORITHM))
elif self.auth_dict['algorithm'] == DEFAULT_ALGORITHM and sign_algorithm is None:
raise HttpSigException("Required sign algorithm for {} algorithm not set".format(DEFAULT_ALGORITHM))

super(HeaderVerifier, self).__init__(
secret, algorithm=self.auth_dict['algorithm'], sign_algorithm=sign_algorithm)
Expand Down

0 comments on commit dc2b90b

Please sign in to comment.