Skip to content

Commit 7b6987c

Browse files
committed
Add libpep python
1 parent 872e477 commit 7b6987c

21 files changed

+3117
-5
lines changed

.github/workflows/lint-and-test.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,34 @@ jobs:
3030
- uses: actions-rust-lang/setup-rust-toolchain@v1
3131
- run: cargo test --all-features
3232
- run: cargo doc --no-deps
33+
34+
test-python:
35+
runs-on: ubuntu-latest
36+
name: test python bindings
37+
steps:
38+
- uses: actions/checkout@v4
39+
- uses: actions-rust-lang/setup-rust-toolchain@v1
40+
- uses: actions/setup-python@v4
41+
with:
42+
python-version: '3.x'
43+
- run: pip install maturin pytest
44+
- name: Build Python extension
45+
run: maturin develop --features python
46+
- name: Run Python tests
47+
run: python -m unittest discover tests/python/ -v
48+
49+
test-wasm:
50+
runs-on: ubuntu-latest
51+
name: test wasm bindings
52+
steps:
53+
- uses: actions/checkout@v4
54+
- uses: actions-rust-lang/setup-rust-toolchain@v1
55+
- uses: actions/setup-node@v4
56+
with:
57+
node-version: '20.x'
58+
- run: cargo install wasm-pack
59+
- run: npm install
60+
- name: Build WASM package
61+
run: npm run build
62+
- name: Run WASM tests
63+
run: npm test

.github/workflows/publish.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,77 @@ jobs:
4343
- run: npm publish --provenance --access public
4444
env:
4545
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
46+
47+
publish-python:
48+
runs-on: ubuntu-latest
49+
needs: semver-checks
50+
strategy:
51+
matrix:
52+
target: [x86_64, x86, aarch64, armv7, s390x, ppc64le]
53+
permissions:
54+
contents: read
55+
id-token: write
56+
57+
name: Build and publish Python wheels
58+
steps:
59+
- uses: actions/checkout@v4
60+
- uses: actions/setup-python@v4
61+
with:
62+
python-version: '3.x'
63+
- run: pip install maturin
64+
- name: Build wheels
65+
uses: PyO3/maturin-action@v1
66+
with:
67+
target: ${{ matrix.target }}
68+
args: --release --out dist --features python
69+
sccache: 'true'
70+
manylinux: auto
71+
- name: Upload wheels
72+
uses: actions/upload-artifact@v3
73+
with:
74+
name: wheels
75+
path: dist
76+
77+
publish-python-sdist:
78+
runs-on: ubuntu-latest
79+
needs: semver-checks
80+
permissions:
81+
contents: read
82+
id-token: write
83+
84+
name: Build Python source distribution
85+
steps:
86+
- uses: actions/checkout@v4
87+
- uses: actions/setup-python@v4
88+
with:
89+
python-version: '3.x'
90+
- run: pip install maturin
91+
- name: Build sdist
92+
uses: PyO3/maturin-action@v1
93+
with:
94+
command: sdist
95+
args: --out dist --features python
96+
- name: Upload sdist
97+
uses: actions/upload-artifact@v3
98+
with:
99+
name: wheels
100+
path: dist
101+
102+
release-python:
103+
runs-on: ubuntu-latest
104+
needs: [publish-python, publish-python-sdist]
105+
permissions:
106+
contents: read
107+
id-token: write
108+
109+
name: Release Python package to PyPI
110+
steps:
111+
- name: Download all artifacts
112+
uses: actions/download-artifact@v3
113+
with:
114+
name: wheels
115+
path: dist
116+
- name: Publish to PyPI
117+
uses: PyPA/gh-action-pypi-publish@release/v1
118+
with:
119+
password: ${{ secrets.PYPI_API_TOKEN }}

.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,46 @@ dist
153153
# Code editors
154154
.idea/
155155

156+
# Python
157+
__pycache__/
158+
*.py[cod]
159+
*$py.class
160+
*.so
161+
.Python
162+
build/
163+
develop-eggs/
164+
downloads/
165+
eggs/
166+
.eggs/
167+
lib/
168+
lib64/
169+
parts/
170+
sdist/
171+
var/
172+
wheels/
173+
*.egg-info/
174+
.installed.cfg
175+
*.egg
176+
MANIFEST
177+
*.manifest
178+
*.spec
179+
pip-log.txt
180+
pip-delete-this-directory.txt
181+
.tox/
182+
.nox/
183+
.coverage
184+
.coverage.*
185+
.cache
186+
nosetests.xml
187+
coverage.xml
188+
*.cover
189+
.hypothesis/
190+
.pytest_cache/
191+
.venv/
192+
venv/
193+
ENV/
194+
env/
195+
.env
196+
156197
# OS specific
157198
.DS_Store

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ readme = "README.md"
1616
default = ["build-binary"]
1717
elgamal3 = []
1818
wasm = ["wasm-bindgen", "getrandom"]
19+
python = ["pyo3"]
1920
legacy-pep-repo-compatible = []
2021
insecure-methods = []
2122
build-binary = ["buildinfy","commandy","commandy_macros"]
@@ -41,6 +42,7 @@ base64 = "^0.22"
4142
serde = { version = "^1.0", features = ["derive"] }
4243
wasm-bindgen = { version = "0.2", optional = true }
4344
getrandom = { version = "^0.2", features = ["js"], optional = true}
45+
pyo3 = { version = "0.22", features = ["extension-module"], optional = true }
4446
buildinfy = { version = "^0.1", optional = true }
4547
commandy = { version = "^0.2", optional = true }
4648
commandy_macros = { version = "^0.2", optional = true }

pyproject.toml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[build-system]
2+
requires = ["maturin>=1.0,<2.0"]
3+
build-backend = "maturin"
4+
5+
[project]
6+
name = "libpep"
7+
description = "Python bindings for libpep - implementation of PEP primitives, offering pseudonymization and encryption interfaces"
8+
authors = [
9+
{name = "Bernard van Gastel", email = "bvgastel@bitpowder.com"},
10+
{name = "Job Doesburg", email = "job@jobdoesburg.nl"}
11+
]
12+
keywords = ["crypto", "pep", "pseudonymization"]
13+
classifiers = [
14+
"Development Status :: 4 - Beta",
15+
"Intended Audience :: Developers",
16+
"License :: OSI Approved :: Apache Software License",
17+
"Programming Language :: Python :: 3",
18+
"Programming Language :: Python :: 3.8",
19+
"Programming Language :: Python :: 3.9",
20+
"Programming Language :: Python :: 3.10",
21+
"Programming Language :: Python :: 3.11",
22+
"Programming Language :: Python :: 3.12",
23+
"Programming Language :: Rust",
24+
"Topic :: Security :: Cryptography",
25+
]
26+
requires-python = ">=3.8"
27+
license = {text = "Apache-2.0"}
28+
dynamic = ["version"]
29+
readme = "README.md"
30+
31+
[project.urls]
32+
Homepage = "https://github.com/NOLAI/libpep"
33+
Repository = "https://github.com/NOLAI/libpep"
34+
Documentation = "https://docs.rs/libpep"
35+
36+
[project.optional-dependencies]
37+
dev = [
38+
"maturin>=1.0",
39+
"pytest>=7.0"
40+
]
41+
42+
[tool.maturin]
43+
features = ["pyo3/extension-module", "python"]
44+
module-name = "libpep"
45+

src/lib/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,9 @@ mod wasm {
7979
mod high_level;
8080
mod primitives;
8181
}
82+
83+
#[cfg(feature = "python")]
84+
mod python;
85+
86+
#[cfg(feature = "python")]
87+
pub use python::libpep;

0 commit comments

Comments
 (0)