src/backup/data_blob.rs: always compute crc

This commit is contained in:
Dietmar Maurer 2019-08-06 11:42:14 +02:00
parent c807d231eb
commit f889b15867
2 changed files with 15 additions and 8 deletions

View File

@ -539,9 +539,9 @@ fn upload_backup_log(
Ok::<_, Error>(acc) Ok::<_, Error>(acc)
}) })
.and_then(move |data| { .and_then(move |data| {
let mut blob = DataBlob::from_raw(data)?; let blob = DataBlob::from_raw(data)?;
// always comput CRC at server side // always verify CRC at server side
blob.set_crc(blob.compute_crc()); blob.verify_crc()?;
let raw_data = blob.raw_data(); let raw_data = blob.raw_data();
file_set_contents(&path, raw_data, None)?; file_set_contents(&path, raw_data, None)?;
Ok(()) Ok(())

View File

@ -73,7 +73,7 @@ impl DataBlob {
bail!("data blob too large ({} bytes).", data.len()); bail!("data blob too large ({} bytes).", data.len());
} }
if let Some(config) = config { let mut blob = if let Some(config) = config {
let compr_data; let compr_data;
let (_compress, data, magic) = if compress { let (_compress, data, magic) = if compress {
@ -110,7 +110,7 @@ impl DataBlob {
(&mut raw_data[0..header_len]).write_le_value(head)?; (&mut raw_data[0..header_len]).write_le_value(head)?;
} }
return Ok(DataBlob { raw_data }); DataBlob { raw_data }
} else { } else {
let max_data_len = data.len() + std::mem::size_of::<DataBlobHeader>(); let max_data_len = data.len() + std::mem::size_of::<DataBlobHeader>();
@ -143,8 +143,12 @@ impl DataBlob {
} }
raw_data.extend_from_slice(data); raw_data.extend_from_slice(data);
return Ok(DataBlob { raw_data }); DataBlob { raw_data }
} };
blob.set_crc(blob.compute_crc());
Ok(blob)
} }
/// Decode blob data /// Decode blob data
@ -238,7 +242,10 @@ impl DataBlob {
} }
raw_data.extend_from_slice(data); raw_data.extend_from_slice(data);
return Ok(DataBlob { raw_data }); let mut blob = DataBlob { raw_data };
blob.set_crc(blob.compute_crc());
return Ok(blob);
} }
/// Create Instance from raw data /// Create Instance from raw data