Skip to content

Commit

Permalink
Bump heapless and all that bumped it
Browse files Browse the repository at this point in the history
  • Loading branch information
nickray committed Jun 10, 2021
1 parent 742620c commit 1682d78
Show file tree
Hide file tree
Showing 24 changed files with 90 additions and 114 deletions.
14 changes: 5 additions & 9 deletions components/admin-app/src/admin.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use core::{convert::TryInto, marker::PhantomData};
use ctaphid_dispatch::app::{self as hid, Command as HidCommand, Message};
use ctaphid_dispatch::command::VendorCommand;
use apdu_dispatch::{Command, response, app as apdu};
use apdu_dispatch::{command::Size as CommandSize, response::Size as ResponseSize};
use apdu_dispatch::{Command, command, response, app as apdu};
use apdu_dispatch::iso7816::Status;
use trussed::{
syscall,
Expand Down Expand Up @@ -120,20 +119,17 @@ where T: TrussedClient,
}
}

impl<T, R> apdu::Aid for App<T, R>
impl<T, R> iso7816::App for App<T, R>
where T: TrussedClient,
R: Reboot
{
// Solo management app
fn aid(&self) -> &'static [u8] {
&[ 0xA0, 0x00, 0x00, 0x08, 0x47, 0x00, 0x00, 0x00, 0x01]
}
fn right_truncated_length(&self) -> usize {
9
fn aid(&self) -> iso7816::Aid {
iso7816::Aid::new(&[ 0xA0, 0x00, 0x00, 0x08, 0x47, 0x00, 0x00, 0x00, 0x01])
}
}

impl<T, R> apdu::App<CommandSize, ResponseSize> for App<T, R>
impl<T, R> apdu::App<{command::SIZE}, {response::SIZE}> for App<T, R>
where T: TrussedClient,
R: Reboot
{
Expand Down
4 changes: 2 additions & 2 deletions components/ctaphid-dispatch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ edition = "2018"

[dependencies]
delog = "0.1.0"
heapless = "0.6"
heapless-bytes = "0.2.0"
heapless = "0.7"
heapless-bytes = "0.3"
interchange = "0.2.0"

[features]
Expand Down
10 changes: 5 additions & 5 deletions components/ctaphid-dispatch/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ pub enum Error {
InvalidLength,
}

// 7609 bytes is max message size for ctaphid
type U6144 = <heapless::consts::U4096 as core::ops::Add<heapless::consts::U2048>>::Output;
type U7168 = <U6144 as core::ops::Add<heapless::consts::U1024>>::Output;
pub type U7609 = <U7168 as core::ops::Add<heapless::consts::U441>>::Output;
// // 7609 bytes is max message size for ctaphid
// type U6144 = <heapless::consts::U4096 as core::ops::Add<heapless::consts::U2048>>::Output;
// type U7168 = <U6144 as core::ops::Add<heapless::consts::U1024>>::Output;
// pub type U7609 = <U7168 as core::ops::Add<heapless::consts::U441>>::Output;
// pub type U7609 = heapless::consts::U4096;

pub type Message = heapless_bytes::Bytes<U7609>;
pub type Message = heapless::Vec<u8, 7609>;
pub type AppResult = core::result::Result<(), Error>;
pub type InterchangeResponse = core::result::Result<Message, Error>;

Expand Down
2 changes: 1 addition & 1 deletion components/dispatch-fido/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2018"
[dependencies]
delog = "0.1.0"
heapless = "0.6"
heapless-bytes = "0.2.0"
heapless-bytes = "0.3"
interchange = "0.2.0"
serde = { version = "1", default-features = false }

Expand Down
16 changes: 8 additions & 8 deletions components/dispatch-fido/src/fido.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ where UP: UserPresence,
}

