|
16 | 16 | // under the License. |
17 | 17 |
|
18 | 18 | #[cfg(feature = "encryption")] |
19 | | -use crate::encryption::encrypt::{encrypt_object, encrypt_object_to_vec, FileEncryptor}; |
20 | | -#[cfg(feature = "encryption")] |
21 | | -use crate::encryption::modules::{create_footer_aad, create_module_aad, ModuleType}; |
| 19 | +use crate::encryption::{ |
| 20 | + encrypt::{ |
| 21 | + encrypt_object, encrypt_object_to_vec, write_signed_plaintext_object, FileEncryptor, |
| 22 | + }, |
| 23 | + modules::{create_footer_aad, create_module_aad, ModuleType}, |
| 24 | +}; |
22 | 25 | #[cfg(feature = "encryption")] |
23 | 26 | use crate::errors::ParquetError; |
24 | 27 | use crate::errors::Result; |
25 | 28 | use crate::file::metadata::{KeyValue, ParquetMetaData}; |
26 | 29 | use crate::file::page_index::index::Index; |
27 | 30 | use crate::file::writer::{get_file_magic, TrackedWrite}; |
| 31 | +use crate::format::EncryptionAlgorithm; |
28 | 32 | #[cfg(feature = "encryption")] |
29 | | -use crate::format::{AesGcmV1, ColumnCryptoMetaData, EncryptionAlgorithm}; |
| 33 | +use crate::format::{AesGcmV1, ColumnCryptoMetaData}; |
30 | 34 | use crate::format::{ColumnChunk, ColumnIndex, FileMetaData, OffsetIndex, RowGroup}; |
31 | 35 | use crate::schema::types; |
32 | 36 | use crate::schema::types::{SchemaDescPtr, SchemaDescriptor, TypePtr}; |
@@ -149,7 +153,7 @@ impl<'a, W: Write> ThriftMetadataWriter<'a, W> { |
149 | 153 | schema: types::to_thrift(self.schema.as_ref())?, |
150 | 154 | created_by: self.created_by.clone(), |
151 | 155 | column_orders, |
152 | | - encryption_algorithm: None, |
| 156 | + encryption_algorithm: self.object_writer.get_footer_encryption_algorithm(), |
153 | 157 | footer_signing_key_metadata: None, |
154 | 158 | }; |
155 | 159 |
|
@@ -474,6 +478,10 @@ impl MetadataObjectWriter { |
474 | 478 | pub fn get_file_magic(&self) -> &[u8; 4] { |
475 | 479 | get_file_magic() |
476 | 480 | } |
| 481 | + |
| 482 | + fn get_footer_encryption_algorithm(&self) -> Option<EncryptionAlgorithm> { |
| 483 | + None |
| 484 | + } |
477 | 485 | } |
478 | 486 |
|
479 | 487 | /// Implementations of [`MetadataObjectWriter`] methods that rely on encryption being enabled |
@@ -503,6 +511,11 @@ impl MetadataObjectWriter { |
503 | 511 | let mut encryptor = file_encryptor.get_footer_encryptor()?; |
504 | 512 | encrypt_object(file_metadata, &mut encryptor, &mut sink, &aad) |
505 | 513 | } |
| 514 | + Some(file_encryptor) if file_metadata.encryption_algorithm.is_some() => { |
| 515 | + let aad = create_footer_aad(file_encryptor.file_aad())?; |
| 516 | + let mut encryptor = file_encryptor.get_footer_encryptor()?; |
| 517 | + write_signed_plaintext_object(file_metadata, &mut encryptor, &mut sink, &aad) |
| 518 | + } |
506 | 519 | _ => Self::write_object(file_metadata, &mut sink), |
507 | 520 | } |
508 | 521 | } |
@@ -622,25 +635,36 @@ impl MetadataObjectWriter { |
622 | 635 | } |
623 | 636 | } |
624 | 637 |
|
625 | | - fn file_crypto_metadata( |
626 | | - file_encryptor: &FileEncryptor, |
627 | | - ) -> Result<crate::format::FileCryptoMetaData> { |
628 | | - let properties = file_encryptor.properties(); |
629 | | - let supply_aad_prefix = properties |
| 638 | + fn get_footer_encryption_algorithm(&self) -> Option<EncryptionAlgorithm> { |
| 639 | + if let Some(file_encryptor) = &self.file_encryptor { |
| 640 | + return Some(Self::encryption_algorithm_from_encryptor(file_encryptor)); |
| 641 | + } |
| 642 | + None |
| 643 | + } |
| 644 | + |
| 645 | + fn encryption_algorithm_from_encryptor(file_encryptor: &FileEncryptor) -> EncryptionAlgorithm { |
| 646 | + let supply_aad_prefix = file_encryptor |
| 647 | + .properties() |
630 | 648 | .aad_prefix() |
631 | | - .map(|_| !properties.store_aad_prefix()); |
632 | | - let encryption_algorithm = AesGcmV1 { |
633 | | - aad_prefix: if properties.store_aad_prefix() { |
634 | | - properties.aad_prefix().cloned() |
635 | | - } else { |
636 | | - None |
637 | | - }, |
| 649 | + .map(|_| !file_encryptor.properties().store_aad_prefix()); |
| 650 | + let aad_prefix = if file_encryptor.properties().store_aad_prefix() { |
| 651 | + file_encryptor.properties().aad_prefix().cloned() |
| 652 | + } else { |
| 653 | + None |
| 654 | + }; |
| 655 | + EncryptionAlgorithm::AESGCMV1(AesGcmV1 { |
| 656 | + aad_prefix, |
638 | 657 | aad_file_unique: Some(file_encryptor.aad_file_unique().clone()), |
639 | 658 | supply_aad_prefix, |
640 | | - }; |
| 659 | + }) |
| 660 | + } |
641 | 661 |
|
| 662 | + fn file_crypto_metadata( |
| 663 | + file_encryptor: &FileEncryptor, |
| 664 | + ) -> Result<crate::format::FileCryptoMetaData> { |
| 665 | + let properties = file_encryptor.properties(); |
642 | 666 | Ok(crate::format::FileCryptoMetaData { |
643 | | - encryption_algorithm: EncryptionAlgorithm::AESGCMV1(encryption_algorithm), |
| 667 | + encryption_algorithm: Self::encryption_algorithm_from_encryptor(file_encryptor), |
644 | 668 | key_metadata: properties.footer_key_metadata().cloned(), |
645 | 669 | }) |
646 | 670 | } |
|
0 commit comments