@@ -67,13 +67,13 @@ impl MeasurementedBootComponents {
67
67
let grub_authenticode_hashes = self
68
68
. grub
69
69
. iter ( )
70
- . map ( |bytes| calculate_authenticode_hash :: < T > ( & bytes) )
70
+ . map ( |bytes| calculate_authenticode_hash :: < T > ( bytes) )
71
71
. collect :: < Result < Vec < _ > > > ( ) ?;
72
72
73
73
let shim_authenticode_hashes = self
74
74
. shim
75
75
. iter ( )
76
- . map ( |bytes| calculate_authenticode_hash :: < T > ( & bytes) )
76
+ . map ( |bytes| calculate_authenticode_hash :: < T > ( bytes) )
77
77
. collect :: < Result < Vec < _ > > > ( ) ?;
78
78
79
79
Ok ( BootComponentsHashValue {
@@ -217,11 +217,26 @@ pub trait FdeDisk: Send + Sync {
217
217
218
218
for line in entry_content. lines ( ) {
219
219
if line. starts_with ( "linux " ) {
220
- kernel_path = line. splitn ( 2 , ' ' ) . nth ( 1 ) . unwrap_or ( "" ) . trim ( ) . to_string ( ) ;
220
+ kernel_path = line
221
+ . split_once ( ' ' )
222
+ . map ( |x| x. 1 )
223
+ . unwrap_or ( "" )
224
+ . trim ( )
225
+ . to_string ( ) ;
221
226
} else if line. starts_with ( "options " ) {
222
- cmdline = line. splitn ( 2 , ' ' ) . nth ( 1 ) . unwrap_or ( "" ) . trim ( ) . to_string ( ) ;
227
+ cmdline = line
228
+ . split_once ( ' ' )
229
+ . map ( |x| x. 1 )
230
+ . unwrap_or ( "" )
231
+ . trim ( )
232
+ . to_string ( ) ;
223
233
} else if line. starts_with ( "initrd " ) {
224
- initrd_path = line. splitn ( 2 , ' ' ) . nth ( 1 ) . unwrap_or ( "" ) . trim ( ) . to_string ( ) ;
234
+ initrd_path = line
235
+ . split_once ( ' ' )
236
+ . map ( |x| x. 1 )
237
+ . unwrap_or ( "" )
238
+ . trim ( )
239
+ . to_string ( ) ;
225
240
}
226
241
}
227
242
@@ -245,7 +260,7 @@ pub trait FdeDisk: Send + Sync {
245
260
246
261
// Make kernel path absolute if needed
247
262
if !kernel_path. is_empty ( ) {
248
- if kernel_path. starts_with ( "/" ) {
263
+ if kernel_path. starts_with ( '/' ) {
249
264
// Already absolute
250
265
} else {
251
266
kernel_path = format ! ( "/boot/{}" , kernel_path) ;
@@ -254,7 +269,7 @@ pub trait FdeDisk: Send + Sync {
254
269
255
270
// Make initrd path absolute if needed
256
271
if !initrd_path. is_empty ( ) {
257
- if initrd_path. starts_with ( "/" ) {
272
+ if initrd_path. starts_with ( '/' ) {
258
273
// Already absolute
259
274
} else {
260
275
initrd_path = format ! ( "/boot/{}" , initrd_path) ;
@@ -265,7 +280,7 @@ pub trait FdeDisk: Send + Sync {
265
280
266
281
// Calculate SHA384 hashes
267
282
let kernel = self
268
- . read_file_on_disk ( & kernel_path)
283
+ . read_file_on_disk ( kernel_path)
269
284
. await
270
285
. with_context ( || format ! ( "Failed to read kernel file at {:?}" , kernel_path) ) ?;
271
286
@@ -284,7 +299,7 @@ pub trait FdeDisk: Send + Sync {
284
299
// Extract partition number from device path
285
300
// For example, /dev/sda3 -> (hd0,gpt3) or (hd0,msdos3), /dev/nvme0n1p3 -> (hd0,gpt3) or (hd0,msdos3)
286
301
let boot_dev = self . get_boot_dev ( ) ;
287
- if let Some ( partition_num) = boot_dev
302
+ if let Ok ( partition_num) = boot_dev
288
303
. to_string_lossy ( )
289
304
. chars ( )
290
305
. rev ( )
@@ -294,7 +309,6 @@ pub trait FdeDisk: Send + Sync {
294
309
. rev ( )
295
310
. collect :: < String > ( )
296
311
. parse :: < u32 > ( )
297
- . ok ( )
298
312
{
299
313
match partition_type {
300
314
PartitionTableType :: Gpt => format ! ( "(hd0,gpt{})" , partition_num) ,
@@ -408,29 +422,22 @@ pub trait FdeDisk: Send + Sync {
408
422
409
423
let mut entries = async_walkdir:: WalkDir :: new ( efi_part_root_dir) ;
410
424
411
- loop {
412
- match entries. next ( ) . await {
413
- Some ( Ok ( entry) ) => {
414
- if matches ! ( entry. file_type( ) . await . map( |e| e. is_file( ) ) , Ok ( true ) ) {
415
- let file_name = entry. file_name ( ) . to_string_lossy ( ) . to_lowercase ( ) ;
416
-
417
- if file_name == "grubx64.efi" {
418
- tracing:: debug!( file=?entry. path( ) , "Found grubx64.efi" ) ;
419
- let mut buf = vec ! [ ] ;
420
- let mut file = File :: open ( entry. path ( ) ) . await ?;
421
- file. read_to_end ( & mut buf) . await ?;
422
- let _ = grub_data. insert ( buf) ;
423
- } else if file_name == "shimx64.efi" {
424
- tracing:: debug!( file=?entry. path( ) , "Found shimx64.efi" ) ;
425
- let mut buf = vec ! [ ] ;
426
- let mut file = File :: open ( entry. path ( ) ) . await ?;
427
- file. read_to_end ( & mut buf) . await ?;
428
- let _ = shim_data. insert ( buf) ;
429
- }
430
- }
431
- }
432
- Some ( Err ( _) ) | None => {
433
- break ;
425
+ while let Some ( Ok ( entry) ) = entries. next ( ) . await {
426
+ if matches ! ( entry. file_type( ) . await . map( |e| e. is_file( ) ) , Ok ( true ) ) {
427
+ let file_name = entry. file_name ( ) . to_string_lossy ( ) . to_lowercase ( ) ;
428
+
429
+ if file_name == "grubx64.efi" {
430
+ tracing:: debug!( file=?entry. path( ) , "Found grubx64.efi" ) ;
431
+ let mut buf = vec ! [ ] ;
432
+ let mut file = File :: open ( entry. path ( ) ) . await ?;
433
+ file. read_to_end ( & mut buf) . await ?;
434
+ let _ = grub_data. insert ( buf) ;
435
+ } else if file_name == "shimx64.efi" {
436
+ tracing:: debug!( file=?entry. path( ) , "Found shimx64.efi" ) ;
437
+ let mut buf = vec ! [ ] ;
438
+ let mut file = File :: open ( entry. path ( ) ) . await ?;
439
+ file. read_to_end ( & mut buf) . await ?;
440
+ let _ = shim_data. insert ( buf) ;
434
441
}
435
442
}
436
443
}
@@ -445,8 +452,8 @@ pub trait FdeDisk: Send + Sync {
445
452
fn get_efi_part_root_dir ( & self ) -> & Path ;
446
453
}
447
454
448
- const CRYPTPILOT_CONFIG_DIR_UNTRUSTED_IN_BOOT : & ' static str = "cryptpilot/config" ;
449
- const METADATA_PATH_IN_BOOT : & ' static str = "cryptpilot/metadata.toml" ;
455
+ const CRYPTPILOT_CONFIG_DIR_UNTRUSTED_IN_BOOT : & str = "cryptpilot/config" ;
456
+ const METADATA_PATH_IN_BOOT : & str = "cryptpilot/metadata.toml" ;
450
457
451
458
async fn load_fde_config_bundle_from_dir ( config_dir : & Path ) -> Result < FdeConfigBundle > {
452
459
Ok ( FileSystemConfigSource :: new ( config_dir)
@@ -662,7 +669,7 @@ impl OnExternalFdeDisk {
662
669
663
670
let content = String :: from_utf8_lossy ( & output) ;
664
671
for line in content. lines ( ) {
665
- let fields: Vec < & str > = line. trim ( ) . split_whitespace ( ) . collect ( ) ;
672
+ let fields: Vec < & str > = line. split_whitespace ( ) . collect ( ) ;
666
673
if fields. len ( ) != 2 {
667
674
continue ;
668
675
}
0 commit comments