From 4fb10fc65ccd3f2eb82cdcff85d9b3ab92845026 Mon Sep 17 00:00:00 2001 From: Nicolas Stalder Date: Fri, 11 Jun 2021 00:12:34 +0200 Subject: [PATCH] Bump heapless and all that bumped it --- Cargo.toml | 6 +++--- src/class.rs | 31 +++++++++++++++++++------------ src/constants.rs | 15 +++------------ src/pipe.rs | 28 ++++++++++++---------------- src/types/packet.rs | 8 ++++---- 5 files changed, 41 insertions(+), 47 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e265d9e..fb23e43 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,9 +8,9 @@ edition = "2018" [dependencies] delog = "0.1.0" -embedded-time = "0.10.1" -heapless = "0.6" -heapless-bytes = "0.2.0" +embedded-time = "0.12" +heapless = "0.7" +# heapless-bytes = "0.3" interchange = "0.2.0" iso7816 = { git = "https://github.com/ycrypto/iso7816", branch = "main" } usb-device = { version = "0.2.3", features = ["control-buffer-256"] } diff --git a/src/class.rs b/src/class.rs index 43537eb..4f3f482 100644 --- a/src/class.rs +++ b/src/class.rs @@ -1,7 +1,7 @@ use core::convert::TryFrom; use embedded_time::duration::Extensions; -use heapless_bytes::Bytes; +use heapless::Vec; use interchange::{Interchange, Requester}; use crate::{ @@ -17,11 +17,10 @@ use crate::{ use usb_device::class_prelude::*; type Result = core::result::Result; -pub struct Ccid +pub struct Ccid where Bus: 'static + UsbBus, - I: 'static + Interchange, RESPONSE = Bytes>, - N: heapless::ArrayLength, + I: 'static + Interchange, RESPONSE = Vec>, { interface_number: InterfaceNumber, string_index: StringIndex, @@ -30,11 +29,10 @@ where pipe: Pipe, } -impl Ccid +impl Ccid where Bus: 'static + UsbBus, - I: 'static + Interchange, RESPONSE = Bytes>, - N: heapless::ArrayLength, + I: 'static + Interchange, RESPONSE = Vec>, { /// Class constructor. /// @@ -85,11 +83,10 @@ where } } -impl UsbClass for Ccid +impl UsbClass for Ccid where Bus: 'static + UsbBus, - I: 'static + Interchange, RESPONSE = Bytes>, - N: heapless::ArrayLength, + I: 'static + Interchange, RESPONSE = Vec>, { fn get_configuration_descriptors(&self, writer: &mut DescriptorWriter) -> Result<()> @@ -132,8 +129,18 @@ where fn endpoint_out(&mut self, addr: EndpointAddress) { if addr != self.read.address() { return; } - let maybe_packet = RawPacket::try_from( - |packet| self.read.read(packet)); + // let maybe_packet = RawPacket::try_from( + // |packet| self.read.read(packet)); + + let maybe_packet = { + let mut packet = RawPacket::new(); + packet.resize_default(packet.capacity()).unwrap(); + let result = self.read.read(&mut packet); + result.map(|count| { + packet.resize_default(count).unwrap(); + packet + }) + }; // should we return an error message // if the raw packet is invalid? diff --git a/src/constants.rs b/src/constants.rs index 55a61d3..aae9206 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -1,16 +1,8 @@ -#![allow(non_camel_case_types)] -use heapless_bytes::{ - consts, - Unsigned as _ -}; - // can be 8, 16, 32, 64 or 512 #[cfg(feature = "highspeed-usb")] -pub type PACKET_SIZE_TYPE = consts::U512; +pub const PACKET_SIZE: usize = 512; #[cfg(not(feature = "highspeed-usb"))] -pub type PACKET_SIZE_TYPE = consts::U64; - -pub const PACKET_SIZE: usize = PACKET_SIZE_TYPE::USIZE; +pub const PACKET_SIZE: usize = 64; pub const CLASS_CCID: u8 = 0x0B; pub const SUBCLASS_NONE: u8 = 0x0; @@ -46,8 +38,7 @@ pub const MAX_IFSD: [u8; 4] = [0xfe, 0x00, 0x00, 0x00]; // "The value shall be between 261 + 10 and 65544 + 10 // dwMaxCCIDMsgLen 3072 -pub type MAX_MSG_LENGTH_TYPE = >::Output; -pub const MAX_MSG_LENGTH: usize = MAX_MSG_LENGTH_TYPE::USIZE; +pub const MAX_MSG_LENGTH: usize = 3072; pub const MAX_MSG_LENGTH_LE: [u8; 4] = [0x00, 0x0C, 0x00, 0x00]; pub const NUM_SLOTS: u8 = 1; diff --git a/src/pipe.rs b/src/pipe.rs index 43d3566..52a853d 100644 --- a/src/pipe.rs +++ b/src/pipe.rs @@ -1,6 +1,5 @@ use core::convert::TryFrom; - -use heapless_bytes::Bytes; +use heapless::Vec; use interchange::{Interchange, Requester}; use crate::{ @@ -41,11 +40,10 @@ enum Error { CommandNotSupported = 0x00, } -pub struct Pipe +pub struct Pipe where Bus: 'static + UsbBus, - I: 'static + Interchange, RESPONSE = Bytes>, - N: heapless::ArrayLength, + I: 'static + Interchange, RESPONSE = Vec>, { pub(crate) write: EndpointIn<'static, Bus>, // pub(crate) rpc: TransportEndpoint<'rpc>, @@ -62,14 +60,13 @@ where long_packet_missing: usize, in_chain: usize, pub(crate) started_processing: bool, - atr: Bytes, + atr: Vec, } -impl Pipe +impl Pipe where Bus: 'static + UsbBus, - I: 'static + Interchange, RESPONSE = Bytes>, - N: heapless::ArrayLength, + I: 'static + Interchange, RESPONSE = Vec>, { pub(crate) fn new( write: EndpointIn<'static, Bus>, @@ -100,10 +97,10 @@ where } } - fn construct_atr(card_issuers_data: Option<&[u8]>, signal_t_equals_0: bool) -> Bytes { + fn construct_atr(card_issuers_data: Option<&[u8]>, signal_t_equals_0: bool) -> Vec { assert!(card_issuers_data.map_or(true, |data| data.len() <= 13)); let k = card_issuers_data.map_or(0u8, |data| 2 + data.len() as u8); - let mut atr = Bytes::new(); + let mut atr = Vec::new(); // TS: direct convention atr.push(0x3B).ok(); // T0: encode length of historical bytes @@ -140,11 +137,10 @@ where } -impl Pipe +impl Pipe where Bus: 'static + UsbBus, - I: 'static + Interchange, RESPONSE = Bytes>, - N: heapless::ArrayLength, + I: 'static + Interchange, RESPONSE = Vec>, { pub fn handle_packet(&mut self, packet: RawPacket) { use crate::types::packet::RawPacketExt; @@ -228,7 +224,7 @@ where #[inline(never)] fn reset_interchange(&mut self) { - let message = Bytes::new(); + let message = Vec::new(); self.interchange.take_response(); // this may no longer be needed // before the interchange change (adding the request_mut method), @@ -378,7 +374,7 @@ where if self.outbox.is_some() { panic!(); } // if let Some(message) = self.interchange.response() { - let message: &mut Bytes = unsafe { self.interchange.interchange.rp_mut() }; + let message: &mut Vec = unsafe { self.interchange.interchange.rp_mut() }; let chunk_size = core::cmp::min(PACKET_SIZE - 10, message.len() - self.sent); let chunk = &message[self.sent..][..chunk_size]; diff --git a/src/types/packet.rs b/src/types/packet.rs index c2072c8..ea840ca 100644 --- a/src/types/packet.rs +++ b/src/types/packet.rs @@ -3,8 +3,8 @@ use core::convert::TryInto; use crate::constants::*; -pub type RawPacket = heapless_bytes::Bytes; -pub type ExtPacket = heapless_bytes::Bytes; +pub type RawPacket = heapless::Vec; +pub type ExtPacket = heapless::Vec; pub trait RawPacketExt { fn packet_len(&self) -> usize; @@ -94,7 +94,7 @@ impl core::fmt::Debug for DataBlock<'_> { ; let l = core::cmp::min(self.data.len(), 16); - let escaped_bytes: heapless::Vec = + let escaped_bytes: heapless::Vec = self.data.iter().take(l) .flat_map(|byte| core::ascii::escape_default(*byte)) .collect(); @@ -342,7 +342,7 @@ impl core::fmt::Debug for Command { match self { Command::XfrBlock(block) => { let l = core::cmp::min(self.len(), 8); - let escaped_bytes: heapless::Vec = + let escaped_bytes: heapless::Vec = block.data().iter().take(l) .flat_map(|byte| core::ascii::escape_default(*byte)) .collect();