Skip to content

Commit 5d5bf58

Browse files
author
Rebecka Gulliksson
committed
Fixed base64_to_long to support getting unicode data.
1 parent 289edfc commit 5d5bf58

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/jwkest/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import re
55
import struct
6+
import six
67

78
try:
89
from builtins import zip
@@ -107,8 +108,9 @@ def long_to_base64(n):
107108

108109

109110
def base64_to_long(data):
110-
# if isinstance(data, str):
111-
# data = bytes(data)
111+
if isinstance(data, six.text_type):
112+
data = data.encode("ascii")
113+
112114
# urlsafe_b64decode will happily convert b64encoded data
113115
_d = base64.urlsafe_b64decode(bytes(data) + b'==')
114116
return intarr2long(struct.unpack('%sB' % len(_d), _d))

tests/test_2_jwk.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ def full_path(local_file):
3131
CERT = full_path("cert.pem")
3232
KEY = full_path("server.key")
3333

34-
N = b'wf-wiusGhA-gleZYQAOPQlNUIucPiqXdPVyieDqQbXXOPBe3nuggtVzeq7pVFH1dZz4dY2Q2LA5DaegvP8kRvoSB_87ds3dy3Rfym_GUSc5B0l1TgEobcyaep8jguRoHto6GWHfCfKqoUYZq4N8vh4LLMQwLR6zi6Jtu82nB5k8'
35-
E = b'AQAB'
34+
N = 'wf-wiusGhA-gleZYQAOPQlNUIucPiqXdPVyieDqQbXXOPBe3nuggtVzeq7pVFH1dZz4dY2Q2LA5DaegvP8kRvoSB_87ds3dy3Rfym_GUSc5B0l1TgEobcyaep8jguRoHto6GWHfCfKqoUYZq4N8vh4LLMQwLR6zi6Jtu82nB5k8'
35+
E = 'AQAB'
3636

3737
JWK = {"keys": [
38-
{'kty': 'RSA', 'use': 'foo', 'e': E.decode("utf-8"), 'kid': "abc",
39-
'n': N.decode("utf8")}
38+
{'kty': 'RSA', 'use': 'foo', 'e': E, 'kid': "abc",
39+
'n': N}
4040
]}
4141

4242

0 commit comments

Comments
 (0)