From 96b8eca3bff9078471cbc0e603f0d2a4eed91805 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Wed, 17 May 2023 13:07:11 +0200 Subject: [PATCH] python interface for the newer stuff --- install.sh | 2 +- src/cplex/printing.rs | 14 +++++++++++++- src/lib.rs | 24 ++++++++++++++++++++---- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index ec3b1bf..103a8fc 100755 --- a/install.sh +++ b/install.sh @@ -2,4 +2,4 @@ rm target/wheels -rf cargo install --path . maturin build --release -pip install target/wheels/plexcryptool*x86_64.whl --force +pip install target/wheels/plexcryptool-*.whl --force diff --git a/src/cplex/printing.rs b/src/cplex/printing.rs index 0dc6c82..4891cf7 100644 --- a/src/cplex/printing.rs +++ b/src/cplex/printing.rs @@ -12,18 +12,30 @@ use crate::cplex::cli::Cli; use std::fmt::{Debug, LowerHex}; +use pyo3::prelude::*; + use clap::CommandFactory; use num::Integer; /////////////////////////////////////////////////////////////////////////////////////////////////// -/// print the version +#[pyfunction] +/// Print version pub fn version() { let b = as CommandFactory>::command(); println!("{} {}", b.get_name(), b.get_version().unwrap()); return; } +#[pyfunction] +/// Print about +pub fn about() { + let b = as CommandFactory>::command(); + println!("{}", b.get_about().unwrap()); + return; +} + +#[pyfunction] /// print a seperator pub fn seperator() { println!("{:=<120}", '='); diff --git a/src/lib.rs b/src/lib.rs index f901b07..c7d18f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,6 +35,18 @@ fn register_binary_module(py: Python, parent_module: &PyModule) -> PyResult<()> Ok(()) } +#[pymodule] +fn register_cplex_module(py: Python, parent_module: &PyModule) -> PyResult<()> { + let cplex_module = PyModule::new(py, "cplex")?; + let printing_module = PyModule::new(py, "printing")?; + printing_module.add_function(wrap_pyfunction!(cplex::printing::seperator, printing_module)?)?; + printing_module.add_function(wrap_pyfunction!(cplex::printing::version, printing_module)?)?; + printing_module.add_function(wrap_pyfunction!(cplex::printing::about, printing_module)?)?; + cplex_module.add_submodule(printing_module)?; + parent_module.add_submodule(cplex_module)?; + Ok(()) +} + #[pymodule] fn register_math_module(py: Python, parent_module: &PyModule) -> PyResult<()> { let math_module = PyModule::new(py, "math")?; @@ -47,10 +59,12 @@ fn register_math_module(py: Python, parent_module: &PyModule) -> PyResult<()> { #[pymodule] fn register_algo_module(py: Python, parent_module: &PyModule) -> PyResult<()> { let algo_module = PyModule::new(py, "algo")?; - algo_module.add_function(wrap_pyfunction!(algo::feistel0::encrypt, algo_module)?)?; - algo_module.add_function(wrap_pyfunction!(algo::feistel0::decrypt, algo_module)?)?; - algo_module.add_function(wrap_pyfunction!(algo::feistel0::sbox, algo_module)?)?; - algo_module.add_function(wrap_pyfunction!(algo::feistel0::key_scheduler, algo_module)?)?; + let feistel0_module = PyModule::new(py, "algo")?; + feistel0_module.add_function(wrap_pyfunction!(algo::feistel0::encrypt, feistel0_module)?)?; + feistel0_module.add_function(wrap_pyfunction!(algo::feistel0::decrypt, feistel0_module)?)?; + feistel0_module.add_function(wrap_pyfunction!(algo::feistel0::sbox, feistel0_module)?)?; + feistel0_module.add_function(wrap_pyfunction!(algo::feistel0::key_scheduler, feistel0_module)?)?; + algo_module.add_submodule(feistel0_module)?; parent_module.add_submodule(algo_module)?; Ok(()) } @@ -60,5 +74,7 @@ fn register_algo_module(py: Python, parent_module: &PyModule) -> PyResult<()> { fn plexcryptool(py: Python, m: &PyModule) -> PyResult<()> { register_binary_module(py, m)?; register_math_module(py, m)?; + register_cplex_module(py, m)?; + register_algo_module(py, m)?; Ok(()) }