Skip to content

Commit 6d3b81f

Browse files
committed
fix
1 parent 666d586 commit 6d3b81f

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

parquet/src/encryption/encrypt.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use ring::rand::{SecureRandom, SystemRandom};
2626
use std::collections::{HashMap, HashSet};
2727
use std::io::Write;
2828
use thrift::protocol::TCompactOutputProtocol;
29+
use crate::format::{AesGcmV1, EncryptionAlgorithm};
2930

3031
#[derive(Debug, Clone, PartialEq)]
3132
struct EncryptionKey {
@@ -360,6 +361,26 @@ impl FileEncryptor {
360361
Some(column_key) => Ok(Box::new(RingGcmBlockEncryptor::new(column_key.key())?)),
361362
}
362363
}
364+
365+
/// Get encryption algorithm for the plaintext footer
366+
pub(crate) fn get_footer_encryptor_for_plaintext(&self) -> Result<Option<EncryptionAlgorithm>> {
367+
if !self.properties.encrypt_footer() {
368+
let supply_aad_prefix = self.properties
369+
.aad_prefix()
370+
.map(|_| !self.properties.store_aad_prefix());
371+
let encryption_algorithm = Some(EncryptionAlgorithm::AESGCMV1(AesGcmV1 {
372+
aad_prefix: if self.properties.store_aad_prefix() {
373+
self.properties.aad_prefix().cloned()
374+
} else {
375+
None
376+
},
377+
aad_file_unique: Some(self.aad_file_unique().clone()),
378+
supply_aad_prefix,
379+
}));
380+
return Ok(encryption_algorithm);
381+
}
382+
Ok(None)
383+
}
363384
}
364385

365386
/// Write an encrypted Thrift serializable object

parquet/src/file/metadata/writer.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,13 @@ impl<'a, W: Write> ThriftMetadataWriter<'a, W> {
142142
.object_writer
143143
.apply_row_group_encryption(self.row_groups)?;
144144

145-
let mut encryption_algorithm = None;
146-
if let Some(file_encryptor) = self.object_writer.file_encryptor.clone() {
147-
let properties = file_encryptor.properties();
148-
if !properties.encrypt_footer() {
149-
let supply_aad_prefix = properties
150-
.aad_prefix()
151-
.map(|_| !properties.store_aad_prefix());
152-
encryption_algorithm = Some(EncryptionAlgorithm::AESGCMV1(AesGcmV1 {
153-
aad_prefix: if properties.store_aad_prefix() {
154-
properties.aad_prefix().cloned()
155-
} else {
156-
None
157-
},
158-
aad_file_unique: Some(file_encryptor.aad_file_unique().clone()),
159-
supply_aad_prefix,
160-
}));
161-
}
145+
#[cfg(not(feature = "encryption"))]
146+
let encryption_algorithm = None;
147+
148+
#[cfg(feature = "encryption")]
149+
let encryption_algorithm = match &self.object_writer.file_encryptor {
150+
Some(file_encryptor) => file_encryptor.get_footer_encryptor_for_plaintext()?,
151+
_ => None,
162152
};
163153

164154
let mut file_metadata = FileMetaData {

0 commit comments

Comments
 (0)