5
0
mirror of git://git.proxmox.com/git/pxar.git synced 2025-01-03 09:17:38 +03:00

format: add helper for payload header consistency checks

The helper method will be used to check the payload header being
consistent with what was encoded as paylaod reference for split
pxar archives.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
This commit is contained in:
Christian Ebner 2024-06-12 10:23:56 +02:00 committed by Fabian Grünbichler
parent d121b920de
commit e67489f059

View File

@ -823,3 +823,24 @@ pub fn check_file_name(path: &Path) -> io::Result<()> {
Ok(())
}
}
/// Check if provided header is of type payload and the headers content size matches given size.
///
/// Returns an [`io::Error`](std::io::Error) of type [`Other`](std::io::ErrorKind::Other) if that's
/// not the case.
pub(crate) fn check_payload_header_and_size(header: &Header, size: u64) -> io::Result<()> {
header.check_header_size()?;
if header.htype != PXAR_PAYLOAD {
io_bail!("unexpected header: expected {PXAR_PAYLOAD:x?} , got {header:x?}");
}
if header.content_size() != size {
io_bail!(
"encountered size mismatch: expected {}, got {size}",
header.content_size()
);
}
Ok(())
}