src/backup/file_formats.rs: moved header_size
This commit is contained in:
parent
41d08aa6de
commit
c638542b4b
|
@ -7,6 +7,7 @@ const MAX_BLOB_SIZE: usize = 128*1024*1024;
|
|||
|
||||
use super::*;
|
||||
|
||||
|
||||
/// Data blob binary storage format
|
||||
///
|
||||
/// Data blobs store arbitrary binary data (< 128MB), and can be
|
||||
|
@ -20,23 +21,6 @@ pub struct DataBlob {
|
|||
|
||||
impl DataBlob {
|
||||
|
||||
pub fn header_size(magic: &[u8; 8]) -> usize {
|
||||
match magic {
|
||||
&UNCOMPRESSED_CHUNK_MAGIC_1_0 => std::mem::size_of::<DataChunkHeader>(),
|
||||
&COMPRESSED_CHUNK_MAGIC_1_0 => std::mem::size_of::<DataChunkHeader>(),
|
||||
&ENCRYPTED_CHUNK_MAGIC_1_0 => std::mem::size_of::<EncryptedDataChunkHeader>(),
|
||||
&ENCR_COMPR_CHUNK_MAGIC_1_0 => std::mem::size_of::<EncryptedDataChunkHeader>(),
|
||||
|
||||
&UNCOMPRESSED_BLOB_MAGIC_1_0 => std::mem::size_of::<DataBlobHeader>(),
|
||||
&COMPRESSED_BLOB_MAGIC_1_0 => std::mem::size_of::<DataBlobHeader>(),
|
||||
&ENCRYPTED_BLOB_MAGIC_1_0 => std::mem::size_of::<EncryptedDataBlobHeader>(),
|
||||
&ENCR_COMPR_BLOB_MAGIC_1_0 => std::mem::size_of::<EncryptedDataBlobHeader>(),
|
||||
&AUTHENTICATED_BLOB_MAGIC_1_0 => std::mem::size_of::<AuthenticatedDataBlobHeader>(),
|
||||
&AUTH_COMPR_BLOB_MAGIC_1_0 => std::mem::size_of::<AuthenticatedDataBlobHeader>(),
|
||||
_ => panic!("unknown blob magic"),
|
||||
}
|
||||
}
|
||||
|
||||
/// accessor to raw_data field
|
||||
pub fn raw_data(&self) -> &[u8] {
|
||||
&self.raw_data
|
||||
|
@ -67,7 +51,7 @@ impl DataBlob {
|
|||
/// compute the CRC32 checksum
|
||||
pub fn compute_crc(&self) -> u32 {
|
||||
let mut hasher = crc32fast::Hasher::new();
|
||||
let start = Self::header_size(self.magic()); // start after HEAD
|
||||
let start = header_size(self.magic()); // start after HEAD
|
||||
hasher.update(&self.raw_data[start..]);
|
||||
hasher.finalize()
|
||||
}
|
||||
|
|
|
@ -119,3 +119,23 @@ pub struct EncryptedDataChunkHeader {
|
|||
pub iv: [u8; 16],
|
||||
pub tag: [u8; 16],
|
||||
}
|
||||
|
||||
/// Header size for different file types
|
||||
///
|
||||
/// Panics on unknown magic numbers.
|
||||
pub fn header_size(magic: &[u8; 8]) -> usize {
|
||||
match magic {
|
||||
&UNCOMPRESSED_CHUNK_MAGIC_1_0 => std::mem::size_of::<DataChunkHeader>(),
|
||||
&COMPRESSED_CHUNK_MAGIC_1_0 => std::mem::size_of::<DataChunkHeader>(),
|
||||
&ENCRYPTED_CHUNK_MAGIC_1_0 => std::mem::size_of::<EncryptedDataChunkHeader>(),
|
||||
&ENCR_COMPR_CHUNK_MAGIC_1_0 => std::mem::size_of::<EncryptedDataChunkHeader>(),
|
||||
|
||||
&UNCOMPRESSED_BLOB_MAGIC_1_0 => std::mem::size_of::<DataBlobHeader>(),
|
||||
&COMPRESSED_BLOB_MAGIC_1_0 => std::mem::size_of::<DataBlobHeader>(),
|
||||
&ENCRYPTED_BLOB_MAGIC_1_0 => std::mem::size_of::<EncryptedDataBlobHeader>(),
|
||||
&ENCR_COMPR_BLOB_MAGIC_1_0 => std::mem::size_of::<EncryptedDataBlobHeader>(),
|
||||
&AUTHENTICATED_BLOB_MAGIC_1_0 => std::mem::size_of::<AuthenticatedDataBlobHeader>(),
|
||||
&AUTH_COMPR_BLOB_MAGIC_1_0 => std::mem::size_of::<AuthenticatedDataBlobHeader>(),
|
||||
_ => panic!("unknown blob magic"),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue