Skip to content

Commit 208fc14

Browse files
committed
feat(types): add setters for enable and sticky application's flags
fix(tests/serialization): removed redundant tests and make enable and sticky tests explicit
1 parent 8430e23 commit 208fc14

2 files changed

Lines changed: 56 additions & 245 deletions

File tree

tbf-parser/src/types.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,37 @@ impl TbfHeader {
12221222
Ok(())
12231223
}
12241224

1225-
/// Returns a 16 byte array with the serialized base header (little-endian format)
1225+
/// Returns the TBF Header's flags (avoid duplication code for the setting functions below).
1226+
fn get_flags(&self) -> u32 {
1227+
match self {
1228+
TbfHeader::TbfHeaderV2(hd) => hd.base.flags,
1229+
TbfHeader::Padding(base) => base.flags,
1230+
}
1231+
}
1232+
1233+
/// Enables or disables the application by setting the enabled flag.
1234+
pub fn set_enabled(&mut self, enabled: bool, header: &[u8]) -> Result<(), TbfParseError> {
1235+
let flags:u32 = if enabled {
1236+
self.get_flags() | 0x00000001
1237+
}
1238+
else {
1239+
self.get_flags() & !0x00000001
1240+
};
1241+
self.set_flags(flags, header)
1242+
}
1243+
1244+
/// Enable or disables erase confirmation by setting the sticky flag.
1245+
pub fn set_sticky(&mut self, enabled: bool, header: &[u8]) -> Result<(), TbfParseError> {
1246+
let flags:u32 = if enabled {
1247+
self.get_flags() | 0x00000002
1248+
}
1249+
else {
1250+
self.get_flags() & !0x00000002
1251+
};
1252+
self.set_flags(flags, header)
1253+
}
1254+
1255+
/// Returns a 16 byte array with the serialized base header (little-endian format).
12261256
pub fn serialize(&self) -> Result<[u8; 16], TbfParseError> {
12271257
let base = match self {
12281258
TbfHeader::TbfHeaderV2(hd) => &hd.base,

0 commit comments

Comments
 (0)