Skip to content

Commit 1ab67ce

Browse files
committed
remove native io types
1 parent 0351241 commit 1ab67ce

3 files changed

Lines changed: 8 additions & 177 deletions

File tree

crates/iceberg/src/encryption/encrypted_io.rs

Lines changed: 0 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use std::sync::Arc;
2121

2222
use bytes::Bytes;
2323

24-
use super::crypto::SensitiveBytes;
2524
use super::file_decryptor::AesGcmFileDecryptor;
2625
use super::file_encryptor::AesGcmFileEncryptor;
2726
use crate::io::{FileMetadata, FileRead, FileWrite, InputFile, OutputFile};
@@ -89,48 +88,6 @@ impl std::fmt::Debug for EncryptedInputFile {
8988
}
9089
}
9190

92-
/// A Parquet Modular Encryption (PME) input file wrapping a plain [`InputFile`].
93-
///
94-
/// The Parquet reader handles decryption at the column/page level using the
95-
/// key material carried by this struct.
96-
pub struct NativeEncryptedInputFile {
97-
inner: InputFile,
98-
key_material: NativeKeyMaterial,
99-
}
100-
101-
impl NativeEncryptedInputFile {
102-
/// Creates a new native-encrypted input file.
103-
pub fn new(inner: InputFile, key_material: NativeKeyMaterial) -> Self {
104-
Self {
105-
inner,
106-
key_material,
107-
}
108-
}
109-
110-
/// Absolute path of the file.
111-
pub fn location(&self) -> &str {
112-
self.inner.location()
113-
}
114-
115-
/// Returns the native key material for PME decryption.
116-
pub fn key_material(&self) -> &NativeKeyMaterial {
117-
&self.key_material
118-
}
119-
120-
/// Consumes self and returns the underlying plain input file.
121-
pub fn into_inner(self) -> InputFile {
122-
self.inner
123-
}
124-
}
125-
126-
impl std::fmt::Debug for NativeEncryptedInputFile {
127-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
128-
f.debug_struct("NativeEncryptedInputFile")
129-
.field("path", &self.inner.location())
130-
.finish_non_exhaustive()
131-
}
132-
}
133-
13491
/// An AGS1 stream-encrypted output file wrapping a plain [`OutputFile`].
13592
///
13693
/// Transparently encrypts on write.
@@ -195,95 +152,3 @@ impl std::fmt::Debug for EncryptedOutputFile {
195152
.finish_non_exhaustive()
196153
}
197154
}
198-
199-
/// A Parquet Modular Encryption (PME) output file wrapping a plain [`OutputFile`].
200-
///
201-
/// The Parquet writer handles encryption at the column/page level using the
202-
/// key material carried by this struct.
203-
pub struct NativeEncryptedOutputFile {
204-
inner: OutputFile,
205-
key_metadata: Box<[u8]>,
206-
key_material: NativeKeyMaterial,
207-
}
208-
209-
impl NativeEncryptedOutputFile {
210-
/// Creates a new native-encrypted output file.
211-
pub fn new(
212-
inner: OutputFile,
213-
key_metadata: Box<[u8]>,
214-
key_material: NativeKeyMaterial,
215-
) -> Self {
216-
Self {
217-
inner,
218-
key_metadata,
219-
key_material,
220-
}
221-
}
222-
223-
/// Returns the key metadata bytes (for storage in manifest/data files).
224-
pub fn key_metadata(&self) -> &[u8] {
225-
&self.key_metadata
226-
}
227-
228-
/// Absolute path of the file.
229-
pub fn location(&self) -> &str {
230-
self.inner.location()
231-
}
232-
233-
/// Returns the native key material for PME encryption.
234-
pub fn key_material(&self) -> &NativeKeyMaterial {
235-
&self.key_material
236-
}
237-
238-
/// Consumes self and returns the underlying plain output file.
239-
pub fn into_inner(self) -> OutputFile {
240-
self.inner
241-
}
242-
}
243-
244-
impl std::fmt::Debug for NativeEncryptedOutputFile {
245-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
246-
f.debug_struct("NativeEncryptedOutputFile")
247-
.field("path", &self.inner.location())
248-
.finish_non_exhaustive()
249-
}
250-
}
251-
252-
/// Plaintext key material for Parquet Modular Encryption (PME).
253-
///
254-
/// Carries the DEK and AAD prefix needed by a Parquet reader/writer to
255-
/// configure `FileEncryptionProperties` / `FileDecryptionProperties`.
256-
///
257-
/// Rust equivalent of Java's `NativeEncryptionKeyMetadata` interface.
258-
pub struct NativeKeyMaterial {
259-
dek: SensitiveBytes,
260-
/// AAD prefix is not secret — it is stored in plaintext in file metadata
261-
/// and used for integrity (authenticated data), not confidentiality.
262-
aad_prefix: Box<[u8]>,
263-
}
264-
265-
impl NativeKeyMaterial {
266-
/// Creates a new `NativeKeyMaterial`.
267-
pub fn new(dek: SensitiveBytes, aad_prefix: Box<[u8]>) -> Self {
268-
Self { dek, aad_prefix }
269-
}
270-
271-
/// Returns the plaintext DEK.
272-
pub fn dek(&self) -> &SensitiveBytes {
273-
&self.dek
274-
}
275-
276-
/// Returns the AAD prefix.
277-
pub fn aad_prefix(&self) -> &[u8] {
278-
&self.aad_prefix
279-
}
280-
}
281-
282-
impl std::fmt::Debug for NativeKeyMaterial {
283-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
284-
f.debug_struct("NativeKeyMaterial")
285-
.field("dek", &self.dek)
286-
.field("aad_prefix_len", &self.aad_prefix.len())
287-
.finish()
288-
}
289-
}

