Commit ea21d349 authored by Jonathan Huot's avatar Jonathan Huot Committed by Simo Sorce

Fix JWK.from_json #130

import_keyset no longer returns self.
parent 3c9000fb
......@@ -441,7 +441,8 @@ class JWK(object):
jkey = json_decode(key)
except Exception as e: # pylint: disable=broad-except
raise InvalidJWKValue(e)
return obj.import_key(**jkey)
obj.import_key(**jkey)
return obj
def export(self, private_key=True):
"""Exports the key in the standard JSON format.
......@@ -854,8 +855,6 @@ class JWKSet(dict):
else:
self[k] = v
return self
@classmethod
def from_json(cls, keyset):
"""Creates a RFC 7517 keyset from the standard JSON format.
......@@ -863,7 +862,8 @@ class JWKSet(dict):
:param keyset: The RFC 7517 representation of a JOSE Keyset.
"""
obj = cls()
return obj.import_keyset(keyset)
obj.import_keyset(keyset)
return obj
def get_key(self, kid):
"""Gets a key from the set.
......
......@@ -311,11 +311,17 @@ class TestJWK(unittest.TestCase):
self.assertRaises(jwk.InvalidJWKValue,
jwk.JWK.from_pyca, dict())
def test_jwk_from_json(self):
k = jwk.JWK.generate(kty='oct', size=256)
y = jwk.JWK.from_json(k.export())
self.assertEqual(k.export(), y.export())
def test_jwkset(self):
k = jwk.JWK(**RSAPrivateKey)
ks = jwk.JWKSet()
ks.add(k)
ks2 = jwk.JWKSet().import_keyset(ks.export())
ks2 = jwk.JWKSet()
ks2.import_keyset(ks.export())
self.assertEqual(len(ks), len(ks2))
self.assertEqual(len(ks), 1)
k1 = ks.get_key(RSAPrivateKey['kid'])
......
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