From ff73936a4d142ed989193ee375d3463b6d19cbce Mon Sep 17 00:00:00 2001 From: Guillaume Endignoux Date: Tue, 22 Sep 2020 13:14:33 +0200 Subject: [PATCH] Fix imports in ctap, embedded_flash and lang-items. --- src/ctap/ctap1.rs | 2 +- src/ctap/hid/mod.rs | 6 +++--- src/ctap/hid/receive.rs | 4 ++-- src/ctap/storage.rs | 8 ++++---- src/ctap/timed_permission.rs | 2 +- src/embedded_flash/mod.rs | 4 ++++ src/embedded_flash/store/mod.rs | 10 +++++++--- src/lib.rs | 5 +++++ src/main.rs | 1 + third_party/lang-items/src/lib.rs | 7 +++++++ 10 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/ctap/ctap1.rs b/src/ctap/ctap1.rs index 56bec45..d412eed 100644 --- a/src/ctap/ctap1.rs +++ b/src/ctap/ctap1.rs @@ -16,11 +16,11 @@ use super::hid::ChannelID; use super::key_material::{ATTESTATION_CERTIFICATE, ATTESTATION_PRIVATE_KEY}; use super::status_code::Ctap2StatusCode; use super::CtapState; -use crate::timer::ClockValue; use alloc::vec::Vec; use core::convert::Into; use core::convert::TryFrom; use crypto::rng256::Rng256; +use libtock_drivers::timer::ClockValue; // The specification referenced in this file is at: // https://fidoalliance.org/specs/fido-u2f-v1.2-ps-20170411/fido-u2f-raw-message-formats-v1.2-ps-20170411.pdf diff --git a/src/ctap/hid/mod.rs b/src/ctap/hid/mod.rs index 877a9fa..115bc3a 100644 --- a/src/ctap/hid/mod.rs +++ b/src/ctap/hid/mod.rs @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -mod receive; -mod send; +pub mod receive; +pub mod send; use self::receive::MessageAssembler; use self::send::HidPacketIterator; @@ -22,13 +22,13 @@ use super::ctap1; use super::status_code::Ctap2StatusCode; use super::timed_permission::TimedPermission; use super::CtapState; -use crate::timer::{ClockValue, Duration, Timestamp}; use alloc::vec::Vec; #[cfg(feature = "debug_ctap")] use core::fmt::Write; use crypto::rng256::Rng256; #[cfg(feature = "debug_ctap")] use libtock_drivers::console::Console; +use libtock_drivers::timer::{ClockValue, Duration, Timestamp}; // CTAP specification (version 20190130) section 8.1 // TODO: Channel allocation, section 8.1.3? diff --git a/src/ctap/hid/receive.rs b/src/ctap/hid/receive.rs index ae2e707..fef51a4 100644 --- a/src/ctap/hid/receive.rs +++ b/src/ctap/hid/receive.rs @@ -13,9 +13,9 @@ // limitations under the License. use super::{ChannelID, CtapHid, HidPacket, Message, ProcessedPacket}; -use crate::timer::Timestamp; use alloc::vec::Vec; use core::mem::swap; +use libtock_drivers::timer::Timestamp; // A structure to assemble CTAPHID commands from a series of incoming USB HID packets. pub struct MessageAssembler { @@ -195,7 +195,7 @@ impl MessageAssembler { #[cfg(test)] mod test { use super::*; - use crate::timer::Duration; + use libtock_drivers::timer::Duration; // Except for tests that exercise timeouts, all packets are synchronized at the same dummy // timestamp. diff --git a/src/ctap/storage.rs b/src/ctap/storage.rs index 24456c8..7480147 100644 --- a/src/ctap/storage.rs +++ b/src/ctap/storage.rs @@ -12,17 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::crypto::rng256::Rng256; #[cfg(feature = "with_ctap2_1")] use crate::ctap::data_formats::{extract_array, extract_text_string}; use crate::ctap::data_formats::{CredentialProtectionPolicy, PublicKeyCredentialSource}; use crate::ctap::pin_protocol_v1::PIN_AUTH_LENGTH; use crate::ctap::status_code::Ctap2StatusCode; use crate::ctap::{key_material, USE_BATCH_ATTESTATION}; +use crate::embedded_flash::{self, StoreConfig, StoreEntry, StoreError}; use alloc::string::String; use alloc::vec::Vec; use core::convert::TryInto; -use ctap2::embedded_flash::{self, StoreConfig, StoreEntry, StoreError}; +use crypto::rng256::Rng256; #[cfg(any(test, feature = "ram_storage"))] type Storage = embedded_flash::BufferStorage; @@ -660,9 +660,9 @@ fn _serialize_min_pin_length_rp_ids(rp_ids: Vec) -> Result, Ctap #[cfg(test)] mod test { use super::*; - use crate::crypto; - use crate::crypto::rng256::{Rng256, ThreadRng256}; use crate::ctap::data_formats::{PublicKeyCredentialSource, PublicKeyCredentialType}; + use crypto; + use crypto::rng256::{Rng256, ThreadRng256}; fn create_credential_source( rng: &mut ThreadRng256, diff --git a/src/ctap/timed_permission.rs b/src/ctap/timed_permission.rs index d56ba09..fcc0ada 100644 --- a/src/ctap/timed_permission.rs +++ b/src/ctap/timed_permission.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::timer::{ClockValue, Duration}; +use libtock_drivers::timer::{ClockValue, Duration}; #[derive(Clone, Copy, Debug)] pub enum TimedPermission { diff --git a/src/embedded_flash/mod.rs b/src/embedded_flash/mod.rs index 8551a52..05407c0 100644 --- a/src/embedded_flash/mod.rs +++ b/src/embedded_flash/mod.rs @@ -12,12 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. +#[cfg(any(test, feature = "ram_storage"))] mod buffer; mod storage; mod store; +#[cfg(not(any(test, feature = "ram_storage")))] mod syscall; +#[cfg(any(test, feature = "ram_storage"))] pub use self::buffer::{BufferOptions, BufferStorage}; pub use self::storage::{Index, Storage, StorageError, StorageResult}; pub use self::store::{Store, StoreConfig, StoreEntry, StoreError, StoreIndex}; +#[cfg(not(any(test, feature = "ram_storage")))] pub use self::syscall::SyscallStorage; diff --git a/src/embedded_flash/store/mod.rs b/src/embedded_flash/store/mod.rs index c5cf838..49ab487 100644 --- a/src/embedded_flash/store/mod.rs +++ b/src/embedded_flash/store/mod.rs @@ -163,9 +163,11 @@ mod bitfield; mod format; use self::format::{Format, IsReplace}; -#[cfg(feature = "std")] -use super::BufferStorage; use super::{Index, Storage}; +#[cfg(any(test, feature = "ram_storage"))] +use crate::embedded_flash::BufferStorage; +#[cfg(any(test, feature = "ram_storage"))] +use alloc::boxed::Box; use alloc::collections::BTreeMap; use alloc::vec::Vec; @@ -402,6 +404,7 @@ impl Store { /// Computes the length in bytes that would be used in the storage if an insert operation is /// executed provided the data of the inserted entry has `length` bytes and whether this data is /// sensitive. + #[allow(dead_code)] pub fn insert_len(&self, sensitive: bool, length: usize) -> usize { self.format.entry_size(IsReplace::Insert, sensitive, length) } @@ -410,6 +413,7 @@ impl Store { /// /// The value at index `page` of the result is the number of times page `page` was erased. This /// number is an underestimate in case power was lost when this page was erased. + #[allow(dead_code)] pub fn compaction_info(&self) -> Vec { let mut info = Vec::with_capacity(self.format.num_pages); for page in 0..self.format.num_pages { @@ -766,7 +770,7 @@ impl Store { } // Those functions are not meant for production. -#[cfg(feature = "std")] +#[cfg(any(test, feature = "ram_storage"))] impl Store { /// Takes a snapshot of the storage after a given amount of word operations. pub fn arm_snapshot(&mut self, delay: usize) { diff --git a/src/lib.rs b/src/lib.rs index ae3ca56..0df6552 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,8 +16,13 @@ #[macro_use] extern crate alloc; +#[macro_use] +extern crate arrayref; +#[macro_use] +extern crate cbor; extern crate lang_items; extern crate libtock_core; extern crate libtock_drivers; +pub mod ctap; pub mod embedded_flash; diff --git a/src/main.rs b/src/main.rs index 2cb7a8c..8a3470f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,6 +28,7 @@ extern crate cbor; extern crate crypto; mod ctap; +pub mod embedded_flash; use core::cell::Cell; #[cfg(feature = "debug_ctap")] diff --git a/third_party/lang-items/src/lib.rs b/third_party/lang-items/src/lib.rs index c4fdcf8..3d517ac 100644 --- a/third_party/lang-items/src/lib.rs +++ b/third_party/lang-items/src/lib.rs @@ -7,3 +7,10 @@ mod allocator; mod panic_handler; #[cfg(not(feature = "std"))] mod util; + +#[cfg(feature = "std")] +#[no_mangle] +unsafe fn libtock_alloc_init(_app_heap_start: usize, _app_heap_size: usize) { + // Stub so that the symbol is present. + unimplemented!() +}