fixes for pdu error enum

This commit is contained in:
Robin Müller 2023-08-17 21:04:27 +02:00
parent 990b8de519
commit 9dfc593d2a
Signed by: muellerr
GPG Key ID: A649FB78196E3849
4 changed files with 6 additions and 7 deletions

View File

@ -106,7 +106,7 @@ impl EofPdu {
}
generic_length_checks_pdu_deserialization(buf, min_expected_len, full_len_without_crc)?;
let directive_type = FileDirectiveType::try_from(buf[current_idx]).map_err(|_| {
PduError::InvalidDirectiveType((buf[current_idx], FileDirectiveType::EofPdu))
PduError::InvalidDirectiveType((buf[current_idx], Some(FileDirectiveType::EofPdu)))
})?;
if directive_type != FileDirectiveType::EofPdu {
return Err(PduError::WrongDirectiveType((

View File

@ -170,7 +170,7 @@ impl<'fs_responses> FinishedPdu<'fs_responses> {
let min_expected_len = current_idx + 2;
generic_length_checks_pdu_deserialization(buf, min_expected_len, full_len_without_crc)?;
let directive_type = FileDirectiveType::try_from(buf[current_idx]).map_err(|_| {
PduError::InvalidDirectiveType((buf[current_idx], FileDirectiveType::FinishedPdu))
PduError::InvalidDirectiveType((buf[current_idx], Some(FileDirectiveType::FinishedPdu)))
})?;
if directive_type != FileDirectiveType::FinishedPdu {
return Err(PduError::WrongDirectiveType((

View File

@ -248,7 +248,7 @@ impl<'src_name, 'dest_name, 'opts> MetadataPdu<'src_name, 'dest_name, 'opts> {
}
generic_length_checks_pdu_deserialization(buf, min_expected_len, full_len_without_crc)?;
let directive_type = FileDirectiveType::try_from(buf[current_idx]).map_err(|_| {
PduError::InvalidDirectiveType((buf[current_idx], FileDirectiveType::MetadataPdu))
PduError::InvalidDirectiveType((buf[current_idx], Some(FileDirectiveType::MetadataPdu)))
})?;
if directive_type != FileDirectiveType::MetadataPdu {
return Err(PduError::WrongDirectiveType((

View File

@ -43,8 +43,8 @@ pub enum PduError {
WrongDirectiveType((FileDirectiveType, FileDirectiveType)),
/// The directive type field contained a value not in the range of permitted values.
/// The first tuple entry will be the found raw number, the second entry the expected entry
/// type.
InvalidDirectiveType((u8, FileDirectiveType)),
/// type when applicable.
InvalidDirectiveType((u8, Option<FileDirectiveType>)),
/// Invalid condition code. Contains the raw detected value.
InvalidConditionCode(u8),
/// Invalid checksum type which is not part of the checksums listed in the
@ -101,8 +101,7 @@ impl Display for PduError {
PduError::InvalidDirectiveType((found, expected)) => {
write!(
f,
"invalid directive type value {found}, expected {expected:?} ({})",
*expected as u8
"invalid directive type value {found}, expected {expected:?}"
)
}
PduError::InvalidChecksumType(checksum_type) => {