freefare-sys
Raw FFI bindings to the public libfreefare C API.
This crate intentionally stays low level. It exposes the upstream ABI for use by higher-level Rust wrappers and NFC tooling, and does not add safe abstractions over tag access, authentication, or memory management.
What changed in 1.0.0
Version 1.0.0 is a breaking cleanup release:
- The binding surface now tracks the public
freefare.hAPI instead of exposing generator artifacts and non-header symbols. - Opaque native types such as
MifareTag,MifareDESFireKey,Mad, andMifareDESFireAIDare no longer represented as fake Rust structs with internals. - Old
Struct_*andEnum_*bindgen names were replaced with stable Rust-facing FFI names. - Unsound
Defaultimplementations based onmem::zeroed()were removed. - Modern Rust FFI types are used throughout (
c_char,c_int,c_void,u8,u16,u32,usize,isize). - The crate now ships smoke tests for layout assumptions and native linking.
Native dependencies
You need both libfreefare and libnfc installed on the system.
macOS with Homebrew
Debian or Ubuntu
Linking
build.rs links against freefare. The nfc-sys dependency links libnfc.
By default it checks common Homebrew and Linux library directories for libfreefare. If your libfreefare installation lives elsewhere, set either the preferred LIBFREEFARE_LIB_DIR variable or the legacy LIBFREEFARE_PATH variable:
Usage
[]
= "1"
= "0.2"
= "1"
Example
use CStr;
use ptr;
Safety
This crate exposes raw C bindings. Callers are responsible for:
- Upholding all pointer validity and lifetime requirements from
libfreefare. - Freeing memory returned by the native library with the correct native deallocator.
- Ensuring linked
libfreefareandlibnfcversions are ABI-compatible with the declarations in this crate.
Versioning
The Rust crate version follows the Rust FFI surface, not the upstream libfreefare release number. Breaking binding corrections or symbol removals may require a new major version even when the C library version is unchanged.
License
MIT