fn response_from_object<T: serde::Serialize>(&mut self, object: Option<T>, reply: &mut response::Data) -> app::Result {
reply.resize_to_capacity();
reply.resize_default(reply.capacity()).ok();
if let Some(object) = object {
match cbor_serialize(&object, &mut reply[1..]) {
Ok(ser) => {
Expand Down Expand Up @@ -144,18 +144,18 @@ where UP: UserPresence,

}

impl<UP, T> app::Aid for Fido<UP, T>
impl<UP, T> iso7816::App for Fido<UP, T>
where UP: UserPresence,
{
fn aid(&self) -> &'static [u8] {
&[ 0xA0, 0x00, 0x00, 0x06, 0x47, 0x2F, 0x00, 0x01 ]
}
fn right_truncated_length(&self) -> usize {
8
fn aid(&self) -> iso7816::Aid {
iso7816::Aid::new(&[ 0xA0, 0x00, 0x00, 0x06, 0x47, 0x2F, 0x00, 0x01])
}
}

impl<UP, T> app::App<apdu_dispatch::command::Size, apdu_dispatch::response::Size> for Fido<UP, T>
impl<UP, T> app::App<
{apdu_dispatch::command::SIZE},
{apdu_dispatch::response::SIZE},
> for Fido<UP, T>
where UP: UserPresence,
T: client::Client
+ client::P256
Expand Down
2 changes: 1 addition & 1 deletion components/fm11nc08/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2018"

[dependencies]
delog = "0.1.0"
embedded-time = "0.10.1"
embedded-time = "0.12"
embedded-hal = { version = "0.2.5", features = ["unproven"] }
nb = "1"
nfc-device = {path = "../nfc-device"}
Expand Down
3 changes: 1 addition & 2 deletions components/ndef-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
heapless = "0.6"
heapless-bytes = "0.2.0"
heapless = "0.7"

apdu-dispatch = { git = "https://github.com/solokeys/apdu-dispatch", branch = "main" }
iso7816 = { git = "https://github.com/ycrypto/iso7816", branch = "main" }
12 changes: 4 additions & 8 deletions components/ndef-app/src/ndef.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use iso7816::{Instruction, Status};
use apdu_dispatch::{Command, response, app, command::Size as CommandSize, response::Size as ResponseSize};
use apdu_dispatch::{Command, response, app, command::SIZE as CommandSize, response::SIZE as ResponseSize};

pub struct App<'a>{
reader: &'a [u8]
Expand Down Expand Up @@ -31,13 +31,9 @@ impl<'a> App<'a> {
}
}

impl<'a> app::Aid for App<'a> {
fn aid(&self) -> &'static [u8] {
&[0xD2u8, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01,]
}

fn right_truncated_length(&self) -> usize {
8
impl<'a> iso7816::App for App<'a> {
fn aid(&self) -> iso7816::Aid {
iso7816::Aid::new(&[0xD2u8, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01])
}
}

Expand Down
5 changes: 2 additions & 3 deletions components/nfc-device/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ 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"
nb = "1"

apdu-dispatch = { git = "https://github.com/solokeys/apdu-dispatch", branch = "main" }
Expand Down
10 changes: 5 additions & 5 deletions components/nfc-device/src/iso14443.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::mem::MaybeUninit;

use apdu_dispatch::interchanges;
use embedded_time::duration::Milliseconds;
use heapless_bytes::Bytes;
use heapless::Vec;
use interchange::Requester;

use crate::traits::nfc;
Expand All @@ -21,7 +21,7 @@ pub enum Iso14443Status {
}

// Max iso14443 frame is 256 bytes
type Iso14443Frame = heapless_bytes::Bytes<heapless::consts::U256>;
type Iso14443Frame = Vec<u8, 256>;

#[derive(Clone, PartialEq)]
enum Iso14443State {
Expand Down Expand Up @@ -116,7 +116,7 @@ where
wtx_requested: false,
block_num: true,

buffer: Bytes::new(),
buffer: Vec::new(),

interchange: interchange,
}
Expand Down Expand Up @@ -192,7 +192,7 @@ where
Iso14443State::Transmitting(last_frame_range, _remaining_data_range) => {
info!("Retransmission requested..");
self.send_frame(
&Bytes::try_from_slice(
&Vec::from_slice(
&self.buffer[last_frame_range]
).unwrap()
).ok();
Expand Down Expand Up @@ -352,7 +352,7 @@ where
debug!("{}", hex_str!(&self.buffer, sep:""));
// logging::dump_hex(packet, l as usize);

let command = interchanges::Data::try_from_slice(&self.buffer);
let command = interchanges::Data::from_slice(&self.buffer);
self.buffer.clear();
if command.is_ok() {
if self.interchange.request(
Expand Down
4 changes: 2 additions & 2 deletions components/provisioner-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ edition = "2018"
apdu-dispatch = { git = "https://github.com/solokeys/apdu-dispatch", branch = "main" }
delog = "0.1.1"
heapless = "0.6"
heapless-bytes = "0.2.0"
lpc55-hal = { version = "0.2.1", features = ["littlefs", "rtic-peripherals"] }
heapless-bytes = "0.3"
lpc55-hal = { version = "0.3", features = ["littlefs", "rtic-peripherals"] }
littlefs2 = "0.2.2"
trussed = { git = "https://github.com/trussed-dev/trussed", branch = "main" }

Expand Down
6 changes: 3 additions & 3 deletions components/usbd-ccid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
31 changes: 19 additions & 12 deletions components/usbd-ccid/src/class.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -17,11 +17,10 @@ use crate::{
use usb_device::class_prelude::*;
type Result<T> = core::result::Result<T, UsbError>;

pub struct Ccid<Bus, I, N>
pub struct Ccid<Bus, I, const N: usize>
where
Bus: 'static + UsbBus,
I: 'static + Interchange<REQUEST = Bytes<N>, RESPONSE = Bytes<N>>,
N: heapless::ArrayLength<u8>,
I: 'static + Interchange<REQUEST = Vec<u8, N>, RESPONSE = Vec<u8, N>>,
{
interface_number: InterfaceNumber,
string_index: StringIndex,
Expand All @@ -30,11 +29,10 @@ where
pipe: Pipe<Bus, I, N>,
}

impl<Bus, I, N> Ccid<Bus, I, N>
impl<Bus, I, const N: usize> Ccid<Bus, I, N>
where
Bus: 'static + UsbBus,
I: 'static + Interchange<REQUEST = Bytes<N>, RESPONSE = Bytes<N>>,
N: heapless::ArrayLength<u8>,
I: 'static + Interchange<REQUEST = Vec<u8, N>, RESPONSE = Vec<u8, N>>,
{
/// Class constructor.
///
Expand Down Expand Up @@ -85,11 +83,10 @@ where
}
}

impl<Bus, I, N> UsbClass<Bus> for Ccid<Bus, I, N>
impl<Bus, I, const N: usize> UsbClass<Bus> for Ccid<Bus, I, N>
where
Bus: 'static + UsbBus,
I: 'static + Interchange<REQUEST = Bytes<N>, RESPONSE = Bytes<N>>,
N: heapless::ArrayLength<u8>,
I: 'static + Interchange<REQUEST = Vec<u8, N>, RESPONSE = Vec<u8, N>>,
{
fn get_configuration_descriptors(&self, writer: &mut DescriptorWriter)
-> Result<()>
Expand Down Expand Up @@ -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?
Expand Down
15 changes: 3 additions & 12 deletions components/usbd-ccid/src/constants.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 = <consts::U2048 as core::ops::Add<consts::U1024>>::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;
Expand Down
Loading

0 comments on commit 1682d78

Please sign in to comment.