crates/iceberg/src/encryption/encryption_manager.rs

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ use uuid::Uuid;
3636
const MILLIS_IN_DAY: i64 = 24 * 60 * 60 * 1000;
3737

3838
use super::crypto::{AesGcmCipher, AesKeySize, SecureKey, SensitiveBytes};
39-
use super::encrypted_io::{
40-
EncryptedInputFile, EncryptedOutputFile, NativeEncryptedInputFile, NativeEncryptedOutputFile,
41-
NativeKeyMaterial,
42-
};
39+
use super::encrypted_io::{EncryptedInputFile, EncryptedOutputFile};
4340
use super::file_decryptor::AesGcmFileDecryptor;
4441
use super::file_encryptor::AesGcmFileEncryptor;
4542
use super::key_metadata::StandardKeyMetadata;
@@ -128,43 +125,15 @@ impl EncryptionManager {
128125
Ok(EncryptedInputFile::new(input, decryptor))
129126
}
130127

131-
/// Encrypt an output file for Parquet Modular Encryption (PME).
128+
/// Generate key material for Parquet Modular Encryption (PME).
132129
///
133-
/// Returns a [`NativeEncryptedOutputFile`] whose key material is available
134-
/// for the Parquet writer to configure `FileEncryptionProperties`.
135-
pub fn encrypt_native(&self, raw_output: OutputFile) -> Result<NativeEncryptedOutputFile> {
130+
/// Returns a [`StandardKeyMetadata`] containing a fresh DEK and AAD prefix.
131+
/// The caller should pass this to the Parquet writer to configure
132+
/// `FileEncryptionProperties`, and serialize it for storage in the manifest.
133+
pub fn generate_native_key_metadata(&self) -> Result<StandardKeyMetadata> {
136134
let dek = SecureKey::generate(self.key_size);
137135
let aad_prefix = Self::generate_aad_prefix();
138-
139-
let key_metadata_bytes = StandardKeyMetadata::new(dek.as_bytes())
140-
.with_aad_prefix(&aad_prefix)
141-
.encode()?;
142-
143-
Ok(NativeEncryptedOutputFile::new(
144-
raw_output,
145-
key_metadata_bytes,
146-
NativeKeyMaterial::new(SensitiveBytes::new(dek.as_bytes()), aad_prefix),
147-
))
148-
}
149-
150-
/// Decrypt key metadata for a Parquet Modular Encryption (PME) file.
151-
///
152-
/// Returns a [`NativeEncryptedInputFile`] carrying the plaintext DEK
153-
/// and AAD prefix for the Parquet reader to configure
154-
/// `FileDecryptionProperties`.
155-
pub fn decrypt_native(
156-
&self,
157-
raw_input: InputFile,
158-
key_metadata: &[u8],
159-
) -> Result<NativeEncryptedInputFile> {
160-
let metadata = StandardKeyMetadata::decode(key_metadata)?;
161-
Ok(NativeEncryptedInputFile::new(
162-
raw_input,
163-
NativeKeyMaterial::new(
164-
metadata.encryption_key().clone(),
165-
metadata.aad_prefix().unwrap_or_default().into(),
166-
),
167-
))
136+
Ok(StandardKeyMetadata::new(dek.as_bytes()).with_aad_prefix(&aad_prefix))
168137
}
169138

170139
/// Wrap key metadata bytes with a KEK for storage in table metadata.

crates/iceberg/src/encryption/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ pub mod kms;
3030
mod stream;
3131

3232
pub use crypto::{AesGcmCipher, AesKeySize, SecureKey, SensitiveBytes};
33-
pub use encrypted_io::{
34-
EncryptedInputFile, EncryptedOutputFile, NativeEncryptedInputFile, NativeEncryptedOutputFile,
35-
NativeKeyMaterial,
36-
};
33+
pub use encrypted_io::{EncryptedInputFile, EncryptedOutputFile};
3734
pub use encryption_manager::EncryptionManager;
3835
pub use file_decryptor::AesGcmFileDecryptor;
3936
pub use file_encryptor::AesGcmFileEncryptor;

0 commit comments

Comments
 (0)