python interface for the newer stuff
This commit is contained in:
parent
49f765c2a5
commit
96b8eca3bf
|
@ -2,4 +2,4 @@
|
||||||
rm target/wheels -rf
|
rm target/wheels -rf
|
||||||
cargo install --path .
|
cargo install --path .
|
||||||
maturin build --release
|
maturin build --release
|
||||||
pip install target/wheels/plexcryptool*x86_64.whl --force
|
pip install target/wheels/plexcryptool-*.whl --force
|
||||||
|
|
|
@ -12,18 +12,30 @@ use crate::cplex::cli::Cli;
|
||||||
|
|
||||||
use std::fmt::{Debug, LowerHex};
|
use std::fmt::{Debug, LowerHex};
|
||||||
|
|
||||||
|
use pyo3::prelude::*;
|
||||||
|
|
||||||
use clap::CommandFactory;
|
use clap::CommandFactory;
|
||||||
use num::Integer;
|
use num::Integer;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/// print the version
|
#[pyfunction]
|
||||||
|
/// Print version
|
||||||
pub fn version() {
|
pub fn version() {
|
||||||
let b = <Box<Cli> as CommandFactory>::command();
|
let b = <Box<Cli> as CommandFactory>::command();
|
||||||
println!("{} {}", b.get_name(), b.get_version().unwrap());
|
println!("{} {}", b.get_name(), b.get_version().unwrap());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[pyfunction]
|
||||||
|
/// Print about
|
||||||
|
pub fn about() {
|
||||||
|
let b = <Box<Cli> as CommandFactory>::command();
|
||||||
|
println!("{}", b.get_about().unwrap());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[pyfunction]
|
||||||
/// print a seperator
|
/// print a seperator
|
||||||
pub fn seperator() {
|
pub fn seperator() {
|
||||||
println!("{:=<120}", '=');
|
println!("{:=<120}", '=');
|
||||||
|
|
24
src/lib.rs
24
src/lib.rs
|
@ -35,6 +35,18 @@ fn register_binary_module(py: Python, parent_module: &PyModule) -> PyResult<()>
|
||||||
Ok(())
|
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]
|
#[pymodule]
|
||||||
fn register_math_module(py: Python, parent_module: &PyModule) -> PyResult<()> {
|
fn register_math_module(py: Python, parent_module: &PyModule) -> PyResult<()> {
|
||||||
let math_module = PyModule::new(py, "math")?;
|
let math_module = PyModule::new(py, "math")?;
|
||||||
|
@ -47,10 +59,12 @@ fn register_math_module(py: Python, parent_module: &PyModule) -> PyResult<()> {
|
||||||
#[pymodule]
|
#[pymodule]
|
||||||
fn register_algo_module(py: Python, parent_module: &PyModule) -> PyResult<()> {
|
fn register_algo_module(py: Python, parent_module: &PyModule) -> PyResult<()> {
|
||||||
let algo_module = PyModule::new(py, "algo")?;
|
let algo_module = PyModule::new(py, "algo")?;
|
||||||
algo_module.add_function(wrap_pyfunction!(algo::feistel0::encrypt, algo_module)?)?;
|
let feistel0_module = PyModule::new(py, "algo")?;
|
||||||
algo_module.add_function(wrap_pyfunction!(algo::feistel0::decrypt, algo_module)?)?;
|
feistel0_module.add_function(wrap_pyfunction!(algo::feistel0::encrypt, feistel0_module)?)?;
|
||||||
algo_module.add_function(wrap_pyfunction!(algo::feistel0::sbox, algo_module)?)?;
|
feistel0_module.add_function(wrap_pyfunction!(algo::feistel0::decrypt, feistel0_module)?)?;
|
||||||
algo_module.add_function(wrap_pyfunction!(algo::feistel0::key_scheduler, algo_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)?;
|
parent_module.add_submodule(algo_module)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -60,5 +74,7 @@ fn register_algo_module(py: Python, parent_module: &PyModule) -> PyResult<()> {
|
||||||
fn plexcryptool(py: Python, m: &PyModule) -> PyResult<()> {
|
fn plexcryptool(py: Python, m: &PyModule) -> PyResult<()> {
|
||||||
register_binary_module(py, m)?;
|
register_binary_module(py, m)?;
|
||||||
register_math_module(py, m)?;
|
register_math_module(py, m)?;
|
||||||
|
register_cplex_module(py, m)?;
|
||||||
|
register_algo_module(py, m)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue