From f8ef06ee0c5a88df8865d2e08008cfc5bcc586ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Hlusi=C4=8Dka?= Date: Sat, 31 Jan 2026 15:36:36 +0100 Subject: [PATCH] Clean up some lints --- firmware/acid-firmware/src/db/mod.rs | 4 +- firmware/acid-firmware/src/ffi/crypto.rs | 5 +- firmware/acid-firmware/src/ffi/inout/mod.rs | 2 +- firmware/acid-firmware/src/ffi/mod.rs | 1 - firmware/acid-firmware/src/keymap.rs | 2 +- firmware/acid-firmware/src/main.rs | 7 +- firmware/acid-firmware/src/ui/backend.rs | 8 +- firmware/acid-firmware/src/ui/mod.rs | 129 ++++++++------------ firmware/acid-firmware/src/ui/storage.rs | 4 +- 9 files changed, 61 insertions(+), 101 deletions(-) diff --git a/firmware/acid-firmware/src/db/mod.rs b/firmware/acid-firmware/src/db/mod.rs index 314b3aa..4872b3f 100644 --- a/firmware/acid-firmware/src/db/mod.rs +++ b/firmware/acid-firmware/src/db/mod.rs @@ -9,7 +9,7 @@ use ekv::{ flash::{Flash, PageID}, }; use embassy_embedded_hal::{adapter::BlockingAsync, flash::partition::Partition}; -use embassy_sync::blocking_mutex::raw::{CriticalSectionRawMutex, RawMutex}; +use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; use embedded_storage_async::nor_flash::{NorFlash, ReadNorFlash}; use esp_hal::rng::Trng; use esp_storage::FlashStorage; @@ -300,7 +300,7 @@ where key: &[u8], buffer: &'b mut Vec, ) -> Result<&'b mut [u8], ekv::ReadError> { - if buffer.len() == 0 { + if buffer.is_empty() { buffer.resize(1, 0); } diff --git a/firmware/acid-firmware/src/ffi/crypto.rs b/firmware/acid-firmware/src/ffi/crypto.rs index 5f27955..e25401f 100644 --- a/firmware/acid-firmware/src/ffi/crypto.rs +++ b/firmware/acid-firmware/src/ffi/crypto.rs @@ -5,10 +5,7 @@ use core::{ use data_encoding_macro::hexlower; use embassy_sync::blocking_mutex::{self, raw::CriticalSectionRawMutex}; -use hmac::{ - Hmac, SimpleHmac, - digest::{FixedOutput, KeyInit, Update}, -}; +use hmac::digest::{FixedOutput, KeyInit, Update}; use sha2::{ Digest, digest::{consts::U32, generic_array::GenericArray}, diff --git a/firmware/acid-firmware/src/ffi/inout/mod.rs b/firmware/acid-firmware/src/ffi/inout/mod.rs index 98157e3..ee5b2fc 100644 --- a/firmware/acid-firmware/src/ffi/inout/mod.rs +++ b/firmware/acid-firmware/src/ffi/inout/mod.rs @@ -76,7 +76,7 @@ pub unsafe extern "C" fn __xkbc_fprintf( pub unsafe extern "C" fn __spre_fprintf( stream: *mut FILE, format: *const c_char, - mut args: ... + args: ... ) -> c_int { unsafe { __xkbc_fprintf(stream, format) } } diff --git a/firmware/acid-firmware/src/ffi/mod.rs b/firmware/acid-firmware/src/ffi/mod.rs index 6062653..f899a23 100644 --- a/firmware/acid-firmware/src/ffi/mod.rs +++ b/firmware/acid-firmware/src/ffi/mod.rs @@ -1,7 +1,6 @@ #![allow(unused_variables)] use core::{ - error, ffi::{c_char, c_int, c_long, c_longlong, c_size_t, c_void}, ptr::null_mut, }; diff --git a/firmware/acid-firmware/src/keymap.rs b/firmware/acid-firmware/src/keymap.rs index 74f4c15..44aca3d 100644 --- a/firmware/acid-firmware/src/keymap.rs +++ b/firmware/acid-firmware/src/keymap.rs @@ -18,7 +18,7 @@ use slint::platform::Key; use xkbcommon::xkb::{self, FeedResult, KeyDirection, Keysym, Status}; use crate::matrix::{MATRIX_COLS, MATRIX_ROWS}; -use crate::util::{DurationExt, FormattedDuration}; +use crate::util::DurationExt; use crate::vial::CustomKeycodes; use crate::{KEYBOARD_REPORT_PROXY, PSRAM_ALLOCATOR}; diff --git a/firmware/acid-firmware/src/main.rs b/firmware/acid-firmware/src/main.rs index 29b4bb9..32e033c 100644 --- a/firmware/acid-firmware/src/main.rs +++ b/firmware/acid-firmware/src/main.rs @@ -25,13 +25,12 @@ use alloc::vec; use embassy_embedded_hal::adapter::BlockingAsync; use embassy_embedded_hal::flash::partition::Partition; use embassy_executor::Spawner; -use embassy_sync::blocking_mutex; use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; use embassy_sync::channel::Channel; use embassy_sync::mutex::Mutex; use embassy_sync::signal::Signal; use embassy_time::{Duration, Timer}; -use esp_alloc::{HeapRegion, MemoryCapability, RegionStats}; +use esp_alloc::{HeapRegion, MemoryCapability}; use esp_hal::Blocking; use esp_hal::clock::CpuClock; use esp_hal::dma::{BurstConfig, DmaDescriptor, DmaTxBuf, ExternalBurstConfig}; @@ -44,10 +43,9 @@ use esp_hal::mcpwm::{McPwm, PeripheralClockConfig}; use esp_hal::psram::{FlashFreq, PsramConfig, PsramSize, SpiRamFreq, SpiTimingConfigCoreClock}; use esp_hal::ram; use esp_hal::rng::TrngSource; -use esp_hal::sha::{Sha, ShaBackend}; +use esp_hal::sha::ShaBackend; use esp_hal::system::Stack; use esp_hal::timer::timg::TimerGroup; -use esp_println::println; use esp_rtos::embassy::Executor; use esp_storage::FlashStorage; use log::{error, info, warn}; @@ -64,7 +62,6 @@ use rmk::storage::async_flash_wrapper; use rmk::types::action::{Action, KeyAction}; use rmk::{initialize_keymap_and_storage, run_devices, run_rmk}; use slint::platform::software_renderer::Rgb565Pixel; -use spectre_api_sys::SpectreAlgorithm; use static_cell::StaticCell; use {esp_alloc as _, esp_backtrace as _}; diff --git a/firmware/acid-firmware/src/ui/backend.rs b/firmware/acid-firmware/src/ui/backend.rs index ac3ea35..a3217fb 100644 --- a/firmware/acid-firmware/src/ui/backend.rs +++ b/firmware/acid-firmware/src/ui/backend.rs @@ -2,9 +2,9 @@ use core::{cell::RefCell, time::Duration}; use alloc::{rc::Rc, string::ToString}; use esp_hal::time::Instant; -use log::{debug, info, warn}; +use log::{debug, info}; use slint::{ - PhysicalSize, SharedString, ToSharedString, WindowSize, + PhysicalSize, SharedString, WindowSize, platform::{ Key, WindowEvent, software_renderer::{RenderingRotation, RepaintBufferType, Rgb565Pixel, SoftwareRenderer}, @@ -62,8 +62,7 @@ impl slint::platform::Platform for SlintBackend { if let Some(string) = key_message.string.as_ref() && (Keysym::a..=Keysym::z).contains(&key_message.keysym) - { - if let &[code] = string.as_bytes() { + && let &[code] = string.as_bytes() { const UNICODE_CTRL_A: char = '\u{1}'; let letter_index_from_keysym = @@ -85,7 +84,6 @@ impl slint::platform::Platform for SlintBackend { ); } } - } // let text = key_message.string.map(SharedString::from).or_else(|| { // Key::try_from_keysym(key_message.keysym).map(SharedString::from) diff --git a/firmware/acid-firmware/src/ui/mod.rs b/firmware/acid-firmware/src/ui/mod.rs index 31a51ce..64b82b9 100644 --- a/firmware/acid-firmware/src/ui/mod.rs +++ b/firmware/acid-firmware/src/ui/mod.rs @@ -1,50 +1,18 @@ // #![cfg_attr(not(feature = "simulator"), no_main)] -use core::{ - cell::RefCell, - ffi::CStr, - iter::Chain, - ops::{Deref, DerefMut, Range}, -}; +use core::{cell::RefCell, ffi::CStr}; -use alloc::{ - borrow::Cow, - boxed::Box, - ffi::CString, - format, - rc::Rc, - string::{String, ToString}, - vec, - vec::Vec, -}; -use chrono::{DateTime, NaiveDateTime}; -use ekv::{Database, MountError, flash::PageID}; -use embassy_embedded_hal::{adapter::BlockingAsync, flash::partition::Partition}; -use embassy_sync::blocking_mutex::raw::{CriticalSectionRawMutex, RawMutex}; -use embassy_time::{Duration, Instant}; -use embedded_storage_async::nor_flash::{NorFlash, ReadNorFlash}; -use esp_hal::rng::Trng; -use esp_storage::FlashStorage; -use itertools::Itertools; +use alloc::{boxed::Box, ffi::CString, format, rc::Rc, vec}; +use embassy_time::Instant; use log::{info, warn}; -use password_hash::Key; -use rmk::futures::TryFutureExt; -use serde::{Deserialize, Serialize}; -use serde_bytes::Bytes; -use slint::{ModelRc, SharedString, StandardListViewItem, VecModel}; -use spectre_api_sys::{ - SpectreAlgorithm, SpectreCounter, SpectreKeyID, SpectreKeyPurpose, SpectreResultType, - SpectreUserKey, -}; +use slint::SharedString; +use spectre_api_sys::{SpectreAlgorithm, SpectreUserKey}; #[cfg(feature = "limit-fps")] use crate::FRAME_DURATION_MIN; use crate::{ PSRAM_ALLOCATOR, SIGNAL_LCD_SUBMIT, SIGNAL_UI_RENDER, - db::{ - AcidDatabase, DbKey, DbPathSpectreUserSite, DbPathSpectreUserSites, DbPathSpectreUsers, - PartitionAcid, ReadTransactionExt, - }, + db::{AcidDatabase, DbKey, DbPathSpectreUsers, PartitionAcid, ReadTransactionExt}, ffi::alloc::__spre_free, ui::{ backend::SlintBackend, @@ -77,7 +45,7 @@ fn spectre_derive_user_key(username: &CStr, password: &CStr) -> SpectreUserKey { "User key derived in {} seconds:\n{user_key:02x?}", user_key_duration.display_as_secs() ); - let user_key_stack = user_key.clone(); + let user_key_stack = *user_key; // TODO: Erase memory before freeing __spre_free(user_key as *const _ as *mut _); @@ -215,7 +183,7 @@ impl State { .read_to_vec(&DbKey::new(DbPathSpectreUsers), &mut buffer) .await { - Ok(bytes) => postcard::from_bytes::(&bytes).unwrap(), + Ok(bytes) => postcard::from_bytes::(bytes).unwrap(), Err(ekv::ReadError::KeyNotFound) => Default::default(), Err(error) => panic!("Failed to read the users config: {error:?}"), } @@ -347,7 +315,7 @@ impl State { } trait AppViewTrait { - fn process_callback_message(state: &mut State, message: CallbackMessage) {} + fn process_callback_message(_state: &mut State, _message: CallbackMessage) {} } #[derive(Default)] @@ -355,48 +323,47 @@ struct StateLogin {} impl AppViewTrait for StateLogin { fn process_callback_message(state: &mut State, message: CallbackMessage) { - match message { - CallbackMessage::Login(CallbackMessageLogin::PwAccepted { username, password }) => { - let username_c = - CString::new(&*username).expect("Username cannot be converted to a C string."); - let password_c = - CString::new(&*password).expect("Password cannot be converted to a C string."); - let user_key = spectre_derive_user_key(&username_c, &password_c); + if let CallbackMessage::Login(CallbackMessageLogin::PwAccepted { username, password }) = + message + { + let username_c = + CString::new(&*username).expect("Username cannot be converted to a C string."); + let password_c = + CString::new(&*password).expect("Password cannot be converted to a C string."); + let user_key = spectre_derive_user_key(&username_c, &password_c); - // let site_key_start = Instant::now(); - // let site_key = &*spectre_api_sys::spectre_site_key( - // user_key as *const SpectreUserKey, - // c"example.org".as_ptr(), - // SpectreCounter::Initial, - // SpectreKeyPurpose::Authentication, - // c"".as_ptr(), - // ); - // let site_key_duration = Instant::now().duration_since(site_key_start); - // warn!( - // "Site key derived in {} seconds:\n{site_key:02x?}", - // site_key_duration.display_as_secs() - // ); - // TODO: Erase memory before freeing - // __spre_free(site_key as *const _ as *mut _); - let Some(user) = state - .users - .users - .iter() - .find(|user| &*user.username == &*username) - else { - return; - }; + // let site_key_start = Instant::now(); + // let site_key = &*spectre_api_sys::spectre_site_key( + // user_key as *const SpectreUserKey, + // c"example.org".as_ptr(), + // SpectreCounter::Initial, + // SpectreKeyPurpose::Authentication, + // c"".as_ptr(), + // ); + // let site_key_duration = Instant::now().duration_since(site_key_start); + // warn!( + // "Site key derived in {} seconds:\n{site_key:02x?}", + // site_key_duration.display_as_secs() + // ); + // TODO: Erase memory before freeing + // __spre_free(site_key as *const _ as *mut _); + let Some(user) = state + .users + .users + .iter() + .find(|user| *user.username == *username) + else { + return; + }; - if user.key_id == user_key.keyID.bytes { - info!("Correct password entered for user {username:?}."); - state.state_user_sites = Some(StateUserSites { username, user_key }); - state.set_view(AppState::UserSites, true); - } else { - warn!("Incorrect password entered for user {username:?}."); - // TODO: Clear the input - } + if user.key_id == user_key.keyID.bytes { + info!("Correct password entered for user {username:?}."); + state.state_user_sites = Some(StateUserSites { username, user_key }); + state.set_view(AppState::UserSites, true); + } else { + warn!("Incorrect password entered for user {username:?}."); + // TODO: Clear the input } - _ => (), } } } @@ -469,7 +436,7 @@ impl AppViewTrait for StateUserEdit { identicon, }) } - CallbackMessage::UserEdit(CallbackMessageUserEdit::Confirm { encrypted_key }) => { + CallbackMessage::UserEdit(CallbackMessageUserEdit::Confirm { encrypted_key: _ }) => { // TODO } _ => (), diff --git a/firmware/acid-firmware/src/ui/storage.rs b/firmware/acid-firmware/src/ui/storage.rs index 259e2e6..958b044 100644 --- a/firmware/acid-firmware/src/ui/storage.rs +++ b/firmware/acid-firmware/src/ui/storage.rs @@ -50,7 +50,7 @@ impl Default for SpectreSiteConfig { } #[derive(Clone, Debug, PartialEq, Eq)] -struct SpectreSite { +pub struct SpectreSite { pub username: String, pub site_name: String, pub config: SpectreSiteConfig, @@ -91,6 +91,7 @@ mod with_repr { } } + #[allow(unused)] pub fn serialize(value: &T, serializer: S) -> Result where T: ReprConvert, @@ -99,6 +100,7 @@ mod with_repr { serializer.serialize_u32(value.into_repr()) } + #[allow(unused)] pub fn deserialize<'de, T, D>(deserializer: D) -> Result where T: ReprConvert,