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


##########
parquet/src/encryption/encrypt.rs:
##########
@@ -0,0 +1,283 @@
+// 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::{BlockEncryptor, RingGcmBlockEncryptor};
+use crate::errors::{ParquetError, Result};
+use crate::file::column_crypto_metadata::{ColumnCryptoMetaData, 
EncryptionWithColumnKey};
+use crate::schema::types::{ColumnDescPtr, SchemaDescriptor};
+use crate::thrift::TSerializable;
+use ring::rand::{SecureRandom, SystemRandom};
+use std::collections::{HashMap, HashSet};
+use std::io::Write;
+use thrift::protocol::TCompactOutputProtocol;
+
+#[derive(Debug, Clone, PartialEq)]
+pub struct EncryptionKey {
+    key: Vec<u8>,
+    key_metadata: Option<Vec<u8>>,
+}
+
+impl EncryptionKey {
+    pub fn new(key: Vec<u8>) -> EncryptionKey {
+        Self {
+            key,
+            key_metadata: None,
+        }
+    }
+
+    pub fn with_metadata(mut self, metadata: Vec<u8>) -> Self {
+        self.key_metadata = Some(metadata);
+        self
+    }
+
+    pub fn key(&self) -> &Vec<u8> {
+        &self.key
+    }
+}
+
+#[derive(Debug, Clone, PartialEq)]
+pub struct FileEncryptionProperties {
+    encrypt_footer: bool,
+    footer_key: EncryptionKey,
+    column_keys: HashMap<String, EncryptionKey>,
+    aad_prefix: Option<Vec<u8>>,
+    store_aad_prefix: bool,
+}
+
+impl FileEncryptionProperties {
+    pub fn builder(footer_key: Vec<u8>) -> EncryptionPropertiesBuilder {
+        EncryptionPropertiesBuilder::new(footer_key)
+    }
+
+    pub fn encrypt_footer(&self) -> bool {
+        self.encrypt_footer
+    }
+
+    pub fn footer_key_metadata(&self) -> Option<&Vec<u8>> {
+        self.footer_key.key_metadata.as_ref()
+    }
+
+    pub fn aad_prefix(&self) -> Option<&Vec<u8>> {
+        self.aad_prefix.as_ref()
+    }
+
+    pub fn store_aad_prefix(&self) -> bool {
+        self.store_aad_prefix && self.aad_prefix.is_some()
+    }
+
+    /// Checks if columns that are to be encrypted are present in schema
+    #[cfg(feature = "encryption")]
+    pub(crate) fn encrypted_columns_in_schema(

Review Comment:
   Done.



##########
parquet/src/file/writer.rs:
##########
@@ -171,19 +183,37 @@ impl<W: Write + Send> SerializedFileWriter<W> {
     /// Creates new file writer.
     pub fn new(buf: W, schema: TypePtr, properties: WriterPropertiesPtr) -> 
Result<Self> {
         let mut buf = TrackedWrite::new(buf);
-        Self::start_file(&mut buf)?;
+
+        #[cfg(feature = "encryption")]
+        let file_encryptor = match 
properties.file_encryption_properties.as_ref() {
+            None => None,
+            Some(encryption_props) => 
Some(Arc::new(FileEncryptor::new(encryption_props.clone())?)),
+        };
+
+        #[cfg(feature = "encryption")]
+        if properties.file_encryption_properties.is_some() {
+            properties
+                .file_encryption_properties
+                .clone()
+                .unwrap()
+                
.encrypted_columns_in_schema(SchemaDescriptor::new(schema.clone()))?;
+        }
+
+        Self::start_file(&properties, &mut buf)?;
         Ok(Self {
             buf,
             schema: schema.clone(),
             descr: Arc::new(SchemaDescriptor::new(schema)),
-            props: properties,
+            props: properties.clone(),

Review Comment:
   Removed.



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