From 15fc0c7780a587dfacd4d21f2579cd49ce657e1f Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Mon, 19 Apr 2021 00:22:43 -0700 Subject: [PATCH] Move size definitions for large buffers to apdu-dispatch --- src/command.rs | 26 +++++++++++++++++--------- src/lib.rs | 5 ----- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/command.rs b/src/command.rs index fbffc02..ed99864 100644 --- a/src/command.rs +++ b/src/command.rs @@ -1,10 +1,14 @@ +use heapless_bytes::ArrayLength; + pub mod class; pub mod instruction; -pub type Data = crate::Bytes; +use crate::Bytes; #[derive(Clone, Debug, PartialEq, Eq)] -pub struct Command { +pub struct Command +where SIZE: ArrayLength +{ class: class::Class, instruction: instruction::Instruction, @@ -13,13 +17,15 @@ pub struct Command { /// The main reason this is modeled as Bytes and not /// a fixed array is for serde purposes. - data: Data, + data: Bytes, le: usize, pub extended: bool, } -impl Command { +impl Command +where SIZE: ArrayLength +{ pub fn try_from(apdu: &[u8]) -> Result { use core::convert::TryInto; apdu.try_into() @@ -33,11 +39,11 @@ impl Command { self.instruction } - pub fn data(&self) -> &Data { + pub fn data(&self) -> &Bytes { &self.data } - pub fn data_mut(&mut self) -> &mut Data { + pub fn data_mut(&mut self) -> &mut Bytes{ &mut self.data } @@ -48,7 +54,7 @@ impl Command { /// This can be use for APDU chaining to convert /// multiple APDU's into one. /// * Global Platform GPC_SPE_055 3.10 - pub fn extend_from_command(&mut self, command: &Command) -> core::result::Result<(),()> { + pub fn extend_from_command(&mut self, command: &Command>) -> core::result::Result<(),()> { // Always take the header from the last command; self.class = command.class(); @@ -77,7 +83,9 @@ impl From for FromSliceError { } } -impl core::convert::TryFrom<&[u8]> for Command { +impl core::convert::TryFrom<&[u8]> for Command +where SIZE: ArrayLength +{ type Error = FromSliceError; fn try_from(apdu: &[u8]) -> core::result::Result { if apdu.len() < 4 { @@ -99,7 +107,7 @@ impl core::convert::TryFrom<&[u8]> for Command { // maximum expected response length le: parsed.le, // payload - data: Data::try_from_slice(data_slice).unwrap(), + data: Bytes::try_from_slice(data_slice).unwrap(), extended: parsed.extended, }) } diff --git a/src/lib.rs b/src/lib.rs index b53d143..f90febf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,11 +3,6 @@ pub use heapless_bytes::Bytes as Bytes; -#[allow(non_camel_case_types)] -pub type U3072 = >::Output; -#[allow(non_camel_case_types)] -pub type MAX_COMMAND_DATA = U3072; - // 7816-4, 8.2.1.2 pub type Aid = Bytes;