@@ -717,42 +717,31 @@ impl ParquetMetaDataReader {
717
717
}
718
718
719
719
#[ cfg( feature = "encryption" ) ]
720
- let mut decryptor = None ;
720
+ let mut file_decryptor = None ;
721
721
#[ cfg( feature = "encryption" ) ]
722
722
let decrypted_fmd_buf;
723
723
724
724
#[ cfg( feature = "encryption" ) ]
725
725
if encrypted_footer {
726
- if file_decryption_properties. is_none ( ) {
727
- return Err ( general_err ! ( "Parquet file has an encrypted footer but no decryption properties were provided" ) ) ;
728
- } ;
729
-
730
- let t_file_crypto_metadata: TFileCryptoMetaData =
731
- TFileCryptoMetaData :: read_from_in_protocol ( & mut prot)
732
- . map_err ( |e| general_err ! ( "Could not parse crypto metadata: {}" , e) ) ?;
733
- let algo = t_file_crypto_metadata. encryption_algorithm ;
734
- let aes_gcm_algo = if let EncryptionAlgorithm :: AESGCMV1 ( a) = algo {
735
- a
736
- } else {
737
- unreachable ! ( )
738
- } ; // todo decr: add support for GCMCTRV1
739
-
740
- // todo decr: get key_metadata
741
- let aad_file_unique = aes_gcm_algo. aad_file_unique . unwrap ( ) ;
742
- let aad_prefix: Vec < u8 > = aes_gcm_algo. aad_prefix . unwrap_or_default ( ) ;
743
-
744
- decryptor = Some ( FileDecryptor :: new (
745
- file_decryption_properties. unwrap ( ) ,
746
- aad_file_unique,
747
- aad_prefix,
748
- ) ) ;
749
- let footer_decryptor = decryptor. clone ( ) . unwrap ( ) . get_footer_decryptor ( ) ;
726
+ if let Some ( file_decryption_properties) = file_decryption_properties {
727
+ let t_file_crypto_metadata: TFileCryptoMetaData =
728
+ TFileCryptoMetaData :: read_from_in_protocol ( & mut prot)
729
+ . map_err ( |e| general_err ! ( "Could not parse crypto metadata: {}" , e) ) ?;
730
+ let decryptor = get_file_decryptor (
731
+ t_file_crypto_metadata. encryption_algorithm ,
732
+ file_decryption_properties,
733
+ ) ;
734
+ let footer_decryptor = decryptor. get_footer_decryptor ( ) ;
735
+ let aad_footer = create_footer_aad ( decryptor. file_aad ( ) ) ?;
750
736
751
- let aad_footer = create_footer_aad ( decryptor. as_ref ( ) . unwrap ( ) . file_aad ( ) ) ?;
737
+ decrypted_fmd_buf =
738
+ footer_decryptor. decrypt ( prot. as_slice ( ) . as_ref ( ) , aad_footer. as_ref ( ) ) ?;
739
+ prot = TCompactSliceInputProtocol :: new ( decrypted_fmd_buf. as_ref ( ) ) ;
752
740
753
- decrypted_fmd_buf =
754
- footer_decryptor. decrypt ( prot. as_slice ( ) . as_ref ( ) , aad_footer. as_ref ( ) ) ?;
755
- prot = TCompactSliceInputProtocol :: new ( decrypted_fmd_buf. as_ref ( ) ) ;
741
+ file_decryptor = Some ( decryptor) ;
742
+ } else {
743
+ return Err ( general_err ! ( "Parquet file has an encrypted footer but no decryption properties were provided" ) ) ;
744
+ }
756
745
}
757
746
758
747
let t_file_metadata: TFileMetaData = TFileMetaData :: read_from_in_protocol ( & mut prot)
@@ -761,33 +750,21 @@ impl ParquetMetaDataReader {
761
750
let schema_descr = Arc :: new ( SchemaDescriptor :: new ( schema) ) ;
762
751
763
752
#[ cfg( feature = "encryption" ) ]
764
- if t_file_metadata. encryption_algorithm . is_some ( ) {
765
- let algo = t_file_metadata. encryption_algorithm ;
766
- let aes_gcm_algo = if let Some ( EncryptionAlgorithm :: AESGCMV1 ( a) ) = algo {
767
- a
768
- } else {
769
- unreachable ! ( )
770
- } ; // todo decr: add support for GCMCTRV1
771
- let aad_file_unique = aes_gcm_algo. aad_file_unique . unwrap ( ) ;
772
- let aad_prefix: Vec < u8 > = aes_gcm_algo. aad_prefix . unwrap_or_default ( ) ;
773
-
774
- decryptor = Some ( FileDecryptor :: new (
775
- file_decryption_properties. unwrap ( ) ,
776
- aad_file_unique,
777
- aad_prefix,
778
- ) ) ;
779
- // todo get key_metadata etc. Set file decryptor in return value
780
- // todo check signature
753
+ if let ( Some ( algo) , Some ( file_decryption_properties) ) = (
754
+ t_file_metadata. encryption_algorithm ,
755
+ file_decryption_properties,
756
+ ) {
757
+ // File has a plaintext footer but encryption algorithm is set
758
+ file_decryptor = Some ( get_file_decryptor ( algo, file_decryption_properties) ) ;
781
759
}
782
760
783
761
let mut row_groups = Vec :: new ( ) ;
784
- // TODO: row group filtering
785
762
for rg in t_file_metadata. row_groups {
786
763
let r = RowGroupMetaData :: from_thrift (
787
764
schema_descr. clone ( ) ,
788
765
rg,
789
766
#[ cfg( feature = "encryption" ) ]
790
- decryptor . as_ref ( ) ,
767
+ file_decryptor . as_ref ( ) ,
791
768
) ?;
792
769
row_groups. push ( r) ;
793
770
}
@@ -806,7 +783,7 @@ impl ParquetMetaDataReader {
806
783
file_metadata,
807
784
row_groups,
808
785
#[ cfg( feature = "encryption" ) ]
809
- decryptor ,
786
+ file_decryptor ,
810
787
) )
811
788
}
812
789
@@ -842,6 +819,23 @@ impl ParquetMetaDataReader {
842
819
}
843
820
}
844
821
822
+ #[ cfg( feature = "encryption" ) ]
823
+ fn get_file_decryptor (
824
+ encryption_algorithm : EncryptionAlgorithm ,
825
+ file_decryption_properties : & FileDecryptionProperties ,
826
+ ) -> FileDecryptor {
827
+ let aes_gcm_algo = if let EncryptionAlgorithm :: AESGCMV1 ( a) = encryption_algorithm {
828
+ a
829
+ } else {
830
+ todo ! ( "GCMCTRV1 encryption algorithm" )
831
+ } ;
832
+
833
+ let aad_file_unique = aes_gcm_algo. aad_file_unique . unwrap ( ) ;
834
+ let aad_prefix: Vec < u8 > = aes_gcm_algo. aad_prefix . unwrap_or_default ( ) ;
835
+
836
+ FileDecryptor :: new ( file_decryption_properties, aad_file_unique, aad_prefix)
837
+ }
838
+
845
839
#[ cfg( test) ]
846
840
mod tests {
847
841
use super :: * ;
0 commit comments