KeySet objects support for filter_algorithms and guess_alg#81
KeySet objects support for filter_algorithms and guess_alg#81lepture merged 1 commit intoauthlib:mainfrom
filter_algorithms and guess_alg#81Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #81 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 47 47
Lines 2849 2856 +7
Branches 320 324 +4
=========================================
+ Hits 2849 2856 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR extends the filter_algorithms method in JWSRegistry to accept KeySet objects in addition to individual key instances, enabling convenient filtering of algorithms across multiple keys at once.
- Adds
KeySetsupport tofilter_algorithmswith recursive algorithm aggregation and deduplication - Includes comprehensive test coverage for the new functionality
- Updates documentation to reflect the API enhancement
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/joserfc/_rfc7515/registry.py | Implements KeySet handling in filter_algorithms by recursively processing each key and deduplicating results |
| tests/jws/test_registry.py | Adds test case verifying filter_algorithms works with KeySet containing multiple RSA and EC keys |
| docs/changelog.rst | Documents the new feature in the unreleased 1.x.x section |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for k in key.keys: | ||
| for alg in cls.filter_algorithms(k, names): | ||
| if alg not in rv: |
There was a problem hiding this comment.
The deduplication logic using if alg not in rv performs a linear search through the list for each algorithm, resulting in O(n²) time complexity. For KeySets with many keys, this could be inefficient. Consider using a set to track seen algorithm names and only append to rv if the algorithm name hasn't been seen yet:
if isinstance(key, KeySet):
seen_names = set()
for k in key.keys:
for alg in cls.filter_algorithms(k, names):
if alg.name not in seen_names:
seen_names.add(alg.name)
rv.append(alg)
return rv| for k in key.keys: | |
| for alg in cls.filter_algorithms(k, names): | |
| if alg not in rv: | |
| seen_names = set() | |
| for k in key.keys: | |
| for alg in cls.filter_algorithms(k, names): | |
| if alg.name not in seen_names: | |
| seen_names.add(alg.name) |
bd94a28 to
7aac8dc
Compare
filter_algorithms supports KeySet objectsfilter_algorithms and guess_alg
Another convenience PR. This makes
filter_algorithmsable to find all the algs in a KeySet andguess_algable to find the best fitting alg in the whole KeySet.