@@ -1000,14 +1000,13 @@ fn validate_single_luks2_header(mut reader: impl std::io::Read, hdr_ind: u64) ->
10001000 ..
10011001 } = header;
10021002
1003- if hdr_ind == 0 {
1004- if magic != [ 76 , 85 , 75 , 83 , 186 , 190 ] {
1005- bail ! ( "Invalid LUKS magic: {:?}" , magic) ;
1006- }
1007- } else {
1008- if magic != [ 83 , 75 , 85 , 76 , 186 , 190 ] {
1009- bail ! ( "Invalid LUKS magic: {:?}" , magic) ;
1010- }
1003+ let expected_magic = match hdr_ind {
1004+ 0 => [ 76 , 85 , 75 , 83 , 186 , 190 ] ,
1005+ 1 => [ 83 , 75 , 85 , 76 , 186 , 190 ] ,
1006+ _ => bail ! ( "Invalid LUKS header index: {hdr_ind}" ) ,
1007+ } ;
1008+ if magic != expected_magic {
1009+ bail ! ( "Invalid LUKS magic: {magic:?}" ) ;
10111010 }
10121011 if version != 2 {
10131012 bail ! ( "Invalid LUKS version: {version}" ) ;
@@ -1024,7 +1023,7 @@ fn validate_single_luks2_header(mut reader: impl std::io::Read, hdr_ind: u64) ->
10241023 if hdr_offset != hdr_ind * hdr_size {
10251024 bail ! ( "Invalid LUKS header offset: {hdr_offset}" ) ;
10261025 }
1027- if hdr_size < 4096 || hdr_size > 1024 * 1024 * 16 {
1026+ if ! ( 4096 ..= 1024 * 1024 * 16 ) . contains ( & hdr_size ) {
10281027 bail ! ( "Invalid LUKS header size: {hdr_size}" ) ;
10291028 }
10301029
@@ -1058,7 +1057,7 @@ fn validate_single_luks2_header(mut reader: impl std::io::Read, hdr_ind: u64) ->
10581057 if keyslots. len ( ) != 1 {
10591058 bail ! ( "Invalid LUKS keyslots" ) ;
10601059 }
1061- if tokens. len ( ) != 0 {
1060+ if ! tokens. is_empty ( ) {
10621061 bail ! ( "Invalid LUKS tokens" ) ;
10631062 }
10641063 if segments. len ( ) != 1 {
0 commit comments