diff --git a/src/backup/data_blob.rs b/src/backup/data_blob.rs index df2408f3..23c73c6b 100644 --- a/src/backup/data_blob.rs +++ b/src/backup/data_blob.rs @@ -3,10 +3,10 @@ use std::convert::TryInto; use proxmox::tools::io::{ReadExt, WriteExt}; -const MAX_BLOB_SIZE: usize = 128*1024*1024; - use super::file_formats::*; -use super::CryptConfig; +use super::{CryptConfig, CryptMode}; + +const MAX_BLOB_SIZE: usize = 128*1024*1024; /// Encoded data chunk with digest and positional information pub struct ChunkInfo { @@ -166,6 +166,21 @@ impl DataBlob { Ok(blob) } + /// Get the encryption mode for this blob. + pub fn crypt_mode(&self) -> Result { + let magic = self.magic(); + + Ok(if magic == &UNCOMPRESSED_BLOB_MAGIC_1_0 || magic == &COMPRESSED_BLOB_MAGIC_1_0 { + CryptMode::None + } else if magic == &ENCR_COMPR_BLOB_MAGIC_1_0 || magic == &ENCRYPTED_BLOB_MAGIC_1_0 { + CryptMode::Encrypt + } else if magic == &AUTH_COMPR_BLOB_MAGIC_1_0 || magic == &AUTHENTICATED_BLOB_MAGIC_1_0 { + CryptMode::SignOnly + } else { + bail!("Invalid blob magic number."); + }) + } + /// Decode blob data pub fn decode(&self, config: Option<&CryptConfig>) -> Result, Error> {