adamreeve commented on code in PR #6637: URL: https://github.com/apache/arrow-rs/pull/6637#discussion_r1949910440
########## parquet/src/arrow/arrow_reader/mod.rs: ########## @@ -379,10 +397,17 @@ impl ArrowReaderMetadata { /// If `options` has [`ArrowReaderOptions::with_page_index`] true, but /// `Self::metadata` is missing the page index, this function will attempt /// to load the page index by making an object store request. + /// + /// If encryption is enabled and the file is encrypted, the + /// `file_decryption_properties` must be provided. Review Comment: This comment is no longer relevant here ########## parquet/src/encryption/decryption.rs: ########## @@ -0,0 +1,234 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use crate::encryption::ciphers::{BlockDecryptor, RingGcmBlockDecryptor}; +use crate::encryption::modules::{create_module_aad, ModuleType}; +use crate::errors::Result; +use std::collections::HashMap; +use std::io::Read; +use std::sync::Arc; + +pub fn read_and_decrypt<T: Read>( + decryptor: &Arc<dyn BlockDecryptor>, + input: &mut T, + aad: &[u8], +) -> Result<Vec<u8>> { + let mut len_bytes = [0; 4]; + input.read_exact(&mut len_bytes)?; + let ciphertext_len = u32::from_le_bytes(len_bytes) as usize; + let mut ciphertext = vec![0; 4 + ciphertext_len]; + input.read_exact(&mut ciphertext[4..])?; + + decryptor.decrypt(&ciphertext, aad.as_ref()) +} + +#[derive(Debug, Clone)] +pub struct CryptoContext { + pub(crate) row_group_ordinal: usize, + pub(crate) column_ordinal: usize, + pub(crate) page_ordinal: Option<usize>, + pub(crate) dictionary_page: bool, + // We have separate data and metadata decryptors because + // in GCM CTR mode, the metadata and data pages use + // different algorithms. + data_decryptor: Arc<dyn BlockDecryptor>, + metadata_decryptor: Arc<dyn BlockDecryptor>, + file_aad: Vec<u8>, +} + +impl CryptoContext { + pub fn new( + row_group_ordinal: usize, + column_ordinal: usize, + data_decryptor: Arc<dyn BlockDecryptor>, + metadata_decryptor: Arc<dyn BlockDecryptor>, + file_aad: Vec<u8>, + ) -> Self { + Self { + row_group_ordinal, + column_ordinal, + page_ordinal: None, + dictionary_page: false, + data_decryptor, + metadata_decryptor, + file_aad, + } + } + + pub fn with_page_ordinal(&self, page_ordinal: usize) -> Self { + Self { + row_group_ordinal: self.row_group_ordinal, + column_ordinal: self.column_ordinal, + page_ordinal: Some(page_ordinal), + dictionary_page: false, + data_decryptor: self.data_decryptor.clone(), + metadata_decryptor: self.metadata_decryptor.clone(), + file_aad: self.file_aad.clone(), + } + } + + pub(crate) fn create_page_aad( + &self, + module_type: ModuleType, + ) -> crate::errors::Result<Vec<u8>> { + create_module_aad( + self.file_aad(), + module_type, Review Comment: Can we infer the module type from `self.dictionary_page` instead of passing it in here? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org