Skip to content

Building

How to choose what goes into a build, use a7pay from your own project, and run the tests.

  • Rust, stable, edition 2024 (install with rustup).
  • For the specification-based tests only: your own copies of the specifications, downloaded from EMVCo and nexo standards (they aren’t distributed with the code), in a directory laid out as specs/pdf, specs/md and specs/txt. Point the A7DOC environment variable to it (by default, a7doc/ beside the repository). The tests that need them skip when they are absent.
cargo build --workspace
cargo test --workspace --all-features

Add one crate, a7pay, and choose its parts with features:

[dependencies]
a7pay = { git = "https://github.com/a7mp/a7pay" }
use a7pay::emvco::l2::ep::EntryPoint;       // EMV: Entry Point and the kernels
use a7pay::platform::reader::Reader;         // the interfaces your device implements
Module What it is Feature
a7pay::emvco EMV Level 2 (Entry Point, the kernels, the reader’s transaction around them) and the Level 3 test platform the kernels by default; l3
a7pay::platform The interfaces your device implements (card reader, cryptography, security module, PIN pad), software implementations, a PC/SC reader: see Platform always
a7pay::nexo The nexo protocols and the nexo FAST payment application: see nexo nexo

Behind it, each module is a crate of its own (a7pay-emvco, a7pay-platform, a7pay-nexo, in crates/), which a7pay re-exports. You only ever depend on a7pay.

By default you get Entry Point, every kernel and the platform interfaces. The host protocols and the test platform are opt-in. That suits development; a terminal’s firmware takes only what it uses.

Feature What it adds Default
l2 EMV Level 2: Entry Point and the EMV functions the kernels share yes, through the kernels
c2 Kernel 2 (EMVCo Book C-2: Mastercard cards) yes
c3 Kernel 3 (Book C-3: Visa) yes
c4 Kernel 4 (Book C-4: American Express) yes
c6 Kernel 6 (Book C-6: Discover, Diners Club) yes
c8 Kernel 8 (Book C-8: EMVCo’s common kernel) yes
c2-de-ds, c3-ids, … A kernel’s optional parts, see Kernels no
brand-mastercard, brand-amex, brand-discover A scheme’s certified behaviour, see Kernels no
vreader, vcrypto, vpinpad Software card reader, cryptography and PIN pad, for tests. Keys in memory, in clear no
std The standard library in a7pay::platform (the software implementations bring it) no
swcrypto Software cryptography for the kernels on a device, without the standard library: see Platform no
pcsc A real contactless reader over PC/SC, to run the kernels against real cards on a desktop no
nexo a7pay::nexo: the nexo protocols and nexo FAST no
nexo-net nexo over TCP, for the test environment no
l3 The Level 3 test platform (a7pay::emvco::l3): simulated cards, logs, pass criteria; its test-case runner; with nexo its network simulator. Brings in the standard library and an XML parser no
l3-testing Test material (a Kernel 8 card image) for tests; brings l3 and c8 no

Each kernel feature brings l2, and each optional or brand feature brings its kernel.

Example: a terminal with Mastercard and Visa only

Section titled “Example: a terminal with Mastercard and Visa only”
[dependencies]
a7pay = { git = "https://github.com/a7mp/a7pay", default-features = false, features = ["c2", "c3"] }

That build carries Entry Point, Kernels 2 and 3 and the platform interfaces, and nothing else. It has no test platform, no XML parser and no standard library: it runs without an operating system, on alloc alone, and depends on two small crates (hex, log).

The terminal is configured with Combinations (an AID and its kernel, see Entry Point). If it is configured with a Combination for a kernel the build doesn’t carry, Kernel Activation answers UnsupportedKernel for it. a7pay::emvco::l2::k::is_built(kernel_id) tells which kernels a build has, to check a configuration against it.

a7pay = { git = "https://github.com/a7mp/a7pay", default-features = false, features = ["c3-issuer-update"] }

c3-issuer-update brings c3, which brings l2.

a7pay = { git = "https://github.com/a7mp/a7pay", features = ["nexo", "vcrypto", "vpinpad"] }

nexo builds on every kernel, whatever the kernel features say, and turns on c3-issuer-update (nexo FAST’s second tap).

The test environment’s programs have features of their own: tui (vpoi, salesim: a full-screen interface instead of log lines) and pcsc (vpoi: real cards on a PC/SC reader).

cargo test --workspace --all-features   # everything
cargo test -p a7pay-emvco                # the kernels, as the public Books describe them
cargo clippy --workspace --all-targets --all-features

The kernels’ behaviour depends on their features, so the kernels are tested in several builds:

cargo test -p a7pay-emvco --no-default-features --features c3     # one kernel on its own
cargo test -p a7pay-emvco --features brand-mastercard             # with a scheme's behaviour
cargo test -p a7pay-emvco --features c6-data-storage              # with an optional behaviour
cargo test -p a7pay-emvco --features l3                           # with the test platform

Most of a7pay-emvco’s tests are one per requirement, named after it, beside the function that implements it.

Two more kinds of tests run elsewhere:

  • The kernels against the schemes’ certification test suites: in the private repository, see Level 2 test suites.
  • Whole payments through the virtual terminal: see Test environment.

The kernels log every requirement they apply and every command exchanged with the card:

RUST_LOG=debug cargo test -p a7pay-emvco <test name> -- --nocapture

When a transaction fails, the log shows:

  • each command sent to the card and its response;
  • each data item the kernel rejected from the card, and why (tag, length, template, permission);
  • each requirement the kernel applied, with its number in the Book.

tools/nexo-codegen generates crates/a7pay-nexo/src/iso20022/types.rs, nexo’s ISO 20022 message types, from the XSD schemas in iso-20022/ (not distributed, like the specifications). Never edit types.rs by hand: change the schemas or the generator, and regenerate.

cargo run -p nexo-codegen               # regenerate types.rs
cargo run -p nexo-codegen -- --check    # fail if types.rs is out of date (its tests run this)

It supports only the subset of XSD the nexo schemas use, and stops with an error on anything else rather than guessing. It is a separate tool, not part of nexo, so that a broken types.rs can’t stop the generator that fixes it.