mirror of
https://github.com/trussed-dev/apdu-dispatch.git
synced 2026-06-20 04:16:15 -07:00
Use iso7816::Aid
This commit is contained in:
+2
-1
@@ -25,7 +25,8 @@ std = ["delog/std", "serial_test"]
|
||||
|
||||
log-all = []
|
||||
log-none = []
|
||||
log-info = []
|
||||
log-debug = []
|
||||
log-info = []
|
||||
log-trace = []
|
||||
log-warn = []
|
||||
log-error = []
|
||||
|
||||
+1
-32
@@ -3,39 +3,8 @@ pub type Result = iso7816::Result<()>;
|
||||
|
||||
pub use crate::{ArrayLength, dispatch::Interface};
|
||||
|
||||
/// The Aid is used to determine whether or not the App will be selected.
|
||||
/// Only `aid()` and `right_truncated_length()` need to be implemented.
|
||||
pub trait Aid {
|
||||
|
||||
fn aid(&self) -> &'static [u8];
|
||||
|
||||
fn right_truncated_length(&self) -> usize;
|
||||
|
||||
fn len(&self) -> usize {
|
||||
self.aid().len()
|
||||
}
|
||||
|
||||
fn full(&self) -> &'static [u8] {
|
||||
self.aid()
|
||||
}
|
||||
|
||||
fn right_truncated(&self) -> &'static [u8] {
|
||||
&self.aid()[..self.right_truncated_length()]
|
||||
}
|
||||
|
||||
fn pix(&self) -> &'static [u8] {
|
||||
&self.aid()[5..]
|
||||
}
|
||||
|
||||
fn rid(&self) -> &'static [u8] {
|
||||
&self.aid()[..5]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// An App can receive and respond APDUs at behest of the ApduDispatch.
|
||||
pub trait App<C: ArrayLength<u8>, R: ArrayLength<u8>>: Aid {
|
||||
pub trait App<C: ArrayLength<u8>, R: ArrayLength<u8>>: iso7816::App {
|
||||
/// Given parsed APDU for select command.
|
||||
/// Write response data back to buf, and return length of payload. Return APDU Error code on error.
|
||||
/// Alternatively, the app can defer the response until later by returning it in `poll()`.
|
||||
|
||||
+13
-9
@@ -83,7 +83,8 @@ impl ApduDispatch
|
||||
{
|
||||
fn apdu_type(apdu: &iso7816::Command<impl heapless_bytes::ArrayLength<u8>>) -> RequestType {
|
||||
if apdu.instruction() == Instruction::Select && (apdu.p1 & 0x04) != 0 {
|
||||
RequestType::Select(Aid::try_from_slice(apdu.data()).unwrap())
|
||||
// RequestType::Select(Aid::try_from_slice(apdu.data()).unwrap())
|
||||
RequestType::Select(Aid::new(apdu.data(), apdu.data().len()))
|
||||
} else if apdu.instruction() == Instruction::GetResponse {
|
||||
RequestType::GetResponse
|
||||
} else {
|
||||
@@ -118,11 +119,14 @@ impl ApduDispatch
|
||||
// Some(aid) => apps.iter_mut().find(|app| aid.starts_with(app.rid())),
|
||||
// None => None,
|
||||
// }
|
||||
aid.and_then(move |aid|
|
||||
apps.iter_mut().find(|app|
|
||||
aid.starts_with(app.aid())
|
||||
)
|
||||
)
|
||||
aid.and_then(move |aid| {
|
||||
debug_now!("matching {:?}", aid);
|
||||
apps.iter_mut().find(|app| {
|
||||
// aid.starts_with(app.aid().truncated())
|
||||
debug_now!("...against {:?}", app.aid());
|
||||
app.aid().matches(aid)
|
||||
} )
|
||||
})
|
||||
}
|
||||
|
||||
fn busy(&self) -> bool {
|
||||
@@ -354,8 +358,8 @@ impl ApduDispatch
|
||||
// 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.as_ref() {
|
||||
if *current_aid != *aid {
|
||||
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();
|
||||
@@ -381,7 +385,7 @@ impl ApduDispatch
|
||||
|
||||
|
||||
} else {
|
||||
info!("could not find app by aid: {}", hex_str!(&aid));
|
||||
info!("could not find app by aid: {}", hex_str!(&aid.as_bytes()));
|
||||
self.reply_error(Status::NotFound);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user