diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ffi.rs | 40 | ||||
-rw-r--r-- | src/lib.rs | 1 | ||||
-rw-r--r-- | src/sequoia.h | 10 |
3 files changed, 51 insertions, 0 deletions
diff --git a/src/ffi.rs b/src/ffi.rs new file mode 100644 index 00000000..3a7b1c66 --- /dev/null +++ b/src/ffi.rs @@ -0,0 +1,40 @@ +extern crate libc; +use self::libc::{uint8_t, size_t}; + +use std::ptr; +use std::slice; +use keys::TPK; +use openpgp; + +#[no_mangle] +pub extern "system" fn sq_tpk_from_bytes(b: *const uint8_t, len: size_t) -> *mut TPK { + assert!(!b.is_null()); + let bytes = unsafe { + slice::from_raw_parts(b, len as usize) + }; + let m = openpgp::Message::from_bytes(bytes); + + if let Some(tpk) = m.ok().and_then(|m| TPK::from_message(m)) { + Box::into_raw(Box::new(tpk)) + } else { + ptr::null_mut() + } +} + +#[no_mangle] +pub extern "system" fn sq_tpk_dump(tpk: *mut TPK) { + assert!(!tpk.is_null()); + unsafe { + println!("{:?}", *tpk); + } +} + +#[no_mangle] +pub extern "system" fn sq_tpk_free(tpk: *mut TPK) { + if tpk.is_null() { + return + } + unsafe { + drop(Box::from_raw(tpk)); + } +} @@ -14,3 +14,4 @@ pub mod openpgp; pub mod keys; pub mod key_store; pub mod net; +pub mod ffi; diff --git a/src/sequoia.h b/src/sequoia.h new file mode 100644 index 00000000..0853b9aa --- /dev/null +++ b/src/sequoia.h @@ -0,0 +1,10 @@ +#ifndef SEQUOIA_H +#define SEQUOIA_H + +struct sq_tpk; + +struct sq_tpk *sq_tpk_from_bytes (const char *b, size_t len); +void sq_tpk_dump (const struct sq_tpk *tpk); +void sq_tpk_free (struct sq_tpk *tpk); + +#endif |