hessra_ffi/lib.rs
1//! C FFI bindings for Hessra token verification and configuration.
2//!
3//! This module provides a C-compatible interface for the core functionality
4//! of the Hessra SDK, focused on token verification and configuration management.
5
6use std::ffi::CString;
7use std::os::raw::c_char;
8
9mod config;
10mod error;
11mod token;
12
13pub use config::{HessraConfig, HessraPublicKey};
14pub use error::HessraResult;
15
16/// Version information for the Hessra FFI library
17#[no_mangle]
18pub extern "C" fn hessra_version() -> *const c_char {
19 static VERSION: &str = env!("CARGO_PKG_VERSION");
20 let c_str = CString::new(VERSION).unwrap_or_default();
21 c_str.into_raw()
22}
23
24/// Free a string allocated by the Hessra library
25///
26/// # Safety
27///
28/// This function must only be called with a pointer that was previously returned by a
29/// Hessra library function that returns a string (like `hessra_version`).
30/// The pointer must not be null and must not have been freed before.
31/// After this call, the pointer is invalid and should not be used.
32#[no_mangle]
33pub unsafe extern "C" fn hessra_string_free(string: *mut c_char) {
34 if !string.is_null() {
35 let _ = CString::from_raw(string);
36 }
37}
38
39/// Initialize the Hessra library.
40/// This function should be called before using any other functions.
41#[no_mangle]
42pub extern "C" fn hessra_init() -> HessraResult {
43 // Any global initialization can be done here
44 error::HessraResult::SUCCESS
45}