@@ -89,7 +89,7 @@ use std::sync::Arc;
89
89
///
90
90
/// // Create decryption properties for reading an encrypted file.
91
91
/// // Note that we don't need to specify which columns are encrypted,
92
- /// // this is determined by the file metadata and the required keys will be retrieved
92
+ /// // this is determined by the file metadata, and the required keys will be retrieved
93
93
/// // dynamically using our key retriever.
94
94
/// let decryption_properties = FileDecryptionProperties::with_key_retriever(key_retriever)
95
95
/// .build()?;
@@ -293,7 +293,7 @@ impl PartialEq for DecryptionKeys {
293
293
/// `FileDecryptionProperties` hold keys and AAD data required to decrypt a Parquet file.
294
294
///
295
295
/// When reading Arrow data, the `FileDecryptionProperties` should be included in the
296
- /// [`ArrowReaderOptions`](crate::arrow::arrow_reader::ArrowReaderOptions) using
296
+ /// [`ArrowReaderOptions`](crate::arrow::arrow_reader::ArrowReaderOptions) using
297
297
/// [`with_file_decryption_properties`](crate::arrow::arrow_reader::ArrowReaderOptions::with_file_decryption_properties).
298
298
///
299
299
/// # Examples
@@ -343,8 +343,10 @@ impl FileDecryptionProperties {
343
343
344
344
/// Returns a new [`FileDecryptionProperties`] builder that uses a [`KeyRetriever`]
345
345
/// to get decryption keys based on key metadata.
346
- pub fn with_key_retriever ( key_retriever : Arc < dyn KeyRetriever > ) -> DecryptionPropertiesBuilder {
347
- DecryptionPropertiesBuilder :: new_with_key_retriever ( key_retriever)
346
+ pub fn with_key_retriever (
347
+ key_retriever : Arc < dyn KeyRetriever > ,
348
+ ) -> DecryptionPropertiesBuilderWithRetriever {
349
+ DecryptionPropertiesBuilderWithRetriever :: new ( key_retriever)
348
350
}
349
351
350
352
/// AAD prefix string uniquely identifies the file and prevents file swapping
@@ -417,8 +419,7 @@ impl std::fmt::Debug for FileDecryptionProperties {
417
419
///
418
420
/// See [`FileDecryptionProperties`] for example usage.
419
421
pub struct DecryptionPropertiesBuilder {
420
- footer_key : Option < Vec < u8 > > ,
421
- key_retriever : Option < Arc < dyn KeyRetriever > > ,
422
+ footer_key : Vec < u8 > ,
422
423
column_keys : HashMap < String , Vec < u8 > > ,
423
424
aad_prefix : Option < Vec < u8 > > ,
424
425
footer_signature_verification : bool ,
@@ -429,22 +430,7 @@ impl DecryptionPropertiesBuilder {
429
430
/// decrypt footer metadata.
430
431
pub fn new ( footer_key : Vec < u8 > ) -> DecryptionPropertiesBuilder {
431
432
Self {
432
- footer_key : Some ( footer_key) ,
433
- key_retriever : None ,
434
- column_keys : HashMap :: default ( ) ,
435
- aad_prefix : None ,
436
- footer_signature_verification : true ,
437
- }
438
- }
439
-
440
- /// Create a new [`DecryptionPropertiesBuilder`] by providing a [`KeyRetriever`] that
441
- /// can be used to get decryption keys based on key metadata.
442
- pub fn new_with_key_retriever (
443
- key_retriever : Arc < dyn KeyRetriever > ,
444
- ) -> DecryptionPropertiesBuilder {
445
- Self {
446
- footer_key : None ,
447
- key_retriever : Some ( key_retriever) ,
433
+ footer_key,
448
434
column_keys : HashMap :: default ( ) ,
449
435
aad_prefix : None ,
450
436
footer_signature_verification : true ,
@@ -453,23 +439,10 @@ impl DecryptionPropertiesBuilder {
453
439
454
440
/// Finalize the builder and return created [`FileDecryptionProperties`]
455
441
pub fn build ( self ) -> Result < FileDecryptionProperties > {
456
- let keys = match ( self . footer_key , self . key_retriever ) {
457
- ( Some ( footer_key) , None ) => DecryptionKeys :: Explicit ( ExplicitDecryptionKeys {
458
- footer_key,
459
- column_keys : self . column_keys ,
460
- } ) ,
461
- ( None , Some ( key_retriever) ) => {
462
- if !self . column_keys . is_empty ( ) {
463
- return Err ( general_err ! (
464
- "Cannot specify column keys directly when using a key retriever"
465
- ) ) ;
466
- }
467
- DecryptionKeys :: ViaRetriever ( key_retriever)
468
- }
469
- _ => {
470
- unreachable ! ( )
471
- }
472
- } ;
442
+ let keys = DecryptionKeys :: Explicit ( ExplicitDecryptionKeys {
443
+ footer_key : self . footer_key ,
444
+ column_keys : self . column_keys ,
445
+ } ) ;
473
446
Ok ( FileDecryptionProperties {
474
447
keys,
475
448
aad_prefix : self . aad_prefix ,
@@ -515,6 +488,52 @@ impl DecryptionPropertiesBuilder {
515
488
}
516
489
}
517
490
491
+ /// Builder for [`FileDecryptionProperties`] that uses a [`KeyRetriever`]
492
+ ///
493
+ /// See the [`KeyRetriever`] documentation for example usage.
494
+ pub struct DecryptionPropertiesBuilderWithRetriever {
495
+ key_retriever : Arc < dyn KeyRetriever > ,
496
+ aad_prefix : Option < Vec < u8 > > ,
497
+ footer_signature_verification : bool ,
498
+ }
499
+
500
+ impl DecryptionPropertiesBuilderWithRetriever {
501
+ /// Create a new [`DecryptionPropertiesBuilderWithRetriever`] by providing a [`KeyRetriever`] that
502
+ /// can be used to get decryption keys based on key metadata.
503
+ pub fn new ( key_retriever : Arc < dyn KeyRetriever > ) -> DecryptionPropertiesBuilderWithRetriever {
504
+ Self {
505
+ key_retriever,
506
+ aad_prefix : None ,
507
+ footer_signature_verification : true ,
508
+ }
509
+ }
510
+
511
+ /// Finalize the builder and return created [`FileDecryptionProperties`]
512
+ pub fn build ( self ) -> Result < FileDecryptionProperties > {
513
+ let keys = DecryptionKeys :: ViaRetriever ( self . key_retriever ) ;
514
+ Ok ( FileDecryptionProperties {
515
+ keys,
516
+ aad_prefix : self . aad_prefix ,
517
+ footer_signature_verification : self . footer_signature_verification ,
518
+ } )
519
+ }
520
+
521
+ /// Specify the expected AAD prefix to be used for decryption.
522
+ /// This must be set if the file was written with an AAD prefix and the
523
+ /// prefix is not stored in the file metadata.
524
+ pub fn with_aad_prefix ( mut self , value : Vec < u8 > ) -> Self {
525
+ self . aad_prefix = Some ( value) ;
526
+ self
527
+ }
528
+
529
+ /// Disable verification of footer tags for files that use plaintext footers.
530
+ /// Signature verification is enabled by default.
531
+ pub fn disable_footer_signature_verification ( mut self ) -> Self {
532
+ self . footer_signature_verification = false ;
533
+ self
534
+ }
535
+ }
536
+
518
537
#[ derive( Clone , Debug ) ]
519
538
pub ( crate ) struct FileDecryptor {
520
539
decryption_properties : FileDecryptionProperties ,
0 commit comments