Skip to content

Commit fe95252

Browse files
Update to heapless 0.9.1 and iso7816 0.2.0
1 parent edf19e9 commit fe95252

File tree

6 files changed

+32
-31
lines changed

6 files changed

+32
-31
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ license = "Apache-2.0 OR MIT"
99
repository = "https://github.com/trussed-dev/apdu-dispatch"
1010

1111
[workspace.dependencies]
12-
iso7816 = "0.1.2"
12+
iso7816 = "0.2.0"
13+
heapless = "0.9"
1314

1415
[patch.crates-io]
1516
apdu-app.path = "app"
17+
iso7816 = { git = "https://github.com/trussed-dev/iso7816.git", branch = "heapless-09"}

app/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ repository.workspace = true
1010

1111
[dependencies]
1212
iso7816.workspace = true
13+
heapless.workspace = true

app/src/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
#![no_std]
22

3-
pub use iso7816::{command::CommandView, Data, Interface, Status};
3+
use heapless::VecView;
4+
pub use iso7816::{command::CommandView, Interface, Status};
45

56
pub type Result = iso7816::Result<()>;
67

78
/// An App can receive and respond APDUs at behest of the ApduDispatch.
8-
pub trait App<const R: usize>: iso7816::App {
9+
pub trait App: iso7816::App {
910
/// Given parsed APDU for select command.
1011
/// Write response data back to buf, and return length of payload. Return APDU Error code on error.
1112
/// Alternatively, the app can defer the response until later by returning it in `poll()`.
1213
fn select(
1314
&mut self,
1415
interface: Interface,
1516
apdu: CommandView<'_>,
16-
reply: &mut Data<R>,
17+
reply: &mut VecView<u8>,
1718
) -> Result;
1819

1920
/// Deselects the app. This is the result of another app getting selected.
@@ -22,5 +23,10 @@ pub trait App<const R: usize>: iso7816::App {
2223

2324
/// Given parsed APDU for app when selected.
2425
/// Write response data back to buf, and return length of payload. Return APDU Error code on error.
25-
fn call(&mut self, interface: Interface, apdu: CommandView<'_>, reply: &mut Data<R>) -> Result;
26+
fn call(
27+
&mut self,
28+
interface: Interface,
29+
apdu: CommandView<'_>,
30+
reply: &mut VecView<u8>,
31+
) -> Result;
2632
}

dispatch/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ repository.workspace = true
1111
[dependencies]
1212
apdu-app = "0.1.0"
1313
delog = "0.1.4"
14-
heapless = "0.7"
1514
interchange = "0.3.0"
1615
iso7816.workspace = true
16+
heapless.workspace = true
1717

1818
[dev-dependencies]
1919
# Testing

dispatch/src/dispatch.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ impl<'pipe> ApduDispatch<'pipe> {
123123
// but that won't work due to ownership rules
124124
fn find_app<'a, 'b>(
125125
aid: Option<&Aid>,
126-
apps: &'a mut [&'b mut dyn App<ResponseSize>],
127-
) -> Option<&'a mut &'b mut dyn App<ResponseSize>> {
126+
apps: &'a mut [&'b mut dyn App],
127+
) -> Option<&'a mut &'b mut dyn App> {
128128
// match aid {
129129
// Some(aid) => apps.iter_mut().find(|app| aid.starts_with(app.rid())),
130130
// None => None,
@@ -366,12 +366,7 @@ impl<'pipe> ApduDispatch<'pipe> {
366366
}
367367

368368
#[inline(never)]
369-
fn handle_app_select(
370-
&mut self,
371-
apps: &mut [&mut dyn App<ResponseSize>],
372-
aid: Aid,
373-
interface: Interface,
374-
) {
369+
fn handle_app_select(&mut self, apps: &mut [&mut dyn App], aid: Aid, interface: Interface) {
375370
// three cases:
376371
// - currently selected app has different AID -> deselect it, to give it
377372
// the chance to clear sensitive state
@@ -412,11 +407,7 @@ impl<'pipe> ApduDispatch<'pipe> {
412407
}
413408

414409
#[inline(never)]
415-
fn handle_app_command(
416-
&mut self,
417-
apps: &mut [&mut dyn App<ResponseSize>],
418-
interface: Interface,
419-
) {
410+
fn handle_app_command(&mut self, apps: &mut [&mut dyn App], interface: Interface) {
420411
// if there is a selected app, send it the command
421412
let mut response = response::Data::new();
422413
if let Some(app) = Self::find_app(self.current_aid.as_ref(), apps) {
@@ -431,7 +422,7 @@ impl<'pipe> ApduDispatch<'pipe> {
431422
};
432423
}
433424

434-
pub fn poll(&mut self, apps: &mut [&mut dyn App<ResponseSize>]) -> Option<Interface> {
425+
pub fn poll(&mut self, apps: &mut [&mut dyn App]) -> Option<Interface> {
435426
// Only take on one transaction at a time.
436427
let request_type = self.check_for_request();
437428

dispatch/tests/dispatch.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use apdu_dispatch::app::{App, CommandView, Result as AppResult};
22
use apdu_dispatch::dispatch;
33
use apdu_dispatch::{interchanges, response};
4+
use heapless::VecView;
45
use hex_literal::hex;
56
use interchange::Channel;
67
use iso7816::Status;
@@ -47,12 +48,12 @@ impl iso7816::App for TestApp1 {
4748
}
4849

4950
// This app echos to Ins code 0x10
50-
impl App<{ apdu_dispatch::response::SIZE }> for TestApp1 {
51+
impl App for TestApp1 {
5152
fn select(
5253
&mut self,
5354
_interface: dispatch::Interface,
5455
_apdu: CommandView<'_>,
55-
_reply: &mut response::Data,
56+
_reply: &mut VecView<u8>,
5657
) -> AppResult {
5758
Ok(())
5859
}
@@ -63,7 +64,7 @@ impl App<{ apdu_dispatch::response::SIZE }> for TestApp1 {
6364
&mut self,
6465
_: dispatch::Interface,
6566
apdu: CommandView<'_>,
66-
reply: &mut response::Data,
67+
reply: &mut VecView<u8>,
6768
) -> AppResult {
6869
println!("TestApp1::call");
6970
match apdu.instruction().into() {
@@ -79,8 +80,8 @@ impl App<{ apdu_dispatch::response::SIZE }> for TestApp1 {
7980
}
8081
// For measuring the stack burden of dispatch
8182
0x15 => {
82-
let buf = heapless::Vec::new();
83-
let addr = (&buf as *const response::Data) as u32;
83+
let buf = heapless::Vec::<u8, { response::SIZE }>::new();
84+
let addr = (&buf as *const VecView<u8>).addr() as u32;
8485
reply.extend_from_slice(&addr.to_be_bytes()).unwrap();
8586
Ok(())
8687
}
@@ -122,12 +123,12 @@ impl iso7816::App for TestApp2 {
122123
}
123124

124125
// This app echos to Ins code 0x20
125-
impl App<{ apdu_dispatch::response::SIZE }> for TestApp2 {
126+
impl App for TestApp2 {
126127
fn select(
127128
&mut self,
128129
_interface: dispatch::Interface,
129130
_apdu: CommandView<'_>,
130-
_reply: &mut response::Data,
131+
_reply: &mut VecView<u8>,
131132
) -> AppResult {
132133
Ok(())
133134
}
@@ -138,7 +139,7 @@ impl App<{ apdu_dispatch::response::SIZE }> for TestApp2 {
138139
&mut self,
139140
_: dispatch::Interface,
140141
apdu: CommandView<'_>,
141-
reply: &mut response::Data,
142+
reply: &mut VecView<u8>,
142143
) -> AppResult {
143144
println!("TestApp2::call");
144145
match apdu.instruction().into() {
@@ -174,12 +175,12 @@ impl iso7816::App for PanicApp {
174175
}
175176

176177
// This app echos to Ins code 0x20
177-
impl App<{ apdu_dispatch::response::SIZE }> for PanicApp {
178+
impl App for PanicApp {
178179
fn select(
179180
&mut self,
180181
_interface: dispatch::Interface,
181182
_apdu: CommandView<'_>,
182-
_reply: &mut response::Data,
183+
_reply: &mut VecView<u8>,
183184
) -> AppResult {
184185
panic!("Dont call the panic app");
185186
}
@@ -192,7 +193,7 @@ impl App<{ apdu_dispatch::response::SIZE }> for PanicApp {
192193
&mut self,
193194
_: dispatch::Interface,
194195
_apdu: CommandView<'_>,
195-
_reply: &mut response::Data,
196+
_reply: &mut VecView<u8>,
196197
) -> AppResult {
197198
panic!("Dont call the panic app");
198199
}

0 commit comments

Comments
 (0)