Skip to content

Commit c4860da

Browse files
committed
FileDecryptionProperties should have at least one key
1 parent 6acb984 commit c4860da

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

parquet/src/arrow/arrow_reader/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,8 @@ mod tests {
18931893
let decryption_properties = FileDecryptionProperties::builder()
18941894
.with_column_key("double_field".as_bytes().to_vec(), column_1_key.to_vec())
18951895
.with_column_key("float_field".as_bytes().to_vec(), column_2_key.to_vec())
1896-
.build();
1896+
.build()
1897+
.unwrap();
18971898

18981899
verify_encryption_test_file_read(file, decryption_properties);
18991900
}
@@ -1913,7 +1914,8 @@ mod tests {
19131914
.with_footer_key(footer_key.to_vec())
19141915
.with_column_key("double_field".as_bytes().to_vec(), column_1_key.to_vec())
19151916
.with_column_key("float_field".as_bytes().to_vec(), column_2_key.to_vec())
1916-
.build();
1917+
.build()
1918+
.unwrap();
19171919

19181920
verify_encryption_test_file_read(file, decryption_properties);
19191921
}
@@ -1928,7 +1930,8 @@ mod tests {
19281930
let key_code: &[u8] = "0123456789012345".as_bytes();
19291931
let decryption_properties = FileDecryptionProperties::builder()
19301932
.with_footer_key(key_code.to_vec())
1931-
.build();
1933+
.build()
1934+
.unwrap();
19321935

19331936
verify_encryption_test_file_read(file, decryption_properties);
19341937
}

parquet/src/encryption/decryption.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
use crate::errors::{ParquetError, Result};
1819
use ring::aead::{Aad, LessSafeKey, UnboundKey, AES_128_GCM};
1920
use std::collections::HashMap;
2021

@@ -23,7 +24,7 @@ const TAG_LEN: usize = 16;
2324
const SIZE_LEN: usize = 4;
2425

2526
pub trait BlockDecryptor {
26-
fn decrypt(&self, length_and_ciphertext: &[u8], aad: &[u8]) -> crate::errors::Result<Vec<u8>>;
27+
fn decrypt(&self, length_and_ciphertext: &[u8], aad: &[u8]) -> Result<Vec<u8>>;
2728
}
2829

2930
#[derive(Debug, Clone)]
@@ -43,7 +44,7 @@ impl RingGcmBlockDecryptor {
4344
}
4445

4546
impl BlockDecryptor for RingGcmBlockDecryptor {
46-
fn decrypt(&self, length_and_ciphertext: &[u8], aad: &[u8]) -> crate::errors::Result<Vec<u8>> {
47+
fn decrypt(&self, length_and_ciphertext: &[u8], aad: &[u8]) -> Result<Vec<u8>> {
4748
let mut result =
4849
Vec::with_capacity(length_and_ciphertext.len() - SIZE_LEN - NONCE_LEN - TAG_LEN);
4950
result.extend_from_slice(&length_and_ciphertext[SIZE_LEN + NONCE_LEN..]);
@@ -99,12 +100,16 @@ impl DecryptionPropertiesBuilder {
99100
}
100101
}
101102

102-
pub fn build(self) -> FileDecryptionProperties {
103-
FileDecryptionProperties {
103+
pub fn build(self) -> Result<FileDecryptionProperties> {
104+
if self.footer_key.is_none() && self.column_keys.is_none() {
105+
return Err(ParquetError::General("Footer or at least one column key is required".to_string()))
106+
}
107+
108+
Ok(FileDecryptionProperties {
104109
footer_key: self.footer_key,
105110
column_keys: self.column_keys,
106111
aad_prefix: self.aad_prefix,
107-
}
112+
})
108113
}
109114

110115
// todo decr: doc comment
@@ -184,6 +189,7 @@ impl FileDecryptor {
184189
.with_footer_key(column_key.clone())
185190
.with_aad_prefix(self.aad_prefix.clone())
186191
.build()
192+
.unwrap()
187193
} else {
188194
self.decryption_properties.clone()
189195
};

0 commit comments

Comments
 (0)