Skip to content

Commit 2125695

Browse files
authored
Merge branch 'main' into kid_thumbprint
2 parents 53fd3e8 + 8cdb628 commit 2125695

File tree

12 files changed

+134
-68
lines changed

12 files changed

+134
-68
lines changed

.github/workflows/release.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66

77
jobs:
88
pypi_release:
9-
name: Build with Poetry and Publish to PyPI
9+
name: Build and Publish to PyPI
1010
runs-on: ubuntu-latest
1111
environment:
1212
name: pypi
@@ -16,9 +16,12 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v4
1818
- uses: actions/setup-python@v5
19-
- name: Install and configure Poetry
20-
run: pip install poetry
21-
- name: Publish package
22-
run: poetry build
19+
- name: Install the latest version of uv
20+
uses: astral-sh/setup-uv@v5
21+
with:
22+
version: latest
23+
enable-cache: true
24+
- name: Build package
25+
run: uv build
2326
- name: Publish package distributions to PyPI
2427
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/test.yml

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
name: Test
22

33
on:
4-
- push
5-
- pull_request
4+
pull_request:
5+
push:
6+
branches:
7+
- main
68

79
jobs:
8-
pre_job:
9-
runs-on: ubuntu-latest
10-
outputs:
11-
should_skip: ${{ steps.skip_check.outputs.should_skip }}
12-
steps:
13-
- id: skip_check
14-
uses: fkirc/skip-duplicate-actions@master
15-
with:
16-
do_not_skip: '["pull_request"]'
17-
cancel_others: 'true'
18-
concurrent_skipping: same_content
1910
ruff:
20-
needs: pre_job
2111
runs-on: ubuntu-latest
2212
steps:
2313
- uses: actions/checkout@v4
@@ -44,15 +34,14 @@ jobs:
4434
uses: actions/setup-python@v5
4535
with:
4636
python-version: ${{ matrix.python-version }}
47-
- name: Install and configure Poetry
48-
run: |
49-
pip install poetry
50-
poetry config virtualenvs.in-project true
51-
- name: Install dependencies
52-
run: poetry install
37+
- name: Install the latest version of uv
38+
uses: astral-sh/setup-uv@v5
39+
with:
40+
version: latest
41+
enable-cache: true
5342
- name: Run pytest
5443
run: |
55-
poetry run pytest -vvv -ra --cov=cryptojwt --cov-report=xml
44+
uv run pytest -vvv -ra --cov=cryptojwt --cov-report=xml
5645
- name: Upload coverage to Codecov
5746
uses: codecov/codecov-action@v4
5847
with:

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,4 @@ tests/pyoidc
137137
tests/pyoidc.pub
138138
tests/xtest_usage.py
139139

140-
# Poetry
141-
poetry.lock
140+
*.lock

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
all:
22

33
test:
4-
poetry run pytest --ruff --ruff-format --cov
4+
uv run pytest --ruff --ruff-format --cov
55

66
reformat:
7-
poetry run ruff check --select I --fix src tests
8-
poetry run ruff format src tests
7+
uv run ruff check --select I --fix src tests
8+
uv run ruff format src tests

pyproject.toml

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,51 @@
11
# PEP 518: https://www.python.org/dev/peps/pep-0518/
22

3-
[tool.poetry]
3+
[project]
44
name = "cryptojwt"
5-
version = "1.9.5"
5+
dynamic = ["version"]
66
description = "Python implementation of JWT, JWE, JWS and JWK"
7-
authors = ["Roland Hedberg <[email protected]>"]
7+
authors = [
8+
{name="Roland Hedberg", email = "[email protected]"}
9+
]
810
license = "Apache-2.0"
911
repository = "https://github.com/IdentityPython/JWTConnect-Python-CryptoJWT"
1012
readme = "README.md"
1113
packages = [
1214
{ include = "cryptojwt", from = "src" }
1315
]
16+
requires-python = ">=3.9,<4.0"
17+
dependencies = [
18+
"cryptography>=3.4.6",
19+
"requests>=2.25.1"
20+
]
1421

15-
[tool.poetry.scripts]
22+
[project.scripts]
1623
jwkgen = "cryptojwt.tools.keygen:main"
1724
jwkconv = "cryptojwt.tools.keyconv:main"
1825
jwtpeek = "cryptojwt.tools.jwtpeek:main"
1926

20-
[tool.poetry.dependencies]
21-
python = "^3.9"
22-
cryptography = ">=3.4.6"
23-
requests = "^2.25.1"
27+
[build-system]
28+
requires = ["hatchling", "uv-dynamic-versioning"]
29+
build-backend = "hatchling.build"
30+
31+
[tool.hatch.version]
32+
source = "uv-dynamic-versioning"
2433

25-
[tool.poetry.group.dev.dependencies]
26-
alabaster = "^0.7.12"
27-
pytest = "^8.2.1"
28-
pytest-cov = "^4.0.0"
29-
responses = "^0.13.0"
30-
sphinx = "^3.5.2"
31-
sphinx-autobuild = "^2021.3.14"
32-
coverage = "^7"
33-
ruff = ">=0.9.9"
34-
pytest-ruff = "^0.3.2"
34+
[tool.hatch.metadata]
35+
allow-direct-references = true
3536

