use sbat::{RevocationSection, RevocationSectionError};
#[cfg(feature = "alloc")]
use sbat::RevocationSbatOwned;
#[cfg(feature = "alloc")]
#[test]
fn test_actual_sbatlevel_data() {
let data = include_bytes!("sbatlevel.section");
let sbat_level_section = RevocationSection::parse(data).unwrap();
assert_eq!(
sbat_level_section.previous(),
b"sbat,1,2022052400\ngrub,2\n"
);
assert_eq!(
sbat_level_section.latest(),
b"sbat,1,2023012900\nshim,2\ngrub,3\ngrub.debian,4\n"
);
RevocationSbatOwned::parse(sbat_level_section.previous()).unwrap();
RevocationSbatOwned::parse(sbat_level_section.latest()).unwrap();
let mut data = data.to_vec();
data.push(123);
let sbat_level_section2 = RevocationSection::parse(&data).unwrap();
assert_eq!(sbat_level_section, sbat_level_section2);
}
#[test]
fn test_sbat_level_section_errors() {
assert_eq!(
RevocationSection::parse(&[0, 0, 0]),
Err(RevocationSectionError::MissingVersion)
);
assert_eq!(
RevocationSection::parse(&[1, 0, 0, 0]),
Err(RevocationSectionError::InvalidVersion(1))
);
assert_eq!(
RevocationSection::parse(&[0; 11]),
Err(RevocationSectionError::MissingHeader)
);
#[rustfmt::skip]
let data = [
0, 0, 0, 0,
8, 0, 0, 0,
8, 0, 0, 0,
];
assert_eq!(
RevocationSection::parse(&data),
Err(RevocationSectionError::InvalidPreviousOffset(8))
);
#[rustfmt::skip]
let data = [
0, 0, 0, 0,
8, 0, 0, 0,
9, 0, 0, 0,
0,
];
assert_eq!(
RevocationSection::parse(&data),
Err(RevocationSectionError::InvalidLatestOffset(9))
);
#[rustfmt::skip]
let data = [
0, 0, 0, 0,
8, 0, 0, 0,
8, 0, 0, 0,
1,
];
assert_eq!(
RevocationSection::parse(&data),
Err(RevocationSectionError::MissingPreviousNull),
);
#[rustfmt::skip]
let data = [
0, 0, 0, 0,
8, 0, 0, 0,
9, 0, 0, 0,
0,
1,
];
assert_eq!(
RevocationSection::parse(&data),
Err(RevocationSectionError::MissingLatestNull),
);
}