From 32757ada31133cce75c0d4708d266e74056cbdc1 Mon Sep 17 00:00:00 2001 From: Nicolas Stalder Date: Sat, 5 Jun 2021 19:52:16 +0200 Subject: [PATCH] More cleanup --- Cargo.toml | 1 - src/apdu_dispatch.rs | 37 +++++++++++++++++++++++++++++++++++++ src/lib.rs | 31 +++---------------------------- 3 files changed, 40 insertions(+), 29 deletions(-) create mode 100644 src/apdu_dispatch.rs diff --git a/Cargo.toml b/Cargo.toml index f8215db..ae14ad8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,6 @@ rand_core = { version = "0.5.1", features = ["getrandom"] } [features] default = [] -applet = ["apdu-dispatch"] strict-pin = [] log-all = [] diff --git a/src/apdu_dispatch.rs b/src/apdu_dispatch.rs new file mode 100644 index 0000000..83fac28 --- /dev/null +++ b/src/apdu_dispatch.rs @@ -0,0 +1,37 @@ +use crate::{Authenticator, constants::PIV_AID, Result}; + +use apdu_dispatch::{ + app::{Aid, App}, + command::Size as CommandSize, + Command, + response::{Data, Size as ResponseSize}, +}; +use trussed::client; + +impl Aid for Authenticator { + + fn aid(&self) -> &'static [u8] { + &PIV_AID + } + + fn right_truncated_length(&self) -> usize { + 11 + } +} + + +#[cfg(feature = "apdu-dispatch")] +impl App for Authenticator +where + T: client::Client + client::Ed255 + client::Tdes +{ + fn select(&mut self, apdu: &Command, reply: &mut Data) -> Result { + self.select(apdu, reply) + } + + fn deselect(&mut self) { self.deselect() } + + fn call(&mut self, _: iso7816::Interface, apdu: &Command, reply: &mut Data) -> Result { + self.respond(apdu, reply) + } +} diff --git a/src/lib.rs b/src/lib.rs index 6a24781..15d766c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,9 @@ pub mod derp; pub mod piv_types; pub use piv_types::{Pin, Puk}; +#[cfg(feature = "apdu-dispatch")] +mod apdu_dispatch; + use core::convert::TryInto; use flexiber::EncodableHeapless; @@ -1069,31 +1072,3 @@ where } -#[cfg(feature = "apdu-dispatch")] -impl apdu_dispatch::app::Aid for Authenticator { - - fn aid(&self) -> &'static [u8] { - &constants::PIV_AID - } - - fn right_truncated_length(&self) -> usize { - 11 - } -} - - -#[cfg(feature = "apdu-dispatch")] -impl apdu_dispatch::app::App for Authenticator -where - T: client::Client + client::Ed255 + client::Tdes -{ - fn select(&mut self, apdu: &apdu_dispatch::Command, reply: &mut apdu_dispatch::response::Data) -> Result { - self.select(apdu, reply) - } - - fn deselect(&mut self) { self.deselect() } - - fn call(&mut self, _: iso7816::Interface, apdu: &apdu_dispatch::Command, reply: &mut apdu_dispatch::response::Data) -> Result { - self.respond(apdu, reply) - } -}