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)
})
.and_then(move |data| {
let mut blob = DataBlob::from_raw(data)?;
// always comput CRC at server side
blob.set_crc(blob.compute_crc());
let blob = DataBlob::from_raw(data)?;
// always verify CRC at server side
blob.verify_crc()?;
let raw_data = blob.raw_data();
file_set_contents(&path, raw_data, None)?;
Ok(())

View File

@ -73,7 +73,7 @@ impl DataBlob {
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 (_compress, data, magic) = if compress {
@ -110,7 +110,7 @@ impl DataBlob {
(&mut raw_data[0..header_len]).write_le_value(head)?;
}
return Ok(DataBlob { raw_data });
DataBlob { raw_data }
} else {
let max_data_len = data.len() + std::mem::size_of::<DataBlobHeader>();
@ -143,8 +143,12 @@ impl DataBlob {
}
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
@ -238,7 +242,10 @@ impl DataBlob {
}
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