freefare
High-level Rust bindings for the libfreefare library.
This crate builds on top of freefare-sys and keeps the common libfreefare workflows a little more ergonomic with Result-returning wrappers and Rust slices where the C API allows it.
It is still a relatively thin wrapper. Many operations continue to use raw FreefareTag handles and inherit the lifetime and ownership rules of the native library.
The high-level API uses freefare::Result<T> and freefare::Error for wrapper
validation failures and libfreefare-reported errors.
Installation
Install both native libraries first:
- macOS:
brew install libfreefare libnfc - Debian/Ubuntu:
sudo apt install libfreefare-dev libnfc-dev
Then add:
[]
= "1.0.0"
Linking
This crate relies on freefare-sys to link libfreefare, and on nfc-sys to link libnfc.
If libfreefare is installed in a non-standard location, set LIBFREEFARE_LIB_DIR. The legacy LIBFREEFARE_PATH variable is also supported through freefare-sys.
If libnfc is installed in a non-standard location, set LIBNFC_LIB_DIR.
Example
use Freefare;
use Mifare;
API Shape
freefare 1.0.0 brings the crate metadata, documentation, and dependency versions in line with the newer nfc, nfc-sys, and freefare-sys releases.
The crate exposes two layers:
- the existing wrapper modules such as
freefare,mifare,mad, andtlv - the raw FFI surface through
freefare::ffi
As part of the 1.0.0 alignment with freefare-sys, wrappers for old non-public libfreefare symbols were dropped. The crate now tracks the public header surface exposed by freefare-sys.
Two mifare_application_* sector-list helpers are intentionally left raw-only through freefare::ffi because the native API does not document a length-bearing wrapper contract for those returned lists clearly enough for this crate to model them confidently as safe Rust collections.
Safety
This crate is more ergonomic than freefare-sys, but it is not a fully safe ownership wrapper in the same sense as nfc.
Callers still need to ensure that:
- raw tag and key handles remain valid for the duration of each call
- native memory returned by libfreefare is only freed through the correct libfreefare function
- device and tag lifetimes are coordinated correctly with the underlying
libnfcsession - raw-only APIs exposed through
freefare::ffimay have additional ownership requirements that are not modeled by the high-level wrapper layer
License
MIT