src/backup/data_{chunk,blob}.rs: add verify_crc method

This commit is contained in:
Dietmar Maurer
2019-06-26 09:54:25 +02:00
parent fef44d4f78
commit b208da8393
3 changed files with 19 additions and 0 deletions

View File

@ -54,6 +54,15 @@ impl DataBlob {
hasher.finalize()
}
/// verify the CRC32 checksum
pub fn verify_crc(&self) -> Result<(), Error> {
let expected_crc = self.compute_crc();
if expected_crc != self.crc() {
bail!("Data blob has wrong CRC checksum.");
}
Ok(())
}
pub fn encode(
data: &[u8],
config: Option<&CryptConfig>,

View File

@ -61,6 +61,15 @@ impl DataChunk {
hasher.finalize()
}
/// verify the CRC32 checksum
pub fn verify_crc(&self) -> Result<(), Error> {
let expected_crc = self.compute_crc();
if expected_crc != self.crc() {
bail!("Data chunk has wrong CRC checksum.");
}
Ok(())
}
fn encode(
data: &[u8],
config: Option<&CryptConfig>,