From 45169cd0c2cb9ee6306bfb55dc18ddf6076fbdb4 Mon Sep 17 00:00:00 2001 From: Nicolas Stalder Date: Fri, 22 May 2020 01:51:09 +0200 Subject: [PATCH] Get rid of heapless-bytes: use hopefully soon to be upstreamed heapless additions --- src/class.rs | 2 +- src/constants.rs | 2 +- src/der.rs | 16 ++++++++-------- src/pipe.rs | 2 +- src/piv.rs | 2 +- src/types.rs | 4 ++-- src/types/apdu.rs | 2 +- src/types/packet.rs | 4 ++-- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/class.rs b/src/class.rs index 91cb3c4..75d370d 100644 --- a/src/class.rs +++ b/src/class.rs @@ -91,7 +91,7 @@ where fn endpoint_out(&mut self, addr: EndpointAddress) { if addr != self.read.address() { return; } - let maybe_packet = RawPacket::try_from( + let maybe_packet = RawPacket::try_read( |packet| self.read.read(packet)); // should we return an error message diff --git a/src/constants.rs b/src/constants.rs index 4d4982b..e862a5a 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -1,5 +1,5 @@ #![allow(non_camel_case_types)] -use heapless_bytes::{ +use heapless::{ consts, Unsigned as _ }; diff --git a/src/der.rs b/src/der.rs index 373ef22..59eb6a8 100644 --- a/src/der.rs +++ b/src/der.rs @@ -1,4 +1,4 @@ -pub use heapless_bytes::{consts, ArrayLength, Bytes}; +pub use heapless::{consts, ArrayLength, ByteBuf}; const CONSTRUCTED: u8 = 1 << 5; // const CONTEXT_SPECIFIC: u8 = 2 << 6; @@ -40,7 +40,7 @@ type Result = core::result::Result<(), ()>; /// DER writer #[derive(Debug)] -pub struct Der(Bytes) +pub struct Der(ByteBuf) where N: ArrayLength; @@ -51,14 +51,14 @@ impl> Default for Der { } impl> core::ops::Deref for Der { - type Target = Bytes; + type Target = ByteBuf; fn deref(&self) -> &Self::Target { &self.0 } } impl> core::ops::DerefMut for Der { - fn deref_mut(&mut self) -> &mut Bytes { + fn deref_mut(&mut self) -> &mut ByteBuf { &mut self.0 } } @@ -66,7 +66,7 @@ impl> core::ops::DerefMut for Der { impl> Der { /// Create a new `Der` structure that writes values to the given buffer pub fn new() -> Self { - Der(Bytes::new()) + Der(ByteBuf::new()) } // // equivalent of method in std::io::Write @@ -75,7 +75,7 @@ impl> Der { // } /// Return underlying buffer - pub fn into_inner(self) -> Bytes { + pub fn into_inner(self) -> ByteBuf { self.0 } @@ -234,8 +234,8 @@ mod test { ]; assert_eq!(der.len(), expected.len()); assert_eq!( - Bytes::::try_from_slice(&der).unwrap(), - Bytes::::try_from_slice(&expected).unwrap(), + ByteBuf::::from_slice(&der).unwrap(), + ByteBuf::::from_slice(&expected).unwrap(), ); // assert_eq!(&got[..32], &expected[..32]); // assert_eq!(&got[32..64], &expected[32..64]); diff --git a/src/pipe.rs b/src/pipe.rs index 447f887..47cd8f1 100644 --- a/src/pipe.rs +++ b/src/pipe.rs @@ -168,7 +168,7 @@ where panic!("short packet!"); } - Err(PacketError::UnknownCommand(c)) => { + Err(PacketError::UnknownCommand(_c)) => { // hprintln!("{:X?}", &p).ok(); // panic!("unknown command byte 0x{:x}", c); diff --git a/src/piv.rs b/src/piv.rs index e5a763f..e4d9751 100644 --- a/src/piv.rs +++ b/src/piv.rs @@ -1,7 +1,7 @@ use core::convert::TryFrom; use cortex_m_semihosting::hprintln; -use heapless_bytes::consts; +use heapless::consts; use crate::{ der::Der, diff --git a/src/types.rs b/src/types.rs index e81543d..b27d837 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,5 +1,5 @@ // use cortex_m_semihosting::hprintln; -use heapless_bytes::Bytes; +use heapless::ByteBuf; use crate::constants::*; @@ -8,7 +8,7 @@ use crate::constants::*; pub mod packet; pub mod tlv; -pub type MessageBuffer = Bytes; +pub type MessageBuffer = ByteBuf; interchange::interchange! { ApduInterchange: (iso7816::Command, iso7816::Response) diff --git a/src/types/apdu.rs b/src/types/apdu.rs index f99d3cc..a939e8d 100644 --- a/src/types/apdu.rs +++ b/src/types/apdu.rs @@ -50,7 +50,7 @@ interchange::interchange! { // p2: apdu.p2(), // lc: apdu.lc(), // le: apdu.le(), -// data: MessageBuffer::try_from_slice(apdu.data()).unwrap(), +// data: MessageBuffer::from_slice(apdu.data()).unwrap(), // }) // } // } diff --git a/src/types/packet.rs b/src/types/packet.rs index aab6af5..5ce2b79 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::ByteBuf; +pub type ExtPacket = heapless::ByteBuf; pub trait RawPacketExt { fn packet_len(&self) -> usize;