From c638542b4b4675389383b8e4806e3ca6ed84cfa5 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 14 Aug 2019 12:35:53 +0200 Subject: [PATCH] src/backup/file_formats.rs: moved header_size --- src/backup/data_blob.rs | 20 ++------------------ src/backup/file_formats.rs | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/backup/data_blob.rs b/src/backup/data_blob.rs index 215797a1..c2027c8a 100644 --- a/src/backup/data_blob.rs +++ b/src/backup/data_blob.rs @@ -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::(), - &COMPRESSED_CHUNK_MAGIC_1_0 => std::mem::size_of::(), - &ENCRYPTED_CHUNK_MAGIC_1_0 => std::mem::size_of::(), - &ENCR_COMPR_CHUNK_MAGIC_1_0 => std::mem::size_of::(), - - &UNCOMPRESSED_BLOB_MAGIC_1_0 => std::mem::size_of::(), - &COMPRESSED_BLOB_MAGIC_1_0 => std::mem::size_of::(), - &ENCRYPTED_BLOB_MAGIC_1_0 => std::mem::size_of::(), - &ENCR_COMPR_BLOB_MAGIC_1_0 => std::mem::size_of::(), - &AUTHENTICATED_BLOB_MAGIC_1_0 => std::mem::size_of::(), - &AUTH_COMPR_BLOB_MAGIC_1_0 => std::mem::size_of::(), - _ => 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() } diff --git a/src/backup/file_formats.rs b/src/backup/file_formats.rs index 2f32cc51..fedea26f 100644 --- a/src/backup/file_formats.rs +++ b/src/backup/file_formats.rs @@ -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::(), + &COMPRESSED_CHUNK_MAGIC_1_0 => std::mem::size_of::(), + &ENCRYPTED_CHUNK_MAGIC_1_0 => std::mem::size_of::(), + &ENCR_COMPR_CHUNK_MAGIC_1_0 => std::mem::size_of::(), + + &UNCOMPRESSED_BLOB_MAGIC_1_0 => std::mem::size_of::(), + &COMPRESSED_BLOB_MAGIC_1_0 => std::mem::size_of::(), + &ENCRYPTED_BLOB_MAGIC_1_0 => std::mem::size_of::(), + &ENCR_COMPR_BLOB_MAGIC_1_0 => std::mem::size_of::(), + &AUTHENTICATED_BLOB_MAGIC_1_0 => std::mem::size_of::(), + &AUTH_COMPR_BLOB_MAGIC_1_0 => std::mem::size_of::(), + _ => panic!("unknown blob magic"), + } +}