Commit 68bac873 authored by Christian Heimes's avatar Christian Heimes Committed by Christian Heimes

Remove unnecessary calls to str()

json_decode() returns str instances for str values anyway. In case the
JSON payload contains invalid types, base64 codec will fail with an
appropriate error message.

'some.string'.split('.') returns a list of str.
Signed-off-by: 's avatarChristian Heimes <cheimes@redhat.com>
parent 323327b6
...@@ -423,30 +423,30 @@ class JWE(object): ...@@ -423,30 +423,30 @@ class JWE(object):
try: try:
try: try:
djwe = json_decode(raw_jwe) djwe = json_decode(raw_jwe)
o['iv'] = base64url_decode(str(djwe['iv'])) o['iv'] = base64url_decode(djwe['iv'])
o['ciphertext'] = base64url_decode(str(djwe['ciphertext'])) o['ciphertext'] = base64url_decode(djwe['ciphertext'])
o['tag'] = base64url_decode(str(djwe['tag'])) o['tag'] = base64url_decode(djwe['tag'])
if 'protected' in djwe: if 'protected' in djwe:
p = base64url_decode(str(djwe['protected'])) p = base64url_decode(djwe['protected'])
o['protected'] = p.decode('utf-8') o['protected'] = p.decode('utf-8')
if 'unprotected' in djwe: if 'unprotected' in djwe:
o['unprotected'] = json_encode(djwe['unprotected']) o['unprotected'] = json_encode(djwe['unprotected'])
if 'aad' in djwe: if 'aad' in djwe:
o['aad'] = base64url_decode(str(djwe['aad'])) o['aad'] = base64url_decode(djwe['aad'])
if 'recipients' in djwe: if 'recipients' in djwe:
o['recipients'] = list() o['recipients'] = list()
for rec in djwe['recipients']: for rec in djwe['recipients']:
e = dict() e = dict()
if 'encrypted_key' in rec: if 'encrypted_key' in rec:
e['encrypted_key'] = \ e['encrypted_key'] = \
base64url_decode(str(rec['encrypted_key'])) base64url_decode(rec['encrypted_key'])
if 'header' in rec: if 'header' in rec:
e['header'] = json_encode(rec['header']) e['header'] = json_encode(rec['header'])
o['recipients'].append(e) o['recipients'].append(e)
else: else:
if 'encrypted_key' in djwe: if 'encrypted_key' in djwe:
o['encrypted_key'] = \ o['encrypted_key'] = \
base64url_decode(str(djwe['encrypted_key'])) base64url_decode(djwe['encrypted_key'])
if 'header' in djwe: if 'header' in djwe:
o['header'] = json_encode(djwe['header']) o['header'] = json_encode(djwe['header'])
...@@ -454,14 +454,14 @@ class JWE(object): ...@@ -454,14 +454,14 @@ class JWE(object):
c = raw_jwe.split('.') c = raw_jwe.split('.')
if len(c) != 5: if len(c) != 5:
raise InvalidJWEData() raise InvalidJWEData()
p = base64url_decode(str(c[0])) p = base64url_decode(c[0])
o['protected'] = p.decode('utf-8') o['protected'] = p.decode('utf-8')
ekey = base64url_decode(str(c[1])) ekey = base64url_decode(c[1])
if ekey != b'': if ekey != b'':
o['encrypted_key'] = base64url_decode(str(c[1])) o['encrypted_key'] = base64url_decode(c[1])
o['iv'] = base64url_decode(str(c[2])) o['iv'] = base64url_decode(c[2])
o['ciphertext'] = base64url_decode(str(c[3])) o['ciphertext'] = base64url_decode(c[3])
o['tag'] = base64url_decode(str(c[4])) o['tag'] = base64url_decode(c[4])
self.objects = o self.objects = o
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment