-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose XorName type in Python bindings
- Created Python wrapper for XorName type - Added methods for creating XorName from content, bytes, and hex - Added conversion methods to bytes and hex - Added comprehensive tests for XorName functionality - Updated project structure to use modular Python bindings
- Loading branch information
Showing
10 changed files
with
459 additions
and
133 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 |
---|---|---|
|
@@ -2,9 +2,9 @@ | |
authors = ["MaidSafe Developers <[email protected]>"] | ||
description = "Self encrypting files (convergent encryption plus obfuscation)" | ||
documentation = "https://docs.rs/self_encryption" | ||
edition = "2018" | ||
edition = "2021" | ||
homepage = "https://maidsafe.net" | ||
license = "GPL-3.0" | ||
license = "MIT OR BSD-3-Clause" | ||
name = "self_encryption" | ||
readme = "README.md" | ||
repository = "https://github.com/maidsafe/self_encryption" | ||
|
@@ -15,33 +15,30 @@ default = [] | |
python = ["pyo3/extension-module"] | ||
|
||
[dependencies] | ||
aes = "~0.8.1" | ||
aes = "0.8.3" | ||
bincode = "~1.3.3" | ||
hex = "~0.4.3" | ||
bytes = "1.5.0" | ||
cbc = { version = "0.1.2", features = ["alloc"] } | ||
hex = "0.4.3" | ||
lazy_static = "1.4.0" | ||
rand = "~0.8.5" | ||
log = "0.4.20" | ||
memmap2 = "0.9.4" | ||
rand = "0.8.5" | ||
rand_chacha = "~0.3.1" | ||
rayon = "1.5.1" | ||
thiserror = "1.0" | ||
sha2 = "0.10.8" | ||
tempfile = "3.10.1" | ||
thiserror = "1.0.57" | ||
num_cpus = "1.13.0" | ||
itertools = "~0.10.0" | ||
tempfile = "3.6.0" | ||
xor_name = "5.0.0" | ||
pyo3 = { version = "=0.20.3", optional = true, features = ["extension-module"] } | ||
pyo3 = { version = "0.21.0", optional = true, features = ["extension-module", "abi3-py38", "abi3"] } | ||
|
||
[dependencies.brotli] | ||
version = "~3.3.0" | ||
default-features = false | ||
features = ["std"] | ||
|
||
[dependencies.cbc] | ||
version = "~0.1.1" | ||
features = ["alloc", "block-padding"] | ||
|
||
[dependencies.bytes] | ||
version = "1.1.0" | ||
features = ["serde"] | ||
|
||
[dependencies.serde] | ||
version = "1.0.136" | ||
features = ["derive"] | ||
|
@@ -55,7 +52,10 @@ version = "1.34.0" | |
features = ["rt"] | ||
|
||
[dev-dependencies] | ||
criterion = "~0.3" | ||
criterion = "0.5.1" | ||
env_logger = "0.11.2" | ||
itertools = "0.12.1" | ||
walkdir = "2.4.0" | ||
docopt = "~0.9.0" | ||
clap = { version = "4.4", features = ["derive"] } | ||
|
||
|
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,52 @@ | ||
// src/python/data_map.rs | ||
pub mod py_data_map; | ||
|
||
use pyo3::prelude::*; | ||
use crate::DataMap; | ||
use crate::data_map::py_data_map::PyDataMap; | ||
|
||
#[pymethods] | ||
impl PyDataMap { | ||
/// Create a new empty DataMap | ||
#[new] | ||
pub fn new() -> Self { | ||
Self { | ||
inner: DataMap::new(Vec::new()), | ||
} | ||
} | ||
|
||
/// Get the original file size | ||
#[getter] | ||
pub fn original_file_size(&self) -> usize { | ||
self.inner.original_file_size() | ||
} | ||
|
||
/// Get the number of chunks | ||
#[getter] | ||
pub fn chunk_count(&self) -> usize { | ||
self.inner.len() | ||
} | ||
|
||
/// Check if this is a child data map | ||
pub fn is_child(&self) -> bool { | ||
self.inner.is_child() | ||
} | ||
|
||
pub fn __str__(&self) -> String { | ||
format!("DataMap(file_size={}, chunks={})", self.original_file_size(), self.chunk_count()) | ||
} | ||
|
||
/// Serialize the data map to bytes | ||
pub fn serialize(&self) -> PyResult<Vec<u8>> { | ||
bincode::serialize(&self.inner) | ||
.map_err(|e| PyErr::new::<pyo3::exceptions::PyValueError, _>(e.to_string())) | ||
} | ||
|
||
/// Create a data map from serialized bytes | ||
#[staticmethod] | ||
pub fn deserialize(data: Vec<u8>) -> PyResult<Self> { | ||
bincode::deserialize(&data) | ||
.map(|inner| Self { inner }) | ||
.map_err(|e| PyErr::new::<pyo3::exceptions::PyValueError, _>(e.to_string())) | ||
} | ||
} |
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,48 @@ | ||
use pyo3::prelude::*; | ||
use std::path::PathBuf; | ||
use crate::StreamSelfDecryptor; | ||
use super::{PyDataMap, PyEncryptedChunk}; | ||
|
||
/// Python wrapper for StreamSelfDecryptor | ||
#[pyclass] | ||
pub struct PyStreamSelfDecryptor { | ||
inner: StreamSelfDecryptor, | ||
} | ||
|
||
#[pymethods] | ||
impl PyStreamSelfDecryptor { | ||
/// Create a new streaming decryptor from a data map and chunks | ||
#[new] | ||
pub fn new(file_path: String, data_map: &PyDataMap) -> PyResult<Self> { | ||
let path = PathBuf::from(file_path); | ||
match StreamSelfDecryptor::decrypt_to_file(path, &data_map.inner) { | ||
Ok(decryptor) => Ok(Self { inner: decryptor }), | ||
Err(e) => Err(PyErr::new::<pyo3::exceptions::PyValueError, _>(format!("Failed to create decryptor: {}", e))), | ||
} | ||
} | ||
|
||
/// Process the next encrypted chunk | ||
/// | ||
/// Args: | ||
/// chunk (PyEncryptedChunk): The next encrypted chunk to process | ||
/// | ||
/// Returns: | ||
/// bool: True if decryption is complete, False if more chunks are needed | ||
/// | ||
/// Raises: | ||
/// ValueError: If decryption fails | ||
pub fn next_encrypted(&mut self, encrypted_chunk: PyEncryptedChunk) -> PyResult<bool> { | ||
match self.inner.next_encrypted(encrypted_chunk.inner) { | ||
Ok(done) => Ok(done), | ||
Err(e) => Err(PyErr::new::<pyo3::exceptions::PyValueError, _>(format!("Decryption failed: {}", e))), | ||
} | ||
} | ||
|
||
/// Get the output file path | ||
/// | ||
/// Returns: | ||
/// str: Path to the decrypted output file | ||
pub fn file_path(&self) -> String { | ||
self.inner.file_path().to_string_lossy().into_owned() | ||
} | ||
} |
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,30 @@ | ||
// src/python/encrypted_chunk.rs | ||
use pyo3::prelude::*; | ||
use bytes::Bytes; | ||
use crate::EncryptedChunk; | ||
|
||
/// Python wrapper for EncryptedChunk | ||
#[pyclass] | ||
#[derive(Clone)] | ||
pub struct PyEncryptedChunk { | ||
pub(crate) inner: EncryptedChunk, | ||
} | ||
|
||
#[pymethods] | ||
impl PyEncryptedChunk { | ||
/// Create a new EncryptedChunk from raw bytes | ||
#[new] | ||
pub fn new(content: Vec<u8>) -> Self { | ||
Self { | ||
inner: EncryptedChunk { | ||
content: Bytes::from(content), | ||
} | ||
} | ||
} | ||
|
||
/// Get the encrypted content as bytes | ||
#[getter] | ||
pub fn content(&self) -> Vec<u8> { | ||
self.inner.content.to_vec() | ||
} | ||
} |
Oops, something went wrong.