python interface for the newer stuff

This commit is contained in:
Christoph J. Scherr 2023-05-17 13:07:11 +02:00
parent 49f765c2a5
commit 96b8eca3bf
Signed by: PlexSheep
GPG Key ID: 25B4ACF7D88186CC
3 changed files with 34 additions and 6 deletions

View File

@ -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

View File

@ -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 = <Box<Cli> as CommandFactory>::command();
println!("{} {}", b.get_name(), b.get_version().unwrap());
return;
}
#[pyfunction]
/// Print about
pub fn about() {
let b = <Box<Cli> as CommandFactory>::command();
println!("{}", b.get_about().unwrap());
return;
}
#[pyfunction]
/// print a seperator
pub fn seperator() {
println!("{:=<120}", '=');

View File

@ -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(())
}