36-
[build-system]
37-
requires = ["poetry-core>=1.0.0"]
38-
build-backend = "poetry.core.masonry.api"
37+
[dependency-groups]
38+
dev = [
39+
"alabaster>=0.7.12",
40+
"pytest>=8.2.1",
41+
"pytest-cov>=4.0.0",
42+
"responses>=0.13.0",
43+
"sphinx>=3.5.2",
44+
"sphinx-autobuild>=2021.3.14",
45+
"coverage>=7",
46+
"ruff>=0.9.9",
47+
"pytest-ruff>=0.3.2"
48+
]
3949

4050
[tool.coverage.run]
4151
branch = true

src/cryptojwt/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""JSON Web Token"""
22

33
import logging
4-
from importlib.metadata import version
4+
from importlib.metadata import version, PackageNotFoundError
55

66
from cryptojwt.jwe.jwe import JWE
77
from cryptojwt.jwk import JWK
@@ -13,7 +13,10 @@
1313
from .exception import BadSyntax
1414
from .utils import as_unicode, b64d, b64encode_item, split_token
1515

16-
__version__ = version("cryptojwt")
16+
try:
17+
__version__ = version("cryptojwt")
18+
except PackageNotFoundError:
19+
__version__ = "0.0.0"
1720

1821
__all__ = [
1922
"JWE",

src/cryptojwt/jwk/ec.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,20 @@ def __eq__(self, other):
243243
if self.__class__ != other.__class__:
244244
return False
245245

246+
if self.use and other.use:
247+
if self.use != other.use:
248+
return False
249+
250+
if self.kid:
251+
if other.kid:
252+
if self.kid != other.kid:
253+
return False
254+
else:
255+
return False
256+
else:
257+
if other.kid:
258+
return False
259+
246260
if cmp_keys(self.pub_key, other.pub_key, ec.EllipticCurvePublicKey):
247261
if other.private_key():
248262
if cmp_keys(self.priv_key, other.priv_key, ec.EllipticCurvePrivateKey):

src/cryptojwt/jws/pss.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ class PSSSigner(Signer):
1414
def __init__(self, algorithm="SHA256"):
1515
if algorithm == "SHA256":
1616
self.hash_algorithm = hashes.SHA256
17+
self.salt_length = 32
1718
elif algorithm == "SHA384":
1819
self.hash_algorithm = hashes.SHA384
20+
self.salt_length = 48
1921
elif algorithm == "SHA512":
2022
self.hash_algorithm = hashes.SHA512
23+
self.salt_length = 64
2124
else:
2225
raise Unsupported(f"algorithm: {algorithm}")
2326

@@ -36,7 +39,7 @@ def sign(self, msg, key):
3639
digest,
3740
padding.PSS(
3841
mgf=padding.MGF1(self.hash_algorithm()),
39-
salt_length=padding.PSS.MAX_LENGTH,
42+
salt_length=self.salt_length,
4043
),
4144
utils.Prehashed(self.hash_algorithm()),
4245
)
@@ -48,7 +51,7 @@ def verify(self, msg, signature, key):
4851
4952
:param msg: The message
5053
:param sig: A signature
51-
:param key: A ec.EllipticCurvePublicKey to use for the verification.
54+
:param key: A rsa._RSAPublicKey to use for the verification.
5255
:raises: BadSignature if the signature can't be verified.
5356
:return: True
5457
"""
@@ -58,7 +61,7 @@ def verify(self, msg, signature, key):
5861
msg,
5962
padding.PSS(
6063
mgf=padding.MGF1(self.hash_algorithm()),
61-
salt_length=padding.PSS.MAX_LENGTH,
64+
salt_length=self.salt_length,
6265
),
6366
self.hash_algorithm(),
6467
)

src/cryptojwt/key_bundle.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,23 +1134,24 @@ def sort_func(kd1, kd2):
11341134

11351135
def order_key_defs(key_def):
11361136
"""
1137-
Sort a set of key definitions. A key definition that defines more then
1138-
one usage type are splitted into as many definitions as the number of
1137+
Sort a set of key definitions. A key definition that defines more than
1138+
one usage type are split into as many definitions as the number of
11391139
usage types specified. One key definition per usage type.
11401140
1141-
:param key_def: A set of key definitions
1141+
:param key_def: A set of key definitions. List of dictionaries
11421142
:return: The set of definitions as a sorted list
11431143
"""
11441144
_int = []
11451145
# First make sure all defs only reference one usage
11461146
for _def in key_def:
1147-
if len(_def["use"]) > 1:
1148-
for _use in _def["use"]:
1149-
_kd = _def.copy()
1150-
_kd["use"] = _use
1151-
_int.append(_kd)
1152-
else:
1153-
_int.append(_def)
1147+
if isinstance(_def, dict):
1148+
if len(_def["use"]) > 1:
1149+
for _use in _def["use"]:
1150+
_kd = _def.copy()
1151+
_kd["use"] = _use
1152+
_int.append(_kd)
1153+
else:
1154+
_int.append(_def)
11541155

11551156
_int.sort(key=cmp_to_key(sort_func))
11561157

src/cryptojwt/key_jar.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,9 @@ def _add_key(
492492
if _add_keys[0] not in keys:
493493
keys.append(_add_keys[0])
494494
elif allow_missing_kid:
495-
keys.extend(_add_keys)
495+
for _key in _add_keys:
496+
if _key and _key not in keys:
497+
keys.append(_key)
496498
elif no_kid_issuer:
497499
try:
498500
allowed_kids = no_kid_issuer[issuer_id]

0 commit comments

Comments
 (0)