libmotor_sys/
lib.rs

1#![allow(non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3#![allow(non_snake_case)]
4
5use std::ffi::{CString, CStr};
6
7include!("./bindings.rs");
8
9pub fn aes_encrypt_with_key(key: String, plaintext: String) -> String {
10    let keyStr = string_to_i8_ptr(key);
11    let textStr = string_to_i8_ptr(plaintext);
12    let result = unsafe { aesEncryptWithKey(keyStr, textStr) };
13    return i8_ptr_to_string(result);
14}
15
16fn string_to_i8_ptr(s: String) -> *mut i8 {
17    let s = String::from(s);
18    let cs = CString::new(s).unwrap();
19    let cv: Vec<u8> = cs.into_bytes_with_nul();
20    let mut tmp: Vec<i8> = cv.into_iter().map(|c| c as i8).collect::<_>(); // line 7
21    let _cptr: *mut i8 = tmp.as_mut_ptr();
22    return _cptr;
23}
24
25fn i8_ptr_to_string(p: *mut i8) -> String {
26  let c_str: &CStr = unsafe { CStr::from_ptr(p) };
27  let str_slice: &str = c_str.to_str().unwrap();
28  return str_slice.to_owned();
29}