Skip to content

Commit

Permalink
fixed calculation of encrypted object footer length
Browse files Browse the repository at this point in the history
  • Loading branch information
ph0llux committed Oct 14, 2023
1 parent 8a36a5e commit 0e8d86b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
22 changes: 16 additions & 6 deletions src/lib/footer/object_footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,23 @@ impl ObjectFooterPhysical {
E: Borrow<EncryptionInformation>
{
let mut vec = Vec::new();
let mut encrypted_content = Encryption::encrypt_object_footer(
let encrypted_content = Encryption::encrypt_object_footer(
&encryption_information.borrow().encryption_key,
self.encode_content(),
self.object_number,
&encryption_information.borrow().algorithm)?;
let identifier = Self::identifier();
let encoded_header_length = (DEFAULT_LENGTH_HEADER_IDENTIFIER + DEFAULT_LENGTH_VALUE_HEADER_LENGTH + encrypted_content.len()) as u64; //4 bytes identifier + 8 bytes for length + length itself
let encoded_header_length = (
DEFAULT_LENGTH_HEADER_IDENTIFIER +
DEFAULT_LENGTH_VALUE_HEADER_LENGTH +
self.version.encode_directly().len() +
self.object_number.encode_directly().len() +
encrypted_content.encode_directly().len()) as u64; //4 bytes identifier + 8 bytes for length + length itself
vec.append(&mut identifier.to_be_bytes().to_vec());
vec.append(&mut encoded_header_length.encode_directly());
vec.append(&mut self.version.encode_directly());
vec.append(&mut self.object_number.encode_directly());
vec.append(&mut encrypted_content);
vec.append(&mut encrypted_content.encode_directly());

Ok(vec)
}
Expand Down Expand Up @@ -703,18 +708,23 @@ impl ObjectFooterLogical {
E: Borrow<EncryptionInformation>
{
let mut vec = Vec::new();
let mut encrypted_content = Encryption::encrypt_object_footer(
let encrypted_content = Encryption::encrypt_object_footer(
&encryption_information.borrow().encryption_key,
self.encode_content(),
self.object_number,
&encryption_information.borrow().algorithm)?;
let identifier = Self::identifier();
let encoded_header_length = (DEFAULT_LENGTH_HEADER_IDENTIFIER + DEFAULT_LENGTH_VALUE_HEADER_LENGTH + encrypted_content.len()) as u64; //4 bytes identifier + 8 bytes for length + length itself
let encoded_header_length = (
DEFAULT_LENGTH_HEADER_IDENTIFIER +
DEFAULT_LENGTH_VALUE_HEADER_LENGTH +
self.version.encode_directly().len() +
self.object_number.encode_directly().len() +
encrypted_content.encode_directly().len()) as u64; //4 bytes identifier + 8 bytes for length + length itself
vec.append(&mut identifier.to_be_bytes().to_vec());
vec.append(&mut encoded_header_length.encode_directly());
vec.append(&mut self.version.encode_directly());
vec.append(&mut self.object_number.encode_directly());
vec.append(&mut encrypted_content);
vec.append(&mut encrypted_content.encode_directly());

Ok(vec)
}
Expand Down
4 changes: 0 additions & 4 deletions src/lib/io/zffreader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,18 +1065,14 @@ fn initialize_encrypted_object_reader<R: Read + Seek>(
segments: &mut HashMap<u64, Segment<R>>,
) -> Result<ZffObjectReader> {



let header = match segments.get_mut(&header_segment_no) {
None => return Err(ZffError::new(ZffErrorKind::MissingSegment, header_segment_no.to_string())),
Some(segment) => segment.read_encrypted_object_header(obj_number)?,
};

let footer = match segments.get_mut(&footer_segment_no) {
None => return Err(ZffError::new(ZffErrorKind::MissingSegment, header_segment_no.to_string())),
Some(segment) => segment.read_encrypted_object_footer(obj_number)?,
};

let obj_reader = ZffObjectReader::Encrypted(Box::new(ZffObjectReaderEncrypted::with_data(header, footer)));
Ok(obj_reader)
}
Expand Down

0 comments on commit 0e8d86b

Please sign in to comment.