ft_sys/
crypto.rs

1unsafe extern "C" {
2    fn crypto_encrypt(ptr: i32, len: i32) -> i32;
3    fn crypto_decrypt(ptr: i32, len: i32) -> i32;
4}
5
6/// Encrypt a string. The encryption is done in host, and host manages the encryption
7/// key. This function should be used if you want to store sensitive data in the
8/// database.
9pub fn encrypt(input: &str) -> String {
10    let (ptr, len) = ft_sys::memory::string_to_bytes_ptr(input.to_owned());
11    let ptr = unsafe { crypto_encrypt(ptr, len) };
12    ft_sys::memory::string_from_ptr(ptr)
13}
14
15/// Decrypt a string. The decryption is done in host, and host manages the decryption
16/// key. This function should be used if you want to retrieve encrypted sensitive data
17/// from the database.
18pub fn decrypt(input: &str) -> Result<String, ft_sys::DecryptionError> {
19    let (ptr, len) = ft_sys::memory::string_to_bytes_ptr(input.to_owned());
20    let ptr = unsafe { crypto_decrypt(ptr, len) };
21    ft_sys::memory::json_from_ptr(ptr)
22}