Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/rad-id-sync/blob/main/src/ffi.rs # rad-id-sync This project has not described itself yet. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `rad-id-sync / src / ffi.rs` 40 lines ยท 1128 bytes Raw Blame History 1 use std::ffi::CString; 2 use std::os::raw::c_char; 3 use crate::identity::IdentityAnchor; 4 use crate::keys::sync_identity_keys; 5 6 #[no_mangle] 7 pub 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] 20 pub 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] 29 pub 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 }