Commit 0ff425e4 authored by Simo Sorce's avatar Simo Sorce Committed by Simo Sorce

Make the default iterator return keys directly

It has no value to return the 'keys' attribute itself, instead we now
we return the inner 'keys' object iterator when the JWKSet is iterated
This way iterating over the JWKSet object returns its JWK objects.
Signed-off-by: 's avatarSimo Sorce <>

Fixes #117
parent 4f3ae07c
...@@ -756,6 +756,12 @@ class JWKSet(dict): ...@@ -756,6 +756,12 @@ class JWKSet(dict):
super(JWKSet, self).__setitem__('keys', _JWKkeys()) super(JWKSet, self).__setitem__('keys', _JWKkeys())
self.update(*args, **kwargs) self.update(*args, **kwargs)
def __iter__(self):
return self['keys'].__iter__()
def __contains__(self, key):
return self['keys'].__contains__(key)
def __setitem__(self, key, val): def __setitem__(self, key, val):
if key == 'keys': if key == 'keys':
self['keys'].add(val) self['keys'].add(val)
...@@ -328,6 +328,15 @@ class TestJWK(unittest.TestCase): ...@@ -328,6 +328,15 @@ class TestJWK(unittest.TestCase):
ks3 = jwk.JWKSet.from_json(ks.export()) ks3 = jwk.JWKSet.from_json(ks.export())
self.assertEqual(len(ks), len(ks3)) self.assertEqual(len(ks), len(ks3))
# Test Keyset with mutiple keys
ksm = jwk.JWKSet.from_json(json_encode(PrivateKeys))
num = 0
for item in ksm:
self.assertTrue(isinstance(item, jwk.JWK))
self.assertTrue(item in ksm)
num += 1
self.assertEqual(num, len(PrivateKeys['keys']))
def test_thumbprint(self): def test_thumbprint(self):
for i in range(0, len(PublicKeys['keys'])): for i in range(0, len(PublicKeys['keys'])):
k = jwk.JWK(**PublicKeys['keys'][i]) k = jwk.JWK(**PublicKeys['keys'][i])
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