pyjosers 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. pyjosers-0.1.0/.github/workflows/ci.yml +90 -0
  2. pyjosers-0.1.0/.github/workflows/release.yml +71 -0
  3. pyjosers-0.1.0/.github/workflows/wheels.yml +138 -0
  4. pyjosers-0.1.0/.gitignore +8 -0
  5. pyjosers-0.1.0/.readthedocs.yaml +14 -0
  6. pyjosers-0.1.0/AGENTS.md +43 -0
  7. pyjosers-0.1.0/CHANGELOG.md +22 -0
  8. pyjosers-0.1.0/Cargo.lock +1709 -0
  9. pyjosers-0.1.0/Cargo.toml +27 -0
  10. pyjosers-0.1.0/LICENSE +24 -0
  11. pyjosers-0.1.0/PKG-INFO +50 -0
  12. pyjosers-0.1.0/README.md +26 -0
  13. pyjosers-0.1.0/build-wheels.sh +12 -0
  14. pyjosers-0.1.0/docs/algorithms.rst +94 -0
  15. pyjosers-0.1.0/docs/api.rst +62 -0
  16. pyjosers-0.1.0/docs/conf.py +10 -0
  17. pyjosers-0.1.0/docs/development.rst +102 -0
  18. pyjosers-0.1.0/docs/encryption.rst +80 -0
  19. pyjosers-0.1.0/docs/exceptions.rst +56 -0
  20. pyjosers-0.1.0/docs/hsm.rst +59 -0
  21. pyjosers-0.1.0/docs/index.rst +41 -0
  22. pyjosers-0.1.0/docs/installation.rst +59 -0
  23. pyjosers-0.1.0/docs/keys.rst +94 -0
  24. pyjosers-0.1.0/docs/migration.rst +179 -0
  25. pyjosers-0.1.0/docs/quickstart.rst +52 -0
  26. pyjosers-0.1.0/docs/signatures.rst +109 -0
  27. pyjosers-0.1.0/docs/tokens.rst +134 -0
  28. pyjosers-0.1.0/examples/federation.py +21 -0
  29. pyjosers-0.1.0/examples/nested.py +10 -0
  30. pyjosers-0.1.0/pyproject.toml +35 -0
  31. pyjosers-0.1.0/python/pyjosers/__init__.py +12 -0
  32. pyjosers-0.1.0/python/pyjosers/_native.pyi +50 -0
  33. pyjosers-0.1.0/python/pyjosers/algorithms.py +13 -0
  34. pyjosers-0.1.0/python/pyjosers/common.py +70 -0
  35. pyjosers-0.1.0/python/pyjosers/hsm.py +7 -0
  36. pyjosers-0.1.0/python/pyjosers/jwe.py +137 -0
  37. pyjosers-0.1.0/python/pyjosers/jwk.py +255 -0
  38. pyjosers-0.1.0/python/pyjosers/jws.py +266 -0
  39. pyjosers-0.1.0/python/pyjosers/jwt.py +308 -0
  40. pyjosers-0.1.0/python/pyjosers/py.typed +0 -0
  41. pyjosers-0.1.0/python/pyjosers/x509.py +27 -0
  42. pyjosers-0.1.0/src/hsm.rs +174 -0
  43. pyjosers-0.1.0/src/lib.rs +404 -0
  44. pyjosers-0.1.0/tests/conftest.py +20 -0
  45. pyjosers-0.1.0/tests/test_admin_checkout.py +40 -0
  46. pyjosers-0.1.0/tests/test_admin_migration.py +44 -0
  47. pyjosers-0.1.0/tests/test_header_policy.py +165 -0
  48. pyjosers-0.1.0/tests/test_hsm.py +72 -0
  49. pyjosers-0.1.0/tests/test_interop.py +86 -0
  50. pyjosers-0.1.0/tests/test_jose.py +294 -0
  51. pyjosers-0.1.0/tests/test_pss_import.py +37 -0
