From 7e7d5e38a1981438e8755a4716c686665be00671 Mon Sep 17 00:00:00 2001 From: kaczmarczyck <43844792+kaczmarczyck@users.noreply.github.com> Date: Mon, 14 Mar 2022 20:44:48 +0100 Subject: [PATCH] enforces Module imports granularity (#445) --- bootloader/src/registers.rs | 6 ++---- build.rs | 10 +++------- examples/crypto_bench.rs | 3 +-- examples/nfct_test.rs | 15 +++++---------- libraries/cbor/src/macros.rs | 4 +++- rustfmt.toml | 3 ++- src/ctap/command.rs | 3 +-- src/ctap/ctap1.rs | 3 +-- src/ctap/mod.rs | 3 +-- src/ctap/storage.rs | 3 +-- third_party/lang-items/src/allocator.rs | 3 +-- third_party/libtock-drivers/src/usb_ctap_hid.rs | 3 +-- 12 files changed, 22 insertions(+), 37 deletions(-) diff --git a/bootloader/src/registers.rs b/bootloader/src/registers.rs index 17725dc..db36357 100644 --- a/bootloader/src/registers.rs +++ b/bootloader/src/registers.rs @@ -15,10 +15,8 @@ use super::bitfields::{ Busy, CryptoMode, HashControl, Interrupts, LliWord1, PaddingConfig, RgfEndianness, Task, }; -use tock_registers::{ - register_structs, - registers::{ReadOnly, ReadWrite, WriteOnly}, -}; +use tock_registers::register_structs; +use tock_registers::registers::{ReadOnly, ReadWrite, WriteOnly}; register_structs! { pub CryptoCellControlRegisters { diff --git a/build.rs b/build.rs index 2640610..6480af2 100644 --- a/build.rs +++ b/build.rs @@ -14,16 +14,12 @@ extern crate alloc; -use openssl::bn; -use openssl::ec; -use openssl::nid; +use openssl::{bn, ec, nid}; use sk_cbor::cbor_map; -use std::env; -use std::fs; use std::fs::File; -use std::io::Read; -use std::io::Write; +use std::io::{Read, Write}; use std::path::Path; +use std::{env, fs}; use uuid::Uuid; fn main() { diff --git a/examples/crypto_bench.rs b/examples/crypto_bench.rs index cebe9a1..1e99517 100644 --- a/examples/crypto_bench.rs +++ b/examples/crypto_bench.rs @@ -24,8 +24,7 @@ use crypto::{aes256, cbc, ecdsa, rng256, sha256, Hash256}; use libtock_drivers::console::Console; use libtock_drivers::result::FlexUnwrap; use libtock_drivers::timer; -use libtock_drivers::timer::Timer; -use libtock_drivers::timer::Timestamp; +use libtock_drivers::timer::{Timer, Timestamp}; libtock_core::stack_size! {0x800} diff --git a/examples/nfct_test.rs b/examples/nfct_test.rs index 6efbce3..3483a92 100644 --- a/examples/nfct_test.rs +++ b/examples/nfct_test.rs @@ -11,8 +11,7 @@ libtock_core::stack_size! {0x4000} #[cfg(not(feature = "with_nfc"))] mod example { - use super::Console; - use super::Write; + use super::{Console, Write}; pub fn nfc(console: &mut Console) { writeln!(console, "NFC feature flag is missing!").unwrap(); @@ -21,16 +20,12 @@ mod example { #[cfg(feature = "with_nfc")] mod example { - use super::Console; - use super::Write; + use super::{Console, Write}; use libtock_core::result::CommandError; - use libtock_drivers::nfc::NfcTag; - use libtock_drivers::nfc::RecvOp; - use libtock_drivers::result::FlexUnwrap; - use libtock_drivers::result::TockError; + use libtock_drivers::nfc::{NfcTag, RecvOp}; + use libtock_drivers::result::{FlexUnwrap, TockError}; use libtock_drivers::timer; - use libtock_drivers::timer::Timer; - use libtock_drivers::timer::Timestamp; + use libtock_drivers::timer::{Timer, Timestamp}; #[derive(Copy, Clone, Debug, PartialEq)] #[allow(clippy::upper_case_acronyms)] diff --git a/libraries/cbor/src/macros.rs b/libraries/cbor/src/macros.rs index d7e1185..e9e4860 100644 --- a/libraries/cbor/src/macros.rs +++ b/libraries/cbor/src/macros.rs @@ -363,7 +363,9 @@ macro_rules! cbor_bytes_lit { #[cfg(test)] mod test { use super::super::values::{SimpleValue, Value}; - use alloc::{string::String, vec, vec::Vec}; + use alloc::string::String; + use alloc::vec; + use alloc::vec::Vec; #[test] fn test_cbor_simple_values() { diff --git a/rustfmt.toml b/rustfmt.toml index d3da3dd..a7fce48 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,3 +1,4 @@ use_field_init_shorthand = true use_try_shorthand = true -edition = "2018" \ No newline at end of file +edition = "2018" +imports_granularity = "Module" diff --git a/src/ctap/command.rs b/src/ctap/command.rs index 6c06205..5fb5e3e 100644 --- a/src/ctap/command.rs +++ b/src/ctap/command.rs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use super::cbor_read; use super::customization::{MAX_CREDENTIAL_COUNT_IN_LIST, MAX_LARGE_BLOB_ARRAY_SIZE}; use super::data_formats::{ extract_array, extract_bool, extract_byte_string, extract_map, extract_text_string, @@ -23,8 +22,8 @@ use super::data_formats::{ PublicKeyCredentialDescriptor, PublicKeyCredentialParameter, PublicKeyCredentialRpEntity, PublicKeyCredentialUserEntity, SetMinPinLengthParams, }; -use super::key_material; use super::status_code::Ctap2StatusCode; +use super::{cbor_read, key_material}; use alloc::string::String; use alloc::vec::Vec; use arrayref::array_ref; diff --git a/src/ctap/ctap1.rs b/src/ctap/ctap1.rs index c847841..c1e08d6 100644 --- a/src/ctap/ctap1.rs +++ b/src/ctap/ctap1.rs @@ -19,8 +19,7 @@ use crate::ctap::storage; use crate::env::Env; use alloc::vec::Vec; use arrayref::array_ref; -use core::convert::Into; -use core::convert::TryFrom; +use core::convert::{Into, TryFrom}; // For now, they're the same thing with apdu.rs containing the authoritative definition pub type Ctap1StatusCode = ApduStatusCode; diff --git a/src/ctap/mod.rs b/src/ctap/mod.rs index 53fedaf..870a9df 100644 --- a/src/ctap/mod.rs +++ b/src/ctap/mod.rs @@ -75,11 +75,10 @@ use alloc::vec::Vec; use arrayref::array_ref; use byteorder::{BigEndian, ByteOrder}; use core::convert::TryFrom; -use crypto::ecdsa; use crypto::hmac::{hmac_256, verify_hmac_256}; use crypto::rng256::Rng256; use crypto::sha256::Sha256; -use crypto::Hash256; +use crypto::{ecdsa, Hash256}; use embedded_time::duration::Milliseconds; use sk_cbor as cbor; use sk_cbor::cbor_map_options; diff --git a/src/ctap/storage.rs b/src/ctap/storage.rs index 371e38f..67fbda0 100644 --- a/src/ctap/storage.rs +++ b/src/ctap/storage.rs @@ -23,9 +23,8 @@ use crate::ctap::data_formats::{ extract_array, extract_text_string, CredentialProtectionPolicy, PublicKeyCredentialSource, PublicKeyCredentialUserEntity, }; -use crate::ctap::key_material; use crate::ctap::status_code::Ctap2StatusCode; -use crate::ctap::INITIAL_SIGNATURE_COUNTER; +use crate::ctap::{key_material, INITIAL_SIGNATURE_COUNTER}; use crate::env::Env; use alloc::string::String; use alloc::vec; diff --git a/third_party/lang-items/src/allocator.rs b/third_party/lang-items/src/allocator.rs index 0d1de00..991c135 100644 --- a/third_party/lang-items/src/allocator.rs +++ b/third_party/lang-items/src/allocator.rs @@ -1,6 +1,5 @@ use crate::util; -use core::alloc::GlobalAlloc; -use core::alloc::Layout; +use core::alloc::{GlobalAlloc, Layout}; #[cfg(any(feature = "debug_allocations", feature = "panic_console"))] use core::fmt::Write; use core::ptr; diff --git a/third_party/libtock-drivers/src/usb_ctap_hid.rs b/third_party/libtock-drivers/src/usb_ctap_hid.rs index d585932..cfb6736 100644 --- a/third_party/libtock-drivers/src/usb_ctap_hid.rs +++ b/third_party/libtock-drivers/src/usb_ctap_hid.rs @@ -15,9 +15,8 @@ #[cfg(feature = "debug_ctap")] use crate::console::Console; use crate::result::TockError; -use crate::timer; use crate::timer::Duration; -use crate::util; +use crate::{timer, util}; use core::cell::Cell; #[cfg(feature = "debug_ctap")] use core::fmt::Write;