Skip to content

[FEATURE] Make PCSC optional for nexum-keycard compilation #123

@mfw78

Description

@mfw78

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:

  1. Add feature flag: Create a pcsc feature flag (enabled by default for backward compatibility)
  2. Conditional compilation: Wrap PCSC-specific code with #[cfg(feature = "pcsc")]
  3. Abstraction layer: Define a trait for smart card communication that can have multiple implementations:
    • PCSC implementation (behind pcsc feature)
    • Future: Android NFC implementation
    • Future: iOS NFC implementation
  4. Update dependencies: Make pcsc crate optional in Cargo.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

  1. Separate crates: Could split into nexum-keycard-core and nexum-keycard-pcsc, but this adds maintenance overhead and complicates the API surface.

  2. 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.

  3. 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 make pcsc dependency optional
  • nexum-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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    dxDeveloper experience is suffering.effort/daysFew days. Needs design.featureNew capability that doesn't exist yet.p2-annoyingNot broken, but annoying enough to matter.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions