diff --git a/src/backup/data_blob.rs b/src/backup/data_blob.rs index 8c37ba36..8f56dce4 100644 --- a/src/backup/data_blob.rs +++ b/src/backup/data_blob.rs @@ -157,4 +157,33 @@ impl DataBlob { bail!("Invalid blob magic number."); } } + + /// Create Instance from raw data + pub fn from_raw(data: Vec) -> Result { + + if data.len() < std::mem::size_of::() { + bail!("blob too small ({} bytes).", data.len()); + } + + let magic = &data[0..8]; + + if magic == ENCR_COMPR_BLOB_MAGIC_1_0 || magic == ENCRYPTED_BLOB_MAGIC_1_0 { + + if data.len() < std::mem::size_of::() { + bail!("encrypted blob too small ({} bytes).", data.len()); + } + + let blob = DataBlob { raw_data: data }; + + Ok(blob) + } else if magic == COMPRESSED_BLOB_MAGIC_1_0 || magic == UNCOMPRESSED_BLOB_MAGIC_1_0 { + + let blob = DataBlob { raw_data: data }; + + Ok(blob) + } else { + bail!("unable to parse raw blob - wrong magic"); + } + } + }