Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

key_import and alg_info #117

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/oauth2_add_on_dpop.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from common import KEYDEFS
from common import full_path
from flow import Flow
from idpyoidc.metadata import get_signing_algs
from idpyoidc.alg_info import get_signing_algs
from idpyoidc.client.oauth2 import Client
from idpyoidc.server import Server
from idpyoidc.server.configure import ASConfiguration
Expand Down
127 changes: 0 additions & 127 deletions private/xmetadata/oidc.py

This file was deleted.

4 changes: 2 additions & 2 deletions src/idpyoidc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__author__ = "Roland Hedberg"
__version__ = "4.3.0"
__version__ = "5.0.0"

VERIFIED_CLAIM_PREFIX = "__verified"

Expand All @@ -10,7 +10,7 @@ def verified_claim_name(claim):

def proper_path(path):
"""
Clean up the path specification so it looks like something I could use.
Clean up the path specification such that it looks like something I could use.
"./" <path> "/"
"""
if path.startswith("./"):
Expand Down
67 changes: 67 additions & 0 deletions src/idpyoidc/alg_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from functools import cmp_to_key
import logging

from cryptojwt.jwe import DEPRECATED
from cryptojwt.jwe import SUPPORTED
from cryptojwt.jws.jws import SIGNER_ALGS

logger = logging.getLogger(__name__)

SIGNING_ALGORITHM_SORT_ORDER = ["RS", "ES", "PS", "HS", "Ed"]


def cmp(a, b):
return (a > b) - (a < b)


def alg_cmp(a, b):
if a == "none":
return 1
elif b == "none":
return -1

_pos1 = SIGNING_ALGORITHM_SORT_ORDER.index(a[0:2])
_pos2 = SIGNING_ALGORITHM_SORT_ORDER.index(b[0:2])
if _pos1 == _pos2:
return (a > b) - (a < b)
elif _pos1 > _pos2:
return 1
else:
return -1


def get_signing_algs():
# Assumes Cryptojwt
_algs = [name for name in list(SIGNER_ALGS.keys()) if name != "none" and name not in DEPRECATED["alg"]]
return sorted(_algs, key=cmp_to_key(alg_cmp))


def get_encryption_algs():
return SUPPORTED["alg"]


def get_encryption_encs():
return SUPPORTED["enc"]


def array_or_singleton(claim_spec, values):
if isinstance(claim_spec[0], list):
if isinstance(values, list):
return values
else:
return [values]
else:
if isinstance(values, list):
return values[0]
else: # singleton
return values


def is_subset(a, b):
if isinstance(a, list):
if isinstance(b, list):
return set(b).issubset(set(a))
elif isinstance(b, list):
return a in b
else:
return a == b
Loading
Loading