@@ -1290,16 +1290,14 @@ mod tests {
1290
1290
1291
1291
use std:: fs:: File ;
1292
1292
1293
- #[ cfg( feature = "encryption" ) ]
1294
- use crate :: arrow:: arrow_reader:: ArrowReaderMetadata ;
1295
1293
#[ cfg( feature = "encryption" ) ]
1296
1294
use crate :: arrow:: arrow_reader:: ArrowReaderOptions ;
1297
1295
use crate :: arrow:: arrow_reader:: { ParquetRecordBatchReader , ParquetRecordBatchReaderBuilder } ;
1298
1296
use crate :: arrow:: ARROW_SCHEMA_META_KEY ;
1299
1297
#[ cfg( feature = "encryption" ) ]
1300
1298
use crate :: encryption:: encrypt:: EncryptionKey ;
1301
1299
#[ cfg( feature = "encryption" ) ]
1302
- use crate :: util:: test_common:: encryption_util:: verify_encryption_test_file_read ;
1300
+ use crate :: util:: test_common:: encryption_util:: read_and_roundtrip_to_encrypted_file ;
1303
1301
use arrow:: datatypes:: ToByteSlice ;
1304
1302
use arrow:: datatypes:: { DataType , Schema } ;
1305
1303
use arrow:: error:: Result as ArrowResult ;
@@ -3808,7 +3806,6 @@ mod tests {
3808
3806
fn test_non_uniform_encryption ( ) {
3809
3807
let testdata = arrow:: util:: test_util:: parquet_test_data ( ) ;
3810
3808
let path = format ! ( "{testdata}/encrypt_columns_and_footer.parquet.encrypted" ) ;
3811
- let temp_file = tempfile:: tempfile ( ) . unwrap ( ) ;
3812
3809
3813
3810
let footer_key = "0123456789012345" . as_bytes ( ) ; // 128bit/16
3814
3811
let column_1_key = "1234567890123450" . as_bytes ( ) ;
@@ -3820,62 +3817,39 @@ mod tests {
3820
3817
. build ( )
3821
3818
. unwrap ( ) ;
3822
3819
3823
- // read example data
3824
- let ( batches, schema) = read_encrypted_file ( & path, decryption_properties. clone ( ) ) ;
3825
-
3826
- // write example data
3827
3820
let column_1_key = EncryptionKey :: new ( column_1_key. as_bytes ( ) . to_vec ( ) ) ;
3828
3821
let column_2_key = EncryptionKey :: new ( column_2_key. as_bytes ( ) . to_vec ( ) ) ;
3829
3822
let file_encryption_properties = FileEncryptionProperties :: builder ( footer_key. to_vec ( ) )
3830
3823
. with_column_key ( "double_field" . into ( ) , column_1_key)
3831
3824
. with_column_key ( "float_field" . into ( ) , column_2_key)
3832
3825
. build ( ) ;
3833
3826
3834
- let temp_file =
3835
- write_batches_to_encrypted_file ( temp_file , file_encryption_properties , batches , schema ) ;
3836
-
3837
- // check re-written example data
3838
- verify_encryption_test_file_read ( temp_file , decryption_properties ) ;
3827
+ read_and_roundtrip_to_encrypted_file (
3828
+ & path ,
3829
+ decryption_properties ,
3830
+ file_encryption_properties ,
3831
+ ) ;
3839
3832
}
3840
3833
3834
+ #[ test]
3841
3835
#[ cfg( feature = "encryption" ) ]
3842
- fn write_batches_to_encrypted_file (
3843
- temp_file : File ,
3844
- file_encryption_properties : FileEncryptionProperties ,
3845
- batches : Vec < RecordBatch > ,
3846
- schema : SchemaRef ,
3847
- ) -> File {
3848
- let props = WriterProperties :: builder ( )
3849
- . with_file_encryption_properties ( file_encryption_properties)
3850
- . build ( ) ;
3836
+ fn test_uniform_encryption ( ) {
3837
+ let testdata = arrow:: util:: test_util:: parquet_test_data ( ) ;
3838
+ let path = format ! ( "{testdata}/uniform_encryption.parquet.encrypted" ) ;
3851
3839
3852
- let mut writer =
3853
- ArrowWriter :: try_new ( temp_file. try_clone ( ) . unwrap ( ) , schema, Some ( props) ) . unwrap ( ) ;
3854
- for batch in batches {
3855
- writer. write ( & batch) . unwrap ( ) ;
3856
- }
3840
+ let footer_key = "0123456789012345" . as_bytes ( ) ; // 128bit/16
3857
3841
3858
- writer . close ( ) . unwrap ( ) ;
3859
- temp_file
3860
- }
3842
+ let decryption_properties = FileDecryptionProperties :: builder ( footer_key . to_vec ( ) )
3843
+ . build ( )
3844
+ . unwrap ( ) ;
3861
3845
3862
- #[ cfg( feature = "encryption" ) ]
3863
- fn read_encrypted_file (
3864
- path : & str ,
3865
- decryption_properties : FileDecryptionProperties ,
3866
- ) -> ( Vec < RecordBatch > , SchemaRef ) {
3867
- let file = File :: open ( path) . unwrap ( ) ;
3868
- let options =
3869
- ArrowReaderOptions :: default ( ) . with_file_decryption_properties ( decryption_properties) ;
3870
- let metadata = ArrowReaderMetadata :: load ( & file, options. clone ( ) ) . unwrap ( ) ;
3846
+ let file_encryption_properties =
3847
+ FileEncryptionProperties :: builder ( footer_key. to_vec ( ) ) . build ( ) ;
3871
3848
3872
- let builder = ParquetRecordBatchReaderBuilder :: try_new_with_options ( file, options) . unwrap ( ) ;
3873
- let batch_reader = builder. build ( ) . unwrap ( ) ;
3874
- (
3875
- batch_reader
3876
- . collect :: < Result < Vec < RecordBatch > , _ > > ( )
3877
- . unwrap ( ) ,
3878
- metadata. schema ,
3879
- )
3849
+ read_and_roundtrip_to_encrypted_file (
3850
+ & path,
3851
+ decryption_properties,
3852
+ file_encryption_properties,
3853
+ ) ;
3880
3854
}
3881
3855
}
0 commit comments