-
Notifications
You must be signed in to change notification settings - Fork 1
Description
What problem does this solve?
Currently, nexum-keycard has a hard dependency on PCSC (PC/SC smart card) libraries, which prevents compilation for targets that don't support PCSC, such as Android. This blocks mobile platform support and limits the portability of the keycard integration.
Android and other mobile platforms need to use different smart card APIs (e.g., NFC on Android uses the Android NFC API, not PCSC). The current architecture forces PCSC to be compiled even when targeting platforms where it won't work.
Describe the solution
Make PCSC support optional via Cargo feature flags:
- Add feature flag: Create a
pcscfeature flag (enabled by default for backward compatibility) - Conditional compilation: Wrap PCSC-specific code with
#[cfg(feature = "pcsc")] - Abstraction layer: Define a trait for smart card communication that can have multiple implementations:
- PCSC implementation (behind
pcscfeature) - Future: Android NFC implementation
- Future: iOS NFC implementation
- PCSC implementation (behind
- Update dependencies: Make
pcsccrate optional inCargo.toml
This allows:
- Building for Android without PCSC:
cargo build --target aarch64-linux-android --no-default-features - Keeping existing PCSC support:
cargo build(default behavior unchanged) - Adding alternative backends in the future
Alternatives considered
-
Separate crates: Could split into
nexum-keycard-coreandnexum-keycard-pcsc, but this adds maintenance overhead and complicates the API surface. -
Runtime detection: Could try to detect PCSC availability at runtime, but this doesn't solve the compilation problem and still requires PCSC libraries to be present during build.
-
Fork for mobile: Could maintain separate forks for mobile platforms, but this creates significant maintenance burden and drift.
Making PCSC optional via features is the standard Rust approach and provides maximum flexibility with minimal complexity.
Implementation notes
Affected areas:
nexum-keycard/Cargo.toml: Add feature flag and makepcscdependency optionalnexum-keycard/src/lib.rs: Feature-gate PCSC imports and implementations- Smart card communication layer: Extract trait for backend abstraction
- Documentation: Update build instructions for cross-compilation
Example feature flag structure:
[features]
default = ["pcsc"]
pcsc = ["dep:pcsc"]
[dependencies]
pcsc = { version = "2.x", optional = true }Related work:
- Epic 5 (Keycard Advanced Features) includes secure channel abstraction, which aligns with this architectural change
- This unblocks future mobile wallet development
Are you willing to PR this?
Yes, if given guidance on the preferred abstraction layer design.