Skip to content

KeySet objects support for filter_algorithms and guess_alg#81

Merged
lepture merged 1 commit intoauthlib:mainfrom
azmeuk:key-set-algs
Dec 8, 2025
Merged

KeySet objects support for filter_algorithms and guess_alg#81
lepture merged 1 commit intoauthlib:mainfrom
azmeuk:key-set-algs

Conversation

@azmeuk
Copy link
Copy Markdown
Member

@azmeuk azmeuk commented Dec 3, 2025

Another convenience PR. This makes filter_algorithms able to find all the algs in a KeySet and guess_alg able to find the best fitting alg in the whole KeySet.

Copilot AI review requested due to automatic review settings December 3, 2025 22:49
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (70deabb) to head (775d53b).
⚠️ Report is 8 commits behind head on main.

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     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 KeySet support to filter_algorithms with 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.

Comment on lines +146 to +148
for k in key.keys:
for alg in cls.filter_algorithms(k, names):
if alg not in rv:
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Suggested change
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)

Copilot uses AI. Check for mistakes.
@azmeuk azmeuk force-pushed the key-set-algs branch 2 times, most recently from bd94a28 to 7aac8dc Compare December 4, 2025 10:41
@azmeuk azmeuk changed the title filter_algorithms supports KeySet objects KeySet objects support for filter_algorithms and guess_alg Dec 4, 2025
@lepture lepture merged commit 6bcf6de into authlib:main Dec 8, 2025
11 checks passed
@azmeuk azmeuk deleted the key-set-algs branch December 8, 2025 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants