Skip to content

Commit

Permalink
allow salt=None again
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism committed May 18, 2021
1 parent 15a2e0d commit 41ec419
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Unreleased

- Mark top-level names as exported so type checking understands
imports in user projects. :pr:`240`
- The ``salt`` argument to ``Serializer`` and ``Signer`` can be
``None`` again. :issue:`237`


Version 2.0.0
Expand Down
9 changes: 7 additions & 2 deletions src/itsdangerous/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Serializer:
def __init__(
self,
secret_key: _t_secret_key,
salt: _t_str_bytes = b"itsdangerous",
salt: _t_opt_str_bytes = b"itsdangerous",
serializer: _t.Any = None,
serializer_kwargs: _t_opt_kwargs = None,
signer: _t.Optional[_t_signer] = None,
Expand All @@ -102,7 +102,12 @@ def __init__(
#: This allows a key rotation system to keep a list of allowed
#: keys and remove expired ones.
self.secret_keys: _t.List[bytes] = _make_keys_list(secret_key)
self.salt: bytes = want_bytes(salt)

if salt is not None:
salt = want_bytes(salt)
# if salt is None then the signer's default is used

self.salt = salt

if serializer is None:
serializer = self.default_serializer
Expand Down
9 changes: 7 additions & 2 deletions src/itsdangerous/signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Signer:
def __init__(
self,
secret_key: _t_secret_key,
salt: _t_str_bytes = b"itsdangerous.Signer",
salt: _t_opt_str_bytes = b"itsdangerous.Signer",
sep: _t_str_bytes = b".",
key_derivation: _t.Optional[str] = None,
digest_method: _t.Optional[_t.Any] = None,
Expand All @@ -141,7 +141,12 @@ def __init__(
" digits, and '-_=' must not be used."
)

self.salt: bytes = want_bytes(salt)
if salt is not None:
salt = want_bytes(salt)
else:
salt = b"itsdangerous.Signer"

self.salt = salt

if key_derivation is None:
key_derivation = self.default_key_derivation
Expand Down

0 comments on commit 41ec419

Please sign in to comment.