diff --git a/parquet/src/encryption/encrypt.rs b/parquet/src/encryption/encrypt.rs index f6ae9004f164..d69e3c02500a 100644 --- a/parquet/src/encryption/encrypt.rs +++ b/parquet/src/encryption/encrypt.rs @@ -275,14 +275,14 @@ impl EncryptionPropertiesBuilder { } /// Build the encryption properties - pub fn build(self) -> Result { - Ok(FileEncryptionProperties { + pub fn build(self) -> Result> { + Ok(Arc::new(FileEncryptionProperties { encrypt_footer: self.encrypt_footer, footer_key: self.footer_key, column_keys: self.column_keys, aad_prefix: self.aad_prefix, store_aad_prefix: self.store_aad_prefix, - }) + })) } } @@ -314,7 +314,7 @@ impl FileEncryptor { } /// Get the encryptor's file encryption properties - pub fn properties(&self) -> &FileEncryptionProperties { + pub fn properties(&self) -> &Arc { &self.properties } @@ -416,7 +416,7 @@ pub(crate) fn encrypt_thrift_object_to_vec( /// Get the crypto metadata for a column from the file encryption properties pub(crate) fn get_column_crypto_metadata( - properties: &FileEncryptionProperties, + properties: &Arc, column: &ColumnDescPtr, ) -> Option { if properties.column_keys.is_empty() { diff --git a/parquet/src/file/properties.rs b/parquet/src/file/properties.rs index d7771b42e24a..38a5a804c0b7 100644 --- a/parquet/src/file/properties.rs +++ b/parquet/src/file/properties.rs @@ -458,7 +458,7 @@ pub struct WriterPropertiesBuilder { statistics_truncate_length: Option, coerce_types: bool, #[cfg(feature = "encryption")] - file_encryption_properties: Option, + file_encryption_properties: Option>, } impl Default for WriterPropertiesBuilder { @@ -506,7 +506,7 @@ impl WriterPropertiesBuilder { statistics_truncate_length: self.statistics_truncate_length, coerce_types: self.coerce_types, #[cfg(feature = "encryption")] - file_encryption_properties: self.file_encryption_properties.map(Arc::new), + file_encryption_properties: self.file_encryption_properties, } } @@ -709,7 +709,7 @@ impl WriterPropertiesBuilder { #[cfg(feature = "encryption")] pub fn with_file_encryption_properties( mut self, - file_encryption_properties: FileEncryptionProperties, + file_encryption_properties: Arc, ) -> Self { self.file_encryption_properties = Some(file_encryption_properties); self @@ -965,7 +965,7 @@ impl From for WriterPropertiesBuilder { statistics_truncate_length: props.statistics_truncate_length, coerce_types: props.coerce_types, #[cfg(feature = "encryption")] - file_encryption_properties: props.file_encryption_properties.map(Arc::unwrap_or_clone), + file_encryption_properties: props.file_encryption_properties, } } } diff --git a/parquet/src/file/writer.rs b/parquet/src/file/writer.rs index f85ca67412ac..b5a0ef4e5523 100644 --- a/parquet/src/file/writer.rs +++ b/parquet/src/file/writer.rs @@ -318,7 +318,7 @@ impl SerializedFileWriter { /// Writes magic bytes at the beginning of the file. #[cfg(feature = "encryption")] fn start_file(properties: &WriterPropertiesPtr, buf: &mut TrackedWrite) -> Result<()> { - let magic = get_file_magic(properties.file_encryption_properties.as_deref()); + let magic = get_file_magic(properties.file_encryption_properties.as_ref()); buf.write_all(magic)?; Ok(()) @@ -1020,7 +1020,7 @@ impl PageWriter for SerializedPageWriter<'_, W> { /// as a Parquet file. #[cfg(feature = "encryption")] pub(crate) fn get_file_magic( - file_encryption_properties: Option<&FileEncryptionProperties>, + file_encryption_properties: Option<&Arc>, ) -> &'static [u8; 4] { match file_encryption_properties.as_ref() { Some(encryption_properties) if encryption_properties.encrypt_footer() => { diff --git a/parquet/tests/encryption/encryption_async.rs b/parquet/tests/encryption/encryption_async.rs index bd8877559405..51acd7374879 100644 --- a/parquet/tests/encryption/encryption_async.rs +++ b/parquet/tests/encryption/encryption_async.rs @@ -471,7 +471,7 @@ async fn verify_encryption_test_file_read_async( async fn read_and_roundtrip_to_encrypted_file_async( path: &str, decryption_properties: Arc, - encryption_properties: FileEncryptionProperties, + encryption_properties: Arc, ) -> Result<(), ParquetError> { let temp_file = tempfile::tempfile().unwrap(); let mut file = File::open(&path).await.unwrap(); diff --git a/parquet/tests/encryption/encryption_util.rs b/parquet/tests/encryption/encryption_util.rs index 345078d28d93..7f4cc5a9da45 100644 --- a/parquet/tests/encryption/encryption_util.rs +++ b/parquet/tests/encryption/encryption_util.rs @@ -235,7 +235,7 @@ pub(crate) fn read_encrypted_file( pub(crate) fn read_and_roundtrip_to_encrypted_file( file: &File, decryption_properties: Arc, - encryption_properties: FileEncryptionProperties, + encryption_properties: Arc, ) { // read example data let (batches, metadata) =