summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2020-12-21 07:57:45 -0800
committerGitHub <noreply@github.com>2020-12-21 10:57:45 -0500
commitb0c1e60be6b3b7b555eb46d947dd859f5d0c70e2 (patch)
treeb795e9ebb36d06146bcbd77022b578dd3017f439
parent5d7bdd68aec70a8a8cc4979bda93adc3c44f945f (diff)
downloadpyjwt-b0c1e60be6b3b7b555eb46d947dd859f5d0c70e2.tar.gz
Simplify from_base64url_uint() (#570)
int.from_bytes() has been available since Python 3.2. Using it avoids string formatting.
-rw-r--r--jwt/utils.py5
1 files changed, 1 insertions, 4 deletions
diff --git a/jwt/utils.py b/jwt/utils.py
index 6a09dcf..8e6cf60 100644
--- a/jwt/utils.py
+++ b/jwt/utils.py
@@ -1,6 +1,5 @@
import base64
import binascii
-import struct
from typing import Any, Union
try:
@@ -55,9 +54,7 @@ def from_base64url_uint(val: Union[str, bytes]) -> int:
val = val.encode("ascii")
data = base64url_decode(val)
-
- buf = struct.unpack("%sB" % len(data), data)
- return int("".join(["%02x" % byte for byte in buf]), 16)
+ return int.from_bytes(data, byteorder="big")
def number_to_bytes(num: int, num_bytes: int) -> bytes: