Skip to content

Commit 1e2af19

Browse files
committed
Added UnicodeDecodeError catch to as_bytes and as_unicode
1 parent e01e7aa commit 1e2af19

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/jwkest/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def as_bytes(s):
207207
"""
208208
try:
209209
s = s.encode()
210-
except AttributeError:
210+
except (AttributeError, UnicodeDecodeError):
211211
pass
212212
return s
213213

@@ -220,6 +220,6 @@ def as_unicode(b):
220220
"""
221221
try:
222222
b = b.decode()
223-
except AttributeError:
223+
except (AttributeError, UnicodeDecodeError):
224224
pass
225225
return b

tests/test_3_jws.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ def test_hmac_from_keyrep():
133133

134134

135135
def test_left_hash_hs256():
136-
hsh = jws.left_hash(b'Please take a moment to register today')
137-
assert hsh == b'rCFHVJuxTqRxOsn2IUzgvA'
136+
hsh = jws.left_hash('Please take a moment to register today')
137+
assert hsh == 'rCFHVJuxTqRxOsn2IUzgvA'
138138

139139

140140
def test_left_hash_hs512():
141-
hsh = jws.left_hash(b'Please take a moment to register today', "HS512")
142-
assert hsh == b'_h6feWLt8zbYcOFnaBmekTzMJYEHdVTaXlDgJSWsEeY'
141+
hsh = jws.left_hash('Please take a moment to register today', "HS512")
142+
assert hsh == '_h6feWLt8zbYcOFnaBmekTzMJYEHdVTaXlDgJSWsEeY'
143143

144144

145145
def test_rs256():

0 commit comments

Comments
 (0)