15
15
// specific language governing permissions and limitations
16
16
// under the License.
17
17
18
+ use crate :: errors:: { ParquetError , Result } ;
18
19
use ring:: aead:: { Aad , LessSafeKey , UnboundKey , AES_128_GCM } ;
19
20
use std:: collections:: HashMap ;
20
21
@@ -23,7 +24,7 @@ const TAG_LEN: usize = 16;
23
24
const SIZE_LEN : usize = 4 ;
24
25
25
26
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 > > ;
27
28
}
28
29
29
30
#[ derive( Debug , Clone ) ]
@@ -43,7 +44,7 @@ impl RingGcmBlockDecryptor {
43
44
}
44
45
45
46
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 > > {
47
48
let mut result =
48
49
Vec :: with_capacity ( length_and_ciphertext. len ( ) - SIZE_LEN - NONCE_LEN - TAG_LEN ) ;
49
50
result. extend_from_slice ( & length_and_ciphertext[ SIZE_LEN + NONCE_LEN ..] ) ;
@@ -99,12 +100,16 @@ impl DecryptionPropertiesBuilder {
99
100
}
100
101
}
101
102
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 {
104
109
footer_key : self . footer_key ,
105
110
column_keys : self . column_keys ,
106
111
aad_prefix : self . aad_prefix ,
107
- }
112
+ } )
108
113
}
109
114
110
115
// todo decr: doc comment
@@ -184,6 +189,7 @@ impl FileDecryptor {
184
189
. with_footer_key ( column_key. clone ( ) )
185
190
. with_aad_prefix ( self . aad_prefix . clone ( ) )
186
191
. build ( )
192
+ . unwrap ( )
187
193
} else {
188
194
self . decryption_properties . clone ( )
189
195
} ;
0 commit comments