@@ -28,8 +28,9 @@ use crate::errors::Result;
28
28
use crate :: file:: metadata:: { KeyValue , ParquetMetaData } ;
29
29
use crate :: file:: page_index:: index:: Index ;
30
30
use crate :: file:: writer:: { get_file_magic, TrackedWrite } ;
31
+ use crate :: format:: EncryptionAlgorithm ;
31
32
#[ cfg( feature = "encryption" ) ]
32
- use crate :: format:: { AesGcmV1 , ColumnCryptoMetaData , EncryptionAlgorithm } ;
33
+ use crate :: format:: { AesGcmV1 , ColumnCryptoMetaData } ;
33
34
use crate :: format:: { ColumnChunk , ColumnIndex , FileMetaData , OffsetIndex , RowGroup } ;
34
35
use crate :: schema:: types;
35
36
use crate :: schema:: types:: { SchemaDescPtr , SchemaDescriptor , TypePtr } ;
@@ -144,15 +145,6 @@ impl<'a, W: Write> ThriftMetadataWriter<'a, W> {
144
145
. object_writer
145
146
. apply_row_group_encryption ( self . row_groups ) ?;
146
147
147
- #[ cfg( not( feature = "encryption" ) ) ]
148
- let encryption_algorithm = None ;
149
-
150
- #[ cfg( feature = "encryption" ) ]
151
- let encryption_algorithm = match & self . object_writer . file_encryptor {
152
- Some ( file_encryptor) => file_encryptor. get_footer_encryptor_for_plaintext ( ) ?,
153
- _ => None ,
154
- } ;
155
-
156
148
let mut file_metadata = FileMetaData {
157
149
num_rows,
158
150
row_groups,
@@ -161,7 +153,7 @@ impl<'a, W: Write> ThriftMetadataWriter<'a, W> {
161
153
schema : types:: to_thrift ( self . schema . as_ref ( ) ) ?,
162
154
created_by : self . created_by . clone ( ) ,
163
155
column_orders,
164
- encryption_algorithm,
156
+ encryption_algorithm : self . object_writer . get_footer_encryption_algorithm ( ) ,
165
157
footer_signing_key_metadata : None ,
166
158
} ;
167
159
@@ -486,6 +478,10 @@ impl MetadataObjectWriter {
486
478
pub fn get_file_magic ( & self ) -> & [ u8 ; 4 ] {
487
479
get_file_magic ( )
488
480
}
481
+
482
+ fn get_footer_encryption_algorithm ( & self ) -> Option < EncryptionAlgorithm > {
483
+ None
484
+ }
489
485
}
490
486
491
487
/// Implementations of [`MetadataObjectWriter`] methods that rely on encryption being enabled
@@ -506,7 +502,7 @@ impl MetadataObjectWriter {
506
502
match self . file_encryptor . as_ref ( ) {
507
503
Some ( file_encryptor) if file_encryptor. properties ( ) . encrypt_footer ( ) => {
508
504
// First write FileCryptoMetadata
509
- let crypto_metadata = Self :: file_crypto_metadata ( file_encryptor ) ?;
505
+ let crypto_metadata = self . file_crypto_metadata ( ) ?;
510
506
let mut protocol = TCompactOutputProtocol :: new ( & mut sink) ;
511
507
crypto_metadata. write_to_out_protocol ( & mut protocol) ?;
512
508
@@ -639,25 +635,31 @@ impl MetadataObjectWriter {
639
635
}
640
636
}
641
637
642
- fn file_crypto_metadata (
643
- file_encryptor : & FileEncryptor ,
644
- ) -> Result < crate :: format:: FileCryptoMetaData > {
645
- let properties = file_encryptor. properties ( ) ;
646
- let supply_aad_prefix = properties
647
- . aad_prefix ( )
648
- . map ( |_| !properties. store_aad_prefix ( ) ) ;
649
- let encryption_algorithm = AesGcmV1 {
650
- aad_prefix : if properties. store_aad_prefix ( ) {
651
- properties. aad_prefix ( ) . cloned ( )
652
- } else {
653
- None
654
- } ,
655
- aad_file_unique : Some ( file_encryptor. aad_file_unique ( ) . clone ( ) ) ,
656
- supply_aad_prefix,
657
- } ;
638
+ fn get_footer_encryption_algorithm ( & self ) -> Option < EncryptionAlgorithm > {
639
+ let file_encryptor = self . file_encryptor . as_ref ( ) . unwrap ( ) ;
640
+ if !file_encryptor. properties ( ) . encrypt_footer ( ) {
641
+ let supply_aad_prefix = file_encryptor
642
+ . properties ( )
643
+ . aad_prefix ( )
644
+ . map ( |_| !file_encryptor. properties ( ) . store_aad_prefix ( ) ) ;
645
+ let encryption_algorithm = Some ( EncryptionAlgorithm :: AESGCMV1 ( AesGcmV1 {
646
+ aad_prefix : if file_encryptor. properties ( ) . store_aad_prefix ( ) {
647
+ file_encryptor. properties ( ) . aad_prefix ( ) . cloned ( )
648
+ } else {
649
+ None
650
+ } ,
651
+ aad_file_unique : Some ( file_encryptor. aad_file_unique ( ) . clone ( ) ) ,
652
+ supply_aad_prefix,
653
+ } ) ) ;
654
+ return encryption_algorithm;
655
+ }
656
+ None
657
+ }
658
658
659
+ fn file_crypto_metadata ( & self ) -> Result < crate :: format:: FileCryptoMetaData > {
660
+ let properties = self . file_encryptor . as_ref ( ) . unwrap ( ) . properties ( ) ;
659
661
Ok ( crate :: format:: FileCryptoMetaData {
660
- encryption_algorithm : EncryptionAlgorithm :: AESGCMV1 ( encryption_algorithm ) ,
662
+ encryption_algorithm : self . get_footer_encryption_algorithm ( ) . unwrap ( ) ,
661
663
key_metadata : properties. footer_key_metadata ( ) . cloned ( ) ,
662
664
} )
663
665
}
0 commit comments