Skip to content

Commit

Permalink
Merge pull request #117 from IdentityPython/arg_info-key_import
Browse files Browse the repository at this point in the history
key_import and alg_info
  • Loading branch information
rohe authored Jan 24, 2025
2 parents 82b6e8f + 421e211 commit fd283e2
Show file tree
Hide file tree
Showing 42 changed files with 617 additions and 713 deletions.
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

0 comments on commit fd283e2

Please sign in to comment.