interplane.Get Omega
Read in your language

rad-id-sync

This project has not described itself yet.

Brought by drakestapleton

branch main Branches Tags History

rad-id-sync / src / ffi.rs

40 lines · 1128 bytes Raw Blame History
1use std::ffi::CString;
2use std::os::raw::c_char;
3use crate::identity::IdentityAnchor;
4use crate::keys::sync_identity_keys;
5
6#[no_mangle]
7pub extern "C" fn rad_id_sync_status_json() -> *mut c_char {
8 let result = match IdentityAnchor::load_or_init() {
9 Ok(anchor) => match sync_identity_keys(anchor) {
10 Ok((_, report)) => serde_json::to_string(&report).unwrap_or_else(|e| format!("{{\"error\":\"{}\"}}", e)),
11 Err(e) => format!("{{\"error\":\"{}\"}}", e),
12 },
13 Err(e) => format!("{{\"error\":\"{}\"}}", e),
14 };
15
16 CString::new(result).unwrap_or_default().into_raw()
17}
18
19#[no_mangle]
20pub extern "C" fn rad_id_sync_free_string(ptr: *mut c_char) {
21 if !ptr.is_null() {
22 unsafe {
23 let _ = CString::from_raw(ptr);
24 }
25 }
26}
27
28#[no_mangle]
29pub extern "C" fn rad_id_sync_is_valid() -> i32 {
30 match IdentityAnchor::load_or_init() {
31 Ok(anchor) => {
32 if anchor.primary_radicle_key.is_some() || anchor.primary_ssh_key.is_some() {
33 1
34 } else {
35 0
36 }
37 }
38 Err(_) => 0,
39 }
40}