summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2020-12-16 14:24:28 -0800
committerGitHub <noreply@github.com>2020-12-16 17:24:28 -0500
commit529647ab8cfc4e05776ebd5d146db9a1f9af6ebf (patch)
tree1c9b0c5677a47acccd256d523e7846aae139f40d
parentdfbe695a92567ed19b0a6d96a89ac4cb1706d3a8 (diff)
downloadpyjwt-529647ab8cfc4e05776ebd5d146db9a1f9af6ebf.tar.gz
Remove unnecessary force_bytes() calls priot to base64url_decode() (#543)
The first line of base64url_decode() is: if isinstance(input, str): input = input.encode("ascii") It therefore accepts either str or bytes. Don't bother coercing to bytes at the call site.
-rw-r--r--jwt/algorithms.py6
-rw-r--r--tests/keys/__init__.py6
2 files changed, 6 insertions, 6 deletions
diff --git a/jwt/algorithms.py b/jwt/algorithms.py
index d4eb862..2eb090c 100644
--- a/jwt/algorithms.py
+++ b/jwt/algorithms.py
@@ -442,8 +442,8 @@ if has_crypto: # noqa: C901
if "x" not in obj or "y" not in obj:
raise InvalidKeyError("Not an Elliptic curve key")
- x = base64url_decode(force_bytes(obj.get("x")))
- y = base64url_decode(force_bytes(obj.get("y")))
+ x = base64url_decode(obj.get("x"))
+ y = base64url_decode(obj.get("y"))
curve = obj.get("crv")
if curve == "P-256":
@@ -479,7 +479,7 @@ if has_crypto: # noqa: C901
if "d" not in obj:
return public_numbers.public_key()
- d = base64url_decode(force_bytes(obj.get("d")))
+ d = base64url_decode(obj.get("d"))
if len(d) != len(x):
raise InvalidKeyError(
"D should be {} bytes for curve {}", len(x), curve
diff --git a/tests/keys/__init__.py b/tests/keys/__init__.py
index af5d83f..b615b7c 100644
--- a/tests/keys/__init__.py
+++ b/tests/keys/__init__.py
@@ -1,14 +1,14 @@
import json
import os
-from jwt.utils import base64url_decode, force_bytes
+from jwt.utils import base64url_decode
from tests.utils import int_from_bytes
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
def decode_value(val):
- decoded = base64url_decode(force_bytes(val))
+ decoded = base64url_decode(val)
return int_from_bytes(decoded, "big")
@@ -16,7 +16,7 @@ def load_hmac_key():
with open(os.path.join(BASE_PATH, "jwk_hmac.json")) as infile:
keyobj = json.load(infile)
- return base64url_decode(force_bytes(keyobj["k"]))
+ return base64url_decode(keyobj["k"])
try: