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
//! Abstraction over the link that carries APDUs to and from the card.
//!
//! [`Card`](crate::Card) owns a transport and layers APDU encoding, response parsing and card
//! operations over it. Applications that already have another smart-card link can use the rest
//! of this crate without enabling the `pcsc` feature by implementing [`Transmit`].
use crateResult;
/// Something that can exchange raw APDUs with a card.
///
/// Implementors are responsible for the physical link only. They do not interpret the bytes,
/// and in particular they must return the response *including* its trailing status word.
/// `command` is already encoded by [`Command::to_bytes`](crate::Command::to_bytes), so it must be
/// forwarded unchanged. Protocol recovery such as retrying `6Cxx` and collecting `61xx` belongs
/// to [`Card::call`](crate::Card::call), not to the transport.
///
/// Transport failures should be returned as [`Error`](crate::Error). A status reported by the
/// card is not a transport failure: include its SW1-SW2 bytes in the returned vector and let the
/// card layer classify it.
///
/// # Example
///
/// A minimal transport can be useful when embedding the crate behind an existing device API:
///
/// ```
/// use myna_card::{Card, Command, Result, Transmit};
///
/// struct AlwaysSucceeds;
///
/// impl Transmit for AlwaysSucceeds {
/// fn transmit(&mut self, command: &[u8]) -> Result<Vec<u8>> {
/// assert_eq!(command, [0x00, 0xA4, 0x02, 0x0C, 0x02, 0x00, 0x01]);
/// Ok(vec![0x90, 0x00]) // response data is empty; SW is 9000
/// }
/// }
///
/// let mut card = Card::new(AlwaysSucceeds);
/// card.select_ef(0x0001)?;
/// # Ok::<(), myna_card::Error>(())
/// ```