diff --git a/core/embed/rust/src/ui/display/toif.rs b/core/embed/rust/src/ui/display/toif.rs index b39059e1c..89a40a2eb 100644 --- a/core/embed/rust/src/ui/display/toif.rs +++ b/core/embed/rust/src/ui/display/toif.rs @@ -1,4 +1,5 @@ use crate::{ + error::Error, trezorhal::{ display::ToifFormat, uzlib::{UzlibContext, UZLIB_WINDOW_SIZE}, @@ -210,16 +211,16 @@ pub struct Toif<'i> { } impl<'i> Toif<'i> { - pub const fn new(data: &'i [u8]) -> Option { + pub const fn new(data: &'i [u8]) -> Result { if data.len() < TOIF_HEADER_LENGTH || data[0] != b'T' || data[1] != b'O' || data[2] != b'I' { - return None; + return Err(value_error!("Invalid TOIF header.")); } let zdatalen = u32::from_le_bytes([data[8], data[9], data[10], data[11]]) as usize; if zdatalen + TOIF_HEADER_LENGTH != data.len() { - return None; + return Err(value_error!("Invalid TOIF length.")); } - Some(Self { + Ok(Self { data, empty_right_column: false, }) @@ -317,8 +318,8 @@ pub struct Icon { impl Icon { pub const fn new(data: &'static [u8]) -> Self { let toif = match Toif::new(data) { - Some(t) => t, - None => panic!("Invalid image."), + Ok(t) => t, + _ => panic!("Invalid image."), }; assert!(matches!(toif.format(), ToifFormat::GrayScaleEH)); Self { diff --git a/core/embed/rust/src/ui/model_tt/component/homescreen/mod.rs b/core/embed/rust/src/ui/model_tt/component/homescreen/mod.rs index b66d884b7..e319f6efc 100644 --- a/core/embed/rust/src/ui/model_tt/component/homescreen/mod.rs +++ b/core/embed/rust/src/ui/model_tt/component/homescreen/mod.rs @@ -380,7 +380,7 @@ fn is_image_jpeg(buffer: &[u8]) -> bool { fn is_image_toif(buffer: &[u8]) -> bool { let toif = Toif::new(buffer); - if let Some(toif) = toif { + if let Ok(toif) = toif { if toif.size().x == HOMESCREEN_TOIF_SIZE && toif.size().y == HOMESCREEN_TOIF_SIZE && toif.format() == ToifFormat::FullColorBE