lanzaboote: fix clippy issues

This commit is contained in:
Julian Stecklina 2022-11-28 13:38:01 +01:00
parent 4fb1e0d0dd
commit 7926ab9e5e
2 changed files with 11 additions and 6 deletions

View File

@ -147,16 +147,16 @@ fn initrd_location(initrd_efi: &mut RegularFile) -> Result<Range<usize>> {
.sections
.iter()
.find(|s| s.name().unwrap() == ".initrd")
.and_then(|s| {
.map(|s| {
let section_start: usize = s.pointer_to_raw_data.try_into().unwrap();
let section_size: usize = s.size_of_raw_data.try_into().unwrap();
Some(Range {
Range {
start: section_start,
end: section_start + section_size,
}
})
})
.ok_or(Status::END_OF_FILE.into())
.ok_or_else(|| Status::END_OF_FILE.into())
}
/// Check the signature of the initrd.

View File

@ -1,3 +1,9 @@
// Clippy doesn't like the lifetimes, but rustc wants them. 🤷
#![allow(clippy::needless_lifetimes)]
// Clippy doesn't understand that we exit with ? from the closure in
// and_then below and this can't be expressed with map.
#![allow(clippy::bind_instead_of_map)]
use alloc::{borrow::ToOwned, string::String};
/// Extracts the data of a section of a PE file.
@ -20,6 +26,5 @@ pub fn pe_section<'a>(file_data: &'a [u8], section_name: &str) -> Option<&'a [u8
/// Extracts the data of a section of a PE file and returns it as a string.
pub fn pe_section_as_string<'a>(file_data: &'a [u8], section_name: &str) -> Option<String> {
pe_section(file_data, section_name)
.and_then(|data| Some(core::str::from_utf8(data).unwrap().to_owned()))
pe_section(file_data, section_name).map(|data| core::str::from_utf8(data).unwrap().to_owned())
}