use python_obfuscator::{PythonObfuscator, PythonObfuscatorResponse};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let my_python_obfuscator =
PythonObfuscator::new(Some("ABCD-ABCD-ABCD-ABCD".to_string()));
let script_source_code = r#"label = 'SecretKey'
port = 443
def get_sum(a, b):
return a + b
print(label, port)
r = get_sum(11, 31)
print(r)"#;
let result = my_python_obfuscator
.obfuscate_script_source(script_source_code, true)
.await;
match result {
Some(PythonObfuscatorResponse::Object(obj)) => {
if obj.error == PythonObfuscator::ERROR_SUCCESS {
println!("{}", obj.output.unwrap_or_default());
} else {
return Err(
format!("An error occurred, error code: {}", obj.error).into(),
);
}
}
Some(PythonObfuscatorResponse::Json(_)) => {}
None => {
return Err("Something unexpected happen while trying to obfuscate the code.".into());
}
}
Ok(())
}