Skip to content

Commit

Permalink
fix(jwk): add __bool__ on KeySet
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Aug 6, 2023
1 parent 752fae7 commit 4d9b838
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/joserfc/_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ def __init__(self, keys: t.List[Key]):
def __iter__(self) -> t.Iterator[Key]:
return iter(self.keys)

def __bool__(self) -> bool:
return bool(self.keys)

def as_dict(self, private: t.Optional[bool] = None, **params: t.Any) -> KeySetSerialization:
keys: t.List[DictKey] = []

Expand Down
7 changes: 7 additions & 0 deletions tests/jwk/test_jwk_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,10 @@ def test_key_set_methods(self):
key_set = KeySet.generate_key_set("oct", 8, count=1)
k2 = key_set.get_by_kid()
self.assertIsInstance(k2, OctKey)

def test_key_set_bool(self):
key_set = KeySet([])
self.assertFalse(key_set)

key_set = KeySet([OctKey.generate_key()])
self.assertTrue(key_set)

0 comments on commit 4d9b838

Please sign in to comment.