rok commented on code in PR #6637:
URL: https://github.com/apache/arrow-rs/pull/6637#discussion_r1985962151


##########
parquet/src/arrow/async_reader/mod.rs:
##########
@@ -2336,4 +2451,241 @@ mod tests {
         let result = reader.try_collect::<Vec<_>>().await.unwrap();
         assert_eq!(result.len(), 1);
     }
+
+    #[cfg(feature = "encryption")]
+    async fn verify_encryption_test_file_read(
+        file: &mut File,
+        decryption_properties: FileDecryptionProperties,
+    ) {
+        let options =
+            
ArrowReaderOptions::new().with_file_decryption_properties(decryption_properties);
+
+        let metadata = ArrowReaderMetadata::load_async(file, options.clone())
+            .await
+            .unwrap();
+        let arrow_reader_metadata = ArrowReaderMetadata::load_async(file, 
options)
+            .await
+            .unwrap();
+        let file_metadata = metadata.metadata.file_metadata();
+
+        let record_reader = ParquetRecordBatchStreamBuilder::new_with_metadata(
+            file.try_clone().await.unwrap(),
+            arrow_reader_metadata.clone(),
+        )
+        .build()
+        .unwrap();
+        let record_batches = 
record_reader.try_collect::<Vec<_>>().await.unwrap();
+
+        assert_eq!(file_metadata.num_rows(), 50);
+        assert_eq!(file_metadata.schema_descr().num_columns(), 8);
+        assert_eq!(
+            file_metadata.created_by().unwrap(),
+            "parquet-cpp-arrow version 19.0.0-SNAPSHOT"
+        );
+
+        metadata.metadata.row_groups().iter().for_each(|rg| {
+            assert_eq!(rg.num_columns(), 8);
+            assert_eq!(rg.num_rows(), 50);
+        });
+
+        let mut row_count = 0;

Review Comment:
   Refactored out into `encryption_util.rs`.



##########
parquet/src/encryption/decryption.rs:
##########
@@ -0,0 +1,254 @@
+// 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 {

Review Comment:
   Added.



-- 
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

Reply via email to