mirror of
https://github.com/Zenithsiz/dcb.git
synced 2026-02-04 08:23:13 +00:00
Invalid edc now returns an error.
This commit is contained in:
parent
b6973b8228
commit
082066af3e
@ -80,21 +80,12 @@ impl Bytes for Sector {
|
||||
};
|
||||
|
||||
// Validate edc
|
||||
{
|
||||
let bytes = match data {
|
||||
Data::Form1(_) => &byte_array[0x10..0x818],
|
||||
Data::Form2(_) => &byte_array[0x10..0x92c],
|
||||
};
|
||||
|
||||
//if !header.subheader.submode.contains(SubMode::FORM) {
|
||||
if let Err(expected_edc) = edc.is_valid(bytes) {
|
||||
log::warn!(
|
||||
"Sector crc {:#010x} doesn't match calculated crc {:#010x} match in {:?}",
|
||||
edc.crc,
|
||||
expected_edc,
|
||||
header
|
||||
);
|
||||
}
|
||||
let edc_bytes = match data {
|
||||
Data::Form1(_) => &byte_array[0x10..0x818],
|
||||
Data::Form2(_) => &byte_array[0x10..0x92c],
|
||||
};
|
||||
if let Err(calculated) = edc.is_valid(edc_bytes) {
|
||||
return Err(FromBytesError::WrongEdc { found: edc.crc, calculated });
|
||||
}
|
||||
|
||||
Ok(Self { header, data })
|
||||
|
||||
@ -17,6 +17,16 @@ pub enum FromBytesError {
|
||||
/// Unable to read header
|
||||
#[error("Unable to parse header")]
|
||||
Header(#[source] header::FromBytesError),
|
||||
|
||||
/// Edc was wrong
|
||||
#[error("Found crc {found}, calculated {calculated}")]
|
||||
WrongEdc {
|
||||
/// Found
|
||||
found: u32,
|
||||
|
||||
/// Calculated
|
||||
calculated: u32,
|
||||
},
|
||||
}
|
||||
|
||||
/// Error type for [`Bytes::to_bytes`](dcb_bytes::Bytes::to_bytes)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user