Skip to content

Commit

Permalink
add update_aad
Browse files Browse the repository at this point in the history
  • Loading branch information
rok committed Dec 17, 2024
1 parent bb6d3e8 commit cf4c54d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 12 additions & 1 deletion parquet/src/encryption/ciphers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const RIGHT_TWELVE: u128 = 0x0000_0000_ffff_ffff_ffff_ffff_ffff_ffff;
const NONCE_LEN: usize = 12;
const TAG_LEN: usize = 16;
const SIZE_LEN: usize = 4;
const NON_PAGE_ORDINAL: i32 = -1;

struct CounterNonce {
start: u128,
Expand Down Expand Up @@ -152,10 +153,12 @@ impl BlockDecryptor for RingGcmBlockDecryptor {
.open_in_place(nonce, Aad::from(aad), &mut result)
.unwrap();

result.resize(result.len() - TAG_LEN, 0u8);
result
}
}

#[derive(PartialEq)]
pub(crate) enum ModuleType {
Footer = 0,
ColumnMetaData = 1,
Expand All @@ -170,7 +173,7 @@ pub(crate) enum ModuleType {
}

pub fn create_footer_aad(file_aad: &[u8]) -> Result<Vec<u8>> {
create_module_aad(file_aad, ModuleType::Footer, -1, -1, -1)
create_module_aad(file_aad, ModuleType::Footer, -1, -1, NON_PAGE_ORDINAL)
}

pub fn create_page_aad(file_aad: &[u8], module_type: ModuleType, row_group_ordinal: i16, column_ordinal: i16, page_ordinal: i32) -> Result<Vec<u8>> {
Expand Down Expand Up @@ -314,6 +317,14 @@ impl FileDecryptor {
pub(crate) fn aad_prefix(&self) -> &Vec<u8> {
&self.aad_prefix
}

pub fn update_aad(&mut self, aad: Vec<u8>, row_group_ordinal: i16, column_ordinal: i16, module_type: ModuleType) {
// todo decr: update aad
debug_assert!(!self.aad_file_unique().is_empty(), "AAD is empty");

let aad = create_module_aad(self.aad_file_unique(), module_type, row_group_ordinal, column_ordinal, NON_PAGE_ORDINAL).unwrap();
self.aad_file_unique = aad;
}
}

#[derive(Debug, Clone)]
Expand Down
3 changes: 1 addition & 2 deletions parquet/src/file/serialized_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ pub(crate) fn decode_page(
can_decompress = header_v2.is_compressed.unwrap_or(true);
}

let buffer = if crypto_context.is_some() {
let buffer : Bytes = if crypto_context.is_some() {
let crypto_context = crypto_context.as_ref().unwrap();
let decryptor = crypto_context.data_decryptor();
let file_decryptor = decryptor.footer_decryptor();
Expand Down Expand Up @@ -463,7 +463,6 @@ pub(crate) fn decode_page(
&mut decompressed,
Some(uncompressed_size - offset),
)?;
todo!("page decompressed!");

if decompressed.len() != uncompressed_size {
return Err(general_err!(
Expand Down

0 comments on commit cf4c54d

Please sign in to comment.