try to use use proxmox::tools::io::ops::ReadExtOps

This commit is contained in:
Dietmar Maurer 2019-06-22 16:29:10 +02:00
parent 27042ce637
commit ba01828d38
3 changed files with 14 additions and 4 deletions

View File

@ -1,7 +1,7 @@
use failure::*;
use std::convert::TryInto;
use crate::tools::read::ReadUtilOps;
use proxmox::tools::io::ops::ReadExtOps;
use crate::tools::write::WriteUtilOps;
use super::*;
@ -139,7 +139,9 @@ impl DataBlob {
return Ok(data);
} else if magic == &ENCR_COMPR_BLOB_MAGIC_1_0 || magic == &ENCRYPTED_BLOB_MAGIC_1_0 {
let header_len = std::mem::size_of::<EncryptedDataBlobHeader>();
let head = (&self.raw_data[..header_len]).read_value::<EncryptedDataBlobHeader>()?;
let head = unsafe {
(&self.raw_data[..header_len]).read_le_value::<EncryptedDataBlobHeader>()?
};
if let Some(config) = config {
let data = if magic == &ENCR_COMPR_BLOB_MAGIC_1_0 {

View File

@ -1,6 +1,6 @@
use failure::*;
use std::convert::TryInto;
use crate::tools::read::ReadUtilOps;
use proxmox::tools::io::ops::ReadExtOps;
use crate::tools::write::WriteUtilOps;
use super::*;
@ -150,7 +150,9 @@ impl DataChunk {
return Ok(data);
} else if magic == &ENCR_COMPR_CHUNK_MAGIC_1_0 || magic == &ENCRYPTED_CHUNK_MAGIC_1_0 {
let header_len = std::mem::size_of::<EncryptedDataChunkHeader>();
let head = (&self.raw_data[..header_len]).read_value::<EncryptedDataChunkHeader>()?;
let head = unsafe {
(&self.raw_data[..header_len]).read_le_value::<EncryptedDataChunkHeader>()?
};
if let Some(config) = config {
let data = if magic == &ENCR_COMPR_CHUNK_MAGIC_1_0 {

View File

@ -1,3 +1,5 @@
use endian_trait::Endian;
// WARNING: PLEASE DO NOT MODIFY THOSE MAGIC VALUES
// openssl::sha::sha256(b"Proxmox Backup uncompressed chunk v1.0")[0..8]
@ -44,6 +46,7 @@ pub static DYNAMIC_SIZED_CHUNK_INDEX_1_0: [u8; 8] = [28, 145, 78, 165, 25, 186,
///
/// This is basically the same format we use for chunks, but
/// with other magic numbers so that we can distinguish them.
#[derive(Endian)]
#[repr(C,packed)]
pub struct DataBlobHeader {
pub magic: [u8; 8],
@ -57,6 +60,7 @@ pub struct DataBlobHeader {
/// tag, followed by the encrypted data:
///
/// (MAGIC || CRC32 || IV || TAG || EncryptedData).
#[derive(Endian)]
#[repr(C,packed)]
pub struct EncryptedDataBlobHeader {
pub head: DataBlobHeader,
@ -75,6 +79,7 @@ pub struct EncryptedDataBlobHeader {
/// (compressed) data.
///
/// (MAGIC || CRC32 || Data)
#[derive(Endian)]
#[repr(C,packed)]
pub struct DataChunkHeader {
pub magic: [u8; 8],
@ -88,6 +93,7 @@ pub struct DataChunkHeader {
/// tag, followed by the encrypted data:
///
/// (MAGIC || CRC32 || IV || TAG || EncryptedData).
#[derive(Endian)]
#[repr(C,packed)]
pub struct EncryptedDataChunkHeader {
pub head: DataChunkHeader,