What changed, and why it matters
This commit is a routine internal refactoring of the BitBox02 firmware's unlock animation. It replaces a callback-based animation trigger with a modern Rust async/await implementation and moves the screensaver-inhibit logic into a dedicated helper. There is no indication this fixes or introduces a security vulnerability.
No security action required. Treat as normal code-quality refactoring; standard review and testing are sufficient.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change ports unlock_animation from a callback-style API (unlock_animation_create + option_no_screensaver) to an async function (unlock_animation()). It introduces a SharedState struct carrying a Waker and result, bridges to a C callback via user_data, and uses core::future::poll_fn to suspend until the animation completes. The old bb02_async::option_no_screensaver helper and module are removed; screensaver inhibition is now handled by crate::screen_saver::ScreensaverInhibitor. Stubs are updated accordingly. No security-relevant behavior change is evident.
Changed components
src/rust/bitbox02-rust/src/workflow/unlock_animation.rssrc/rust/bitbox02/src/ui/ui.rssrc/rust/bitbox02/src/ui/ui_stub.rssrc/rust/bitbox02/src/ui/ui_stub_c_unit_tests.rssrc/rust/bitbox02-rust/src/bb02_async.rssrc/rust/bitbox02-rust/src/lib.rsInspect captured patch +49 / −58
diff --git a/src/rust/bitbox02-rust/src/bb02_async.rs b/src/rust/bitbox02-rust/src/bb02_async.rs
deleted file mode 100644
index bf00508..0000000
--- a/src/rust/bitbox02-rust/src/bb02_async.rs
+++ /dev/null
@@ -1,11 +0,0 @@
-// SPDX-License-Identifier: Apache-2.0
-
-use core::cell::RefCell;
-
-/// Disables the screensaver while waiting for an option to contain a value. Afterwards, it returns that value
-pub async fn option_no_screensaver<O>(opt: &RefCell<Option<O>>) -> O {
- bitbox02::screen_saver::screen_saver_disable();
- let result = util::bb02_async::option(opt).await;
- bitbox02::screen_saver::screen_saver_enable();
- result
-}
diff --git a/src/rust/bitbox02-rust/src/lib.rs b/src/rust/bitbox02-rust/src/lib.rs
index 3064b8a..fe6f863 100644
--- a/src/rust/bitbox02-rust/src/lib.rs
+++ b/src/rust/bitbox02-rust/src/lib.rs
@@ -17,7 +17,6 @@ pub mod general;
pub mod async_usb;
pub mod attestation;
pub mod backup;
-pub mod bb02_async;
mod bip32;
pub mod bip39;
pub mod communication_mode;
diff --git a/src/rust/bitbox02-rust/src/workflow/unlock_animation.rs b/src/rust/bitbox02-rust/src/workflow/unlock_animation.rs
index 4e3787c..912aafa 100644
--- a/src/rust/bitbox02-rust/src/workflow/unlock_animation.rs
+++ b/src/rust/bitbox02-rust/src/workflow/unlock_animation.rs
@@ -1,15 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
-use crate::bb02_async::option_no_screensaver;
-use core::cell::RefCell;
-
/// Performs the unlock animation. Its duration is determined by the component render rate, see
/// unlock_animation.c
pub async fn animate() {
- let result = RefCell::new(None as Option<()>);
- let mut component = bitbox02::ui::unlock_animation_create(|| {
- *result.borrow_mut() = Some(());
- });
- component.screen_stack_push();
- option_no_screensaver(&result).await
+ bitbox02::ui::unlock_animation().await;
}
diff --git a/src/rust/bitbox02/src/ui/ui.rs b/src/rust/bitbox02/src/ui/ui.rs
index 5321510..7f3d622 100644
--- a/src/rust/bitbox02/src/ui/ui.rs
+++ b/src/rust/bitbox02/src/ui/ui.rs
@@ -709,31 +709,60 @@ pub fn empty_create<'a>() -> Component<'a> {
}
}
-pub fn unlock_animation_create<'a, F>(on_done: F) -> Component<'a>
-where
- // Callback must outlive component.
- F: FnMut() + 'a,
-{
- unsafe extern "C" fn c_on_done<F2>(param: *mut c_void)
- where
- F2: FnMut(),
- {
- // The callback is dropped afterwards. This is safe because
- // this C callback is guaranteed to be called only once.
- let mut on_done = unsafe { Box::from_raw(param as *mut F2) };
- on_done();
+pub async fn unlock_animation() {
+ let _no_screensaver = crate::screen_saver::ScreensaverInhibitor::new();
+
+ // Shared between the async context and the c callback
+ struct SharedState {
+ waker: Option<Waker>,
+ result: Option<()>,
+ }
+ let shared_state = Box::new(RefCell::new(SharedState {
+ waker: None,
+ result: None,
+ }));
+ let shared_state_ptr = shared_state.as_ref() as *const RefCell<SharedState> as *mut c_void;
+
+ unsafe extern "C" fn callback(user_data: *mut c_void) {
+ let shared_state = unsafe { &*(user_data as *mut RefCell<SharedState>) };
+ let mut shared_state = shared_state.borrow_mut();
+ if shared_state.result.is_none() {
+ shared_state.result = Some(());
+ if let Some(waker) = shared_state.waker.as_ref() {
+ waker.wake_by_ref();
+ }
+ }
}
+
let component = unsafe {
bitbox02_sys::unlock_animation_create(
- Some(c_on_done::<F>),
- Box::into_raw(Box::new(on_done)) as *mut _, // passed to c_on_done as `param`.
+ Some(callback),
+ shared_state_ptr, // passed to callback as `user_data`.
)
};
- Component {
+
+ let mut component = Component {
component,
is_pushed: false,
_p: PhantomData,
- }
+ };
+ component.screen_stack_push();
+
+ core::future::poll_fn({
+ let shared_state = &shared_state;
+ move |cx| {
+ let mut shared_state = shared_state.borrow_mut();
+
+ if let Some(result) = shared_state.result.take() {
+ Poll::Ready(result)
+ } else {
+ // Store the waker so the callback can wake up this task
+ shared_state.waker = Some(cx.waker().clone());
+ Poll::Pending
+ }
+ }
+ })
+ .await
}
pub async fn choose_orientation() -> bool {
diff --git a/src/rust/bitbox02/src/ui/ui_stub.rs b/src/rust/bitbox02/src/ui/ui_stub.rs
index 8aa474e..a88e405 100644
--- a/src/rust/bitbox02/src/ui/ui_stub.rs
+++ b/src/rust/bitbox02/src/ui/ui_stub.rs
@@ -104,16 +104,7 @@ pub fn empty_create<'a>() -> Component<'a> {
}
}
-pub fn unlock_animation_create<'a, F>(mut on_done: F) -> Component<'a>
-where
- F: FnMut() + 'a,
-{
- on_done();
- Component {
- is_pushed: false,
- _p: PhantomData,
- }
-}
+pub async fn unlock_animation() {}
pub async fn choose_orientation() -> bool {
false
diff --git a/src/rust/bitbox02/src/ui/ui_stub_c_unit_tests.rs b/src/rust/bitbox02/src/ui/ui_stub_c_unit_tests.rs
index 42ede4b..6ae6d14 100644
--- a/src/rust/bitbox02/src/ui/ui_stub_c_unit_tests.rs
+++ b/src/rust/bitbox02/src/ui/ui_stub_c_unit_tests.rs
@@ -126,16 +126,7 @@ pub fn empty_create<'a>() -> Component<'a> {
}
}
-pub fn unlock_animation_create<'a, F>(mut on_done: F) -> Component<'a>
-where
- F: FnMut() + 'a,
-{
- on_done();
- Component {
- is_pushed: false,
- _p: PhantomData,
- }
-}
+pub async fn unlock_animation() {}
pub async fn choose_orientation() -> bool {
false
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.