1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//! `GlobalPlatform` APDU builders — PDD §5 (pure; §3.5).
//!
//! Each submodule builds the C-APDU **plaintext**; SCP wrapping (`CLA | 0x04`,
//! C-MAC, optional C-ENC) is applied later by the session/backend. Verified
//! wire values are documented per submodule against GPCS v2.3.1 §11.
//!
//! `no_std`: builders return a fixed-capacity [`Capdu`] instead of `Vec<u8>`.
//! Because a `heapless` push is fallible, the builders are total — oversized
//! input returns [`BuildError::Overflow`] rather than panicking (the no-panic
//! invariant, §10.5) — so each now returns `Result<Capdu, BuildError>`.
//!
//! All builders share the [`build`] short-APDU framer and the [`push`] /
//! [`push_lv`] helpers below (private to this module; visible to the
//! submodules). `build` lays out the ISO/IEC 7816-4:2020 §5.1 short-APDU cases:
//! empty data ⇒ no `Lc` (Case 1/2), `le` ⇒ a trailing `Le = 00` ("all
//! available"). Only SET STATUS omits `Le` (Case 1/3, Table 11-85).
use Vec;
use crateCAPDU_MAX;
// DELETE (INS E4): object + key scope — §5.3.3/§5.5/§5.8, GPCS §11.2
// GET DATA '66'/'67'/'00E0'/IIN/CIN — §5.2
// GET STATUS (INS F2) — §5.12, GPCS §11.4
// INSTALL (INS E6): for Load/Install/Personalization — §5.4/§5.4a/§5.6/§5.7
// PUT KEY (INS D8) — §5.3.1, GPCS §11.8
// BEGIN/END R-MAC SESSION (INS 7A/78) — SCP02, GPCS App E
// SELECT — ISO/IEC 7816-4; §5.2/§5.9
// SET STATUS (INS F0) — §5.11, GPCS §11.10 // LOAD (INS E8) — §5.4a, GPCS §11.6
/// A built short C-APDU plaintext buffer (≤ `CAPDU_MAX`). SCP wrapping (C-MAC,
/// optional C-ENC) is applied later by the session, which may grow it — still
/// within `CAPDU_MAX` for short APDUs.
pub type Capdu = ;
/// Command-builder failure. Builders are total (no panic on any input): inputs
/// that would exceed the short-APDU buffer return `Overflow`.
/// Assemble a short C-APDU plaintext: 4-byte header, optional `Lc`+data,
/// optional `Le`.
///
/// Empty `data` ⇒ no `Lc`/data bytes (ISO/IEC 7816-4:2020 §5.1, Case 1/2).
/// `le = true` appends a single `0x00` (`Le`, "all available"). Total: any
/// `data` longer than a short `Lc` (255) yields [`BuildError::Overflow`]
/// instead of panicking.
/// Append `src` to `out`, mapping the `heapless` capacity error to `Overflow`.
/// Append a 1-byte-length-prefixed field `len ‖ bytes` — the INSTALL field
/// layout and the value half of a 1-byte-length BER-TLV. `bytes` longer than
/// 255 ⇒ [`BuildError::Overflow`].