@@ -0,0 +1,90 @@
1
+ name: Tests, wheels and documentation
2
+
3
+ on:
4
+ push:
5
+ branches: ['**']
6
+ pull_request:
7
+ workflow_dispatch:
8
+ workflow_call:
9
+ inputs:
10
+ retention-days:
11
+ type: number
12
+ default: 1
13
+
14
+ permissions:
15
+ contents: read
16
+
17
+ env:
18
+ FORCE_COLOR: "1"
19
+ UV_LINK_MODE: "copy"
20
+
21
+ jobs:
22
+ test:
23
+ runs-on: ubuntu-latest
24
+ timeout-minutes: 30
25
+ strategy:
26
+ fail-fast: false
27
+ matrix:
28
+ python: ['3.10', '3.14']
29
+ steps:
30
+ - uses: actions/checkout@v7
31
+ - uses: actions/setup-python@v7
32
+ with:
33
+ python-version: ${{ matrix.python }}
34
+ - uses: dtolnay/rust-toolchain@stable
35
+ with:
36
+ components: rustfmt, clippy
37
+ - name: Install SoftHSM and OpenSC
38
+ run: sudo apt-get update && sudo apt-get install -y softhsm2 opensc
39
+ - name: Install development dependencies
40
+ run: |
41
+ python -m pip install --upgrade uv
42
+ uv pip install --system -e '.[dev]'
43
+ - name: Check Rust formatting and linting
44
+ if: matrix.python == '3.14'
45
+ run: |
46
+ cargo fmt --check
47
+ cargo clippy --locked --all-features -- -D warnings
48
+ - name: Run tests
49
+ run: python -m pytest -q
50
+ - name: Build strict documentation and run examples
51
+ if: matrix.python == '3.14'
52
+ run: |
53
+ sphinx-build -W --keep-going -b html docs docs/_build/html
54
+ sphinx-build -W -b doctest docs docs/_build/doctest
55
+
56
+ features:
57
+ runs-on: ubuntu-latest
58
+ timeout-minutes: 30
59
+ strategy:
60
+ fail-fast: false
61
+ matrix:
62
+ include:
63
+ - name: minimal
64
+ args: --no-default-features
65
+ - name: legacy
66
+ args: --features legacy
67
+ name: Feature tests (${{ matrix.name }})
68
+ steps:
69
+ - uses: actions/checkout@v7
70
+ - uses: actions/setup-python@v7
71
+ with:
72
+ python-version: '3.14'
73
+ - uses: dtolnay/rust-toolchain@stable
74
+ - name: Install SoftHSM and OpenSC
75
+ run: sudo apt-get update && sudo apt-get install -y softhsm2 opensc
76
+ - name: Build and test the feature configuration
77
+ env:
78
+ FEATURE_ARGS: ${{ matrix.args }}
79
+ run: |
80
+ python -m pip install --upgrade uv
81
+ uv pip install --system 'maturin>=1.9,<2' pytest jwcrypto
82
+ # Deliberately split the fixed flags from the workflow matrix.
83
+ maturin build --locked $FEATURE_ARGS --out dist
84
+ uv pip install --system --no-index --find-links dist pyjosers
85
+ python -m pytest -q
86
+
87
+ distributions:
88
+ uses: ./.github/workflows/wheels.yml
89
+ with:
90
+ retention-days: ${{ inputs.retention-days || 1 }}
@@ -0,0 +1,71 @@
1
+ name: Release to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags: ['v*']
6
+ workflow_dispatch:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ concurrency:
12
+ group: release-${{ github.ref }}
13
+ cancel-in-progress: false
14
+
15
+ jobs:
16
+ version:
17
+ name: Check release version
18
+ runs-on: ubuntu-latest
19
+ timeout-minutes: 5
20
+ steps:
21
+ - uses: actions/checkout@v7
22
+ - uses: actions/setup-python@v7
23
+ with:
24
+ python-version: '3.14'
25
+ - name: Check package and tag versions
26
+ env:
27
+ RELEASE_REF: ${{ github.ref }}
28
+ RELEASE_TAG: ${{ github.ref_name }}
29
+ run: |
30
+ python - <<'PY'
31
+ import os
32
+ import tomllib
33
+ from pathlib import Path
34
+
35
+ python_version = tomllib.loads(Path("pyproject.toml").read_text())["project"]["version"]
36
+ rust_version = tomllib.loads(Path("Cargo.toml").read_text())["package"]["version"]
37
+ if python_version != rust_version:
38
+ raise SystemExit("Python and Rust package versions disagree")
39
+ if os.environ["RELEASE_REF"].startswith("refs/tags/"):
40
+ if os.environ["RELEASE_TAG"] != f"v{python_version}":
41
+ raise SystemExit("Release tag must match the package version")
42
+ PY
43
+
44
+ distributions:
45
+ needs: version
46
+ uses: ./.github/workflows/ci.yml
47
+ with:
48
+ retention-days: 3
49
+
50
+ publish:
51
+ name: Publish tested distributions
52
+ if: startsWith(github.ref, 'refs/tags/v')
53
+ needs: distributions
54
+ runs-on: ubuntu-latest
55
+ timeout-minutes: 15
56
+ environment:
57
+ name: pypi
58
+ url: https://pypi.org/p/pyjosers
59
+ permissions:
60
+ id-token: write
61
+ steps:
62
+ - name: Download distributions
63
+ uses: actions/download-artifact@v8
64
+ with:
65
+ path: dist
66
+ pattern: pyjosers_*
67
+ merge-multiple: true
68
+ - name: Publish to PyPI
69
+ uses: pypa/gh-action-pypi-publish@release/v1
70
+ with:
71
+ packages-dir: dist/
@@ -0,0 +1,138 @@
1
+ name: Build and test distributions
2
+
3
+ on:
4
+ workflow_call:
5
+ inputs:
6
+ retention-days:
7
+ type: number
8
+ default: 1
9
+
10
+ permissions:
11
+ contents: read
12
+
13
+ env:
14
+ FORCE_COLOR: "1"
15
+ UV_LINK_MODE: "copy"
16
+
17
+ jobs:
18
+ wheels:
19
+ name: Wheel (${{ matrix.platform }})
20
+ runs-on: ${{ matrix.os }}
21
+ timeout-minutes: 45
22
+ defaults:
23
+ run:
24
+ shell: bash
25
+ strategy:
26
+ fail-fast: false
27
+ matrix:
28
+ include:
29
+ - platform: manylinux_x86_64
30
+ os: ubuntu-latest
31
+ target: x86_64-unknown-linux-gnu
32
+ architecture: x64
33
+ image: quay.io/pypa/manylinux_2_28_x86_64
34
+ - platform: manylinux_aarch64
35
+ os: ubuntu-24.04-arm
36
+ target: aarch64-unknown-linux-gnu
37
+ architecture: arm64
38
+ image: quay.io/pypa/manylinux_2_28_aarch64
39
+ - platform: macos_aarch64
40
+ os: macos-15
41
+ target: aarch64-apple-darwin
42
+ architecture: arm64
43
+ image: ''
44
+ - platform: windows_amd64
45
+ os: windows-2025
46
+ target: x86_64-pc-windows-msvc
47
+ architecture: x64
48
+ image: ''
49
+ steps:
50
+ - uses: actions/checkout@v7
51
+ - uses: actions/setup-python@v7
52
+ with:
53
+ python-version: '3.14'
54
+ architecture: ${{ matrix.architecture }}
55
+ - uses: dtolnay/rust-toolchain@stable
56
+ if: runner.os != 'Linux' && matrix.platform != 'windows_aarch64'
57
+ with:
58
+ targets: ${{ matrix.target }}
59
+ - name: Install native Windows ARM Rust toolchain
60
+ if: matrix.platform == 'windows_aarch64'
61
+ shell: pwsh
62
+ run: |
63
+ Invoke-WebRequest -Uri "https://static.rust-lang.org/rustup/dist/aarch64-pc-windows-msvc/rustup-init.exe" -OutFile rustup-init.exe
64
+ .\rustup-init.exe --default-toolchain stable-aarch64-pc-windows-msvc --profile minimal -y
65
+ if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
66
+ "$env:USERPROFILE\.cargo\bin" | Out-File -Append -Encoding ascii $env:GITHUB_PATH
67
+ - name: Install build and test dependencies
68
+ run: |
69
+ python -m pip install --upgrade uv
70
+ uv pip install --system 'maturin>=1.9,<2' pytest jwcrypto
71
+ - name: Install SoftHSM and OpenSC
72
+ if: runner.os == 'Linux'
73
+ run: sudo apt-get update && sudo apt-get install -y softhsm2 opensc
74
+ - name: Build manylinux wheel
75
+ if: runner.os == 'Linux'
76
+ env:
77
+ MANYLINUX_IMAGE: ${{ matrix.image }}
78
+ run: |
79
+ docker pull "$MANYLINUX_IMAGE"
80
+ docker run --rm -v "$GITHUB_WORKSPACE:/io" "$MANYLINUX_IMAGE" bash /io/build-wheels.sh
81
+ - name: Build macOS wheel
82
+ if: runner.os == 'macOS'
83
+ env:
84
+ MACOSX_DEPLOYMENT_TARGET: '11.0'
85
+ RUST_TARGET: ${{ matrix.target }}
86
+ run: maturin build --release --strip --locked --interpreter python --target "$RUST_TARGET" --out dist
87
+ - name: Build Windows wheel
88
+ if: runner.os == 'Windows'
89
+ env:
90
+ RUST_TARGET: ${{ matrix.target }}
91
+ run: maturin build --release --strip --locked --interpreter python --target "$RUST_TARGET" --out dist
92
+ - name: Test the built wheel
93
+ run: |
94
+ uv pip install --system --no-index --find-links dist pyjosers
95
+ python -m pytest -q
96
+ - name: Store wheel
97
+ uses: actions/upload-artifact@v7
98
+ with:
99
+ name: pyjosers_${{ matrix.platform }}
100
+ path: dist/*.whl
101
+ retention-days: ${{ inputs.retention-days }}
102
+ if-no-files-found: error
103
+ compression-level: 0
104
+
105
+ sdist:
106
+ name: Build and test source distribution
107
+ runs-on: ubuntu-latest
108
+ timeout-minutes: 45
109
+ steps:
110
+ - uses: actions/checkout@v7
111
+ - uses: actions/setup-python@v7
112
+ with:
113
+ python-version: '3.10'
114
+ - uses: dtolnay/rust-toolchain@stable
115
+ - name: Install build and test dependencies
116
+ run: |
117
+ sudo apt-get update && sudo apt-get install -y softhsm2 opensc
118
+ python -m pip install --upgrade uv
119
+ uv pip install --system 'maturin>=1.9,<2' pytest jwcrypto
120
+ - name: Build source distribution
121
+ run: maturin sdist --out dist
122
+ - name: Build and test outside the checkout
123
+ run: |
124
+ set -euo pipefail
125
+ package_dir=$(mktemp -d)
126
+ tar -xzf dist/pyjosers-*.tar.gz -C "$package_dir"
127
+ cd "$package_dir"/pyjosers-*
128
+ maturin build --release --strip --locked --interpreter python --out wheels
129
+ uv pip install --system --no-index --find-links wheels pyjosers
130
+ python -m pytest -q
131
+ - name: Store source distribution
132
+ uses: actions/upload-artifact@v7
133
+ with:
134
+ name: pyjosers_sdist
135
+ path: dist/*.tar.gz
136
+ retention-days: ${{ inputs.retention-days }}
137
+ if-no-files-found: error
138
+ compression-level: 0
@@ -0,0 +1,8 @@
1
+ .venv/
2
+ target/
3
+ __pycache__/
4
+ *.so
5
+ *.pyc
6
+ .pytest_cache/
7
+ docs/_build/
8
+ dist/
@@ -0,0 +1,14 @@
1
+ version: 2
2
+ build:
3
+ os: ubuntu-24.04
4
+ tools:
5
+ python: '3.12'
6
+ rust: '1.89'
7
+ sphinx:
8
+ configuration: docs/conf.py
9
+ fail_on_warning: true
10
+ python:
11
+ install:
12
+ - method: pip
13
+ path: .
14
+ extra_requirements: [docs]
@@ -0,0 +1,43 @@
1
+ # Repository Guidelines
2
+
3
+ ## Project Structure & Module Organization
4
+
5
+ - `src/lib.rs` implements the PyO3 boundary; `src/hsm.rs` owns PKCS#11 handles.
6
+ - `python/pyjosers/` contains the public JWK, JWS, JWE, and JWT APIs, native stubs, and `py.typed` marker.
7
+ - `jose-rs` and `kryptering` are crates.io dependencies. Their source checkouts are `../jose-rs/` and `../kryptering/`; do not vendor their source in this repository.
8
+ - `tests/` covers interoperability, validation, admin migration, and SoftHSM integration.
9
+ - `docs/` contains Sphinx sources; `examples/` contains runnable demonstrations. Generated files belong in `target/`, `dist/`, and `docs/_build/`.
10
+
11
+ ## Build, Test, and Development Commands
12
+
13
+ Requires Python 3.10+ and Rust 1.89+. Set up and activate the environment:
14
+
15
+ ```sh
16
+ uv venv
17
+ source .venv/bin/activate
18
+ uv pip install -e '.[dev]'
19
+ ```
20
+
21
+ - `maturin develop`: rebuild and install the editable native extension after Rust changes.
22
+ - `pytest -q`: run the Python test suite.
23
+ - `cargo fmt --check`: check Rust formatting.
24
+ - `cargo clippy --all-features -- -D warnings`: lint Rust with all features enabled.
25
+ - `sphinx-build -W --keep-going -b html docs docs/_build/html`: build documentation strictly.
26
+ - `sphinx-build -W -b doctest docs docs/_build/doctest`: execute documentation examples.
27
+ - `maturin build --release --locked` and `maturin sdist`: create distribution artifacts.
28
+
29
+ ## Coding Style & Naming Conventions
30
+
31
+ Use four-space Python indentation, `snake_case` functions/modules, and descriptive class names; preserve established JOSE acronyms such as `JWK`. Add type annotations and public docstrings, and synchronize `_native.pyi` with Rust signatures. Use rustfmt for Rust; no Python formatter is currently configured. Keep cryptography in Rust and compatibility behavior in Python. Update documentation whenever public APIs change.
32
+
33
+ ## Testing Guidelines
34
+
35
+ Name pytest files `test_*.py` and tests `test_*`. Add regression coverage for changed behavior, including failed authentication and object-state clearing. Cryptographic changes should include bidirectional jwcrypto interoperability where supported. No numeric coverage threshold is configured. Generate disposable keys; never use application secrets. SoftHSM tests skip when dependencies are unavailable. Set `PYJOSERS_ADMIN_CHECKOUT` to exercise actual admin functions. Check minimal and legacy feature builds when relevant; restore defaults afterward.
36
+
37
+ ## Commit & Pull Request Guidelines
38
+
39
+ Use concise, imperative commit subjects. Pull requests should
40
+ explain the problem, behavior changes, compatibility implications, related
41
+ issues when applicable, and validation commands/results. Document backend
42
+ patches and algorithm limitations explicitly. Exclude generated binaries, build
43
+ output, and private keys.
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ First release: PyO3 bindings for crates.io jose-rs 0.8.0 and kryptering 0.6,
6
+ with jwcrypto-style JWK/JWKSet,
7
+ JWS, JWE and JWT APIs; full validation policy; detached, unencoded and
8
+ multi-signature JWS; nested JWT; post-quantum signatures; PKCS#11 signing;
9
+ PEM/DER and certificate-binding helpers; interoperability tests and Sphinx docs.
10
+
11
+ Custom protected JWE headers use the public upstream API. No backend source
12
+ is vendored. RSA-PSS-specific PKCS#8 and SPKI keys (including PEM wrappers)
13
+ are rejected because JWK conversion cannot preserve their restrictions.
14
+ Ordinary RSA keys support both RS* and PS* algorithms.
15
+
16
+ Header emission follows jose-rs 0.8.0 policy: JWS signing rejects JWE-only
17
+ members and registered or duplicate critical names; JWE encryption rejects
18
+ unsupported registered members. Emitting jku, jwk, x5u or x5c requires the
19
+ explicit allow_key_reference_headers opt-in on JWS, JWE, JWT, jwt.encode or
20
+ jwt.encode_nested. Software and PKCS#11 signing use the same policy.
21
+
22
+ See docs/migration.rst for compatibility scope and upstream limitations.