diff --git a/CHANGELOG.md b/CHANGELOG.md index c27ed62..ae42428 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/). allow those fields to have different widths. - Removed the `PusError::RawDataTooShort` variant which is already covered by `PusError::ByteConversionError` variant. +- Ranamed `TlvLvError::ByteConversionError` to `TlvLvError::ByteConversion`. + +## Removed + +- Removed `PusError::NoRawData` and renamed `PusError::IncorrectCrc` to + `PusError::ChecksumFailure`. # [v0.7.0-beta.2] 2023-09-26 diff --git a/src/cfdp/mod.rs b/src/cfdp/mod.rs index cab3351..cff6a56 100644 --- a/src/cfdp/mod.rs +++ b/src/cfdp/mod.rs @@ -180,7 +180,7 @@ pub const NULL_CHECKSUM_U32: [u8; 4] = [0; 4]; #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum TlvLvError { DataTooLarge(usize), - ByteConversionError(ByteConversionError), + ByteConversion(ByteConversionError), /// First value: Found value. Second value: Expected value if there is one. InvalidTlvTypeField((u8, Option)), /// Logically invalid value length detected. The value length may not exceed 255 bytes. @@ -195,7 +195,7 @@ pub enum TlvLvError { impl From for TlvLvError { fn from(value: ByteConversionError) -> Self { - Self::ByteConversionError(value) + Self::ByteConversion(value) } } @@ -210,7 +210,7 @@ impl Display for TlvLvError { u8::MAX ) } - TlvLvError::ByteConversionError(e) => { + TlvLvError::ByteConversion(e) => { write!(f, "{}", e) } TlvLvError::InvalidTlvTypeField((found, expected)) => { @@ -236,8 +236,32 @@ impl Display for TlvLvError { impl Error for TlvLvError { fn source(&self) -> Option<&(dyn Error + 'static)> { match self { - TlvLvError::ByteConversionError(e) => Some(e), + TlvLvError::ByteConversion(e) => Some(e), _ => None, } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_crc_from_bool() { + assert_eq!(CrcFlag::from(false), CrcFlag::NoCrc); + } + + #[test] + fn test_crc_flag_to_bool() { + let is_true: bool = CrcFlag::WithCrc.into(); + assert!(is_true); + let is_false: bool = CrcFlag::NoCrc.into(); + assert!(!is_false); + } + + #[test] + fn test_default_checksum_type() { + let checksum = ChecksumType::default(); + assert_eq!(checksum, ChecksumType::NullChecksum); + } +} diff --git a/src/cfdp/tlv/mod.rs b/src/cfdp/tlv/mod.rs index 2e779a1..d232d03 100644 --- a/src/cfdp/tlv/mod.rs +++ b/src/cfdp/tlv/mod.rs @@ -241,7 +241,7 @@ impl EntityIdTlv { self.entity_id .write_to_be_bytes(&mut buf[2..2 + self.entity_id.size()])?; Tlv::new(TlvType::EntityId, &buf[2..2 + self.entity_id.size()]).map_err(|e| match e { - TlvLvError::ByteConversionError(e) => e, + TlvLvError::ByteConversion(e) => e, // All other errors are impossible. _ => panic!("unexpected TLV error"), })