mirror of
https://github.com/trussed-dev/apdu-dispatch.git
synced 2026-06-20 04:16:15 -07:00
Do not deselect applications if the application was not found
This commit is contained in:
committed by
sosthene-nitrokey
parent
7e68a8d471
commit
228013cecc
@@ -8,6 +8,8 @@
|
||||
//!
|
||||
//! Apps need to implement the App trait to be managed.
|
||||
//!
|
||||
use core::mem;
|
||||
|
||||
use crate::response::SIZE as ResponseSize;
|
||||
use crate::App;
|
||||
use crate::{
|
||||
@@ -381,14 +383,6 @@ impl<'pipe> ApduDispatch<'pipe> {
|
||||
// not necessarily the case for other apps
|
||||
|
||||
// if there is a selected app with a different AID, deselect it
|
||||
if let Some(current_aid) = self.current_aid {
|
||||
if current_aid != aid {
|
||||
let app = Self::find_app(self.current_aid.as_ref(), apps).unwrap();
|
||||
// for now all apps will be happy with this.
|
||||
app.deselect();
|
||||
self.current_aid = None;
|
||||
}
|
||||
}
|
||||
|
||||
// select specified app in any case
|
||||
if let Some(app) = Self::find_app(Some(&aid), apps) {
|
||||
@@ -401,7 +395,14 @@ impl<'pipe> ApduDispatch<'pipe> {
|
||||
_ => panic!("Unexpected buffer state."),
|
||||
};
|
||||
|
||||
self.current_aid = Some(aid);
|
||||
let old_aid = mem::replace(&mut self.current_aid, Some(aid));
|
||||
if let Some(old_aid) = old_aid {
|
||||
if old_aid != aid {
|
||||
let app = Self::find_app(self.current_aid.as_ref(), apps).unwrap();
|
||||
// for now all apps will be happy with this.
|
||||
app.deselect();
|
||||
}
|
||||
}
|
||||
|
||||
self.handle_app_response(&result, &response);
|
||||
} else {
|
||||
|
||||
@@ -324,6 +324,25 @@ fn select_not_found() {
|
||||
])
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn select_not_found_still_selected() {
|
||||
run_apdus(&[
|
||||
// Select
|
||||
&hex!("00A40400 05 0A01000001"),
|
||||
// Ok
|
||||
&hex!("9000"),
|
||||
// Select
|
||||
&hex!("00A40400 05 0A01000100"),
|
||||
// Not found
|
||||
&hex!("6A82"),
|
||||
// Echo app is still selected
|
||||
&hex!("80100000 05 0102030405 00"),
|
||||
// Echo + Ok
|
||||
&hex!("0000000000 0102030405 9000"),
|
||||
])
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn select_bad_aid() {
|
||||
|
||||
Reference in New Issue
Block a user