diff options
author | Jon Dufresne <jon.dufresne@gmail.com> | 2020-12-21 07:57:45 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-21 10:57:45 -0500 |
commit | b0c1e60be6b3b7b555eb46d947dd859f5d0c70e2 (patch) | |
tree | b795e9ebb36d06146bcbd77022b578dd3017f439 | |
parent | 5d7bdd68aec70a8a8cc4979bda93adc3c44f945f (diff) | |
download | pyjwt-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.py | 5 |
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: |