forked from maidsafe/self_encryption
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
189 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
name: Build and Publish Python Package | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
macos: | ||
runs-on: macos-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | ||
target: [x86_64, aarch64] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Build wheels | ||
uses: PyO3/maturin-action@v1 | ||
with: | ||
target: ${{ matrix.target }} | ||
args: --release --out dist | ||
sccache: 'true' | ||
|
||
windows: | ||
runs-on: windows-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | ||
target: [x64] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
architecture: ${{ matrix.target }} | ||
- name: Build wheels | ||
uses: PyO3/maturin-action@v1 | ||
with: | ||
args: --release --out dist | ||
sccache: 'true' | ||
|
||
linux: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | ||
target: [x86_64, aarch64] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Build wheels | ||
uses: PyO3/maturin-action@v1 | ||
with: | ||
target: ${{ matrix.target }} | ||
manylinux: auto | ||
args: --release --out dist | ||
sccache: 'true' | ||
|
||
sdist: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build sdist | ||
uses: PyO3/maturin-action@v1 | ||
with: | ||
command: sdist | ||
args: --out dist | ||
|
||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
needs: [macos, windows, linux, sdist] | ||
steps: | ||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: wheels | ||
path: dist | ||
- name: Publish to PyPI | ||
uses: PyO3/maturin-action@v1 | ||
env: | ||
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} | ||
with: | ||
command: upload | ||
args: --skip-existing dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[build-system] | ||
requires = ["maturin>=1.0,<2.0"] | ||
build-backend = "maturin" | ||
|
||
[project] | ||
name = "self_encryption" | ||
version = "0.1.0" | ||
description = "Python bindings for self-encryption library" | ||
authors = [{name = "David Irvine", email = "[email protected]"}] | ||
requires-python = ">=3.7" | ||
classifiers = [ | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Rust", | ||
"Operating System :: OS Independent", | ||
] | ||
|
||
[tool.maturin] | ||
features = ["python"] |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use pyo3::prelude::*; | ||
use crate::{encrypt, decrypt_full_set, DataMap, EncryptedChunk}; | ||
use bytes::Bytes; | ||
|
||
#[pyclass] | ||
struct PyDataMap { | ||
inner: DataMap | ||
} | ||
|
||
#[pymethods] | ||
impl PyDataMap { | ||
#[new] | ||
fn new(data: &[u8]) -> PyResult<Self> { | ||
let bytes = Bytes::from(data.to_vec()); | ||
let (data_map, _) = encrypt(bytes).map_err(|e| { | ||
PyErr::new::<pyo3::exceptions::PyValueError, _>(format!("Encryption failed: {}", e)) | ||
})?; | ||
Ok(PyDataMap { inner: data_map }) | ||
} | ||
|
||
fn encrypt(mut slf: PyRefMut<'_, Self>, _py: Python<'_>, data: &[u8]) -> PyResult<Vec<Vec<u8>>> { | ||
let bytes = Bytes::from(data.to_vec()); | ||
let (data_map, chunks) = encrypt(bytes).map_err(|e| { | ||
PyErr::new::<pyo3::exceptions::PyValueError, _>(format!("Encryption failed: {}", e)) | ||
})?; | ||
|
||
slf.inner = data_map; | ||
|
||
Ok(chunks.into_iter().map(|c| c.content.to_vec()).collect()) | ||
} | ||
|
||
fn decrypt(slf: PyRef<'_, Self>, _py: Python<'_>, chunks: Vec<Vec<u8>>) -> PyResult<Vec<u8>> { | ||
let encrypted_chunks: Vec<EncryptedChunk> = chunks | ||
.into_iter() | ||
.map(|c| EncryptedChunk { content: Bytes::from(c) }) | ||
.collect(); | ||
|
||
let decrypted = decrypt_full_set(&slf.inner, &encrypted_chunks).map_err(|e| { | ||
PyErr::new::<pyo3::exceptions::PyValueError, _>(format!("Decryption failed: {}", e)) | ||
})?; | ||
|
||
Ok(decrypted.to_vec()) | ||
} | ||
} | ||
|
||
#[pymodule] | ||
fn self_encryption(_py: Python<'_>, m: &PyModule) -> PyResult<()> { | ||
m.add_class::<PyDataMap>()?; | ||
Ok(()) | ||
} |