Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
comments
  • Loading branch information
xanderbailey committed Jul 16, 2026
commit 1ce34666f58af5bd1b894099cbf6a50eff421ec1
7 changes: 5 additions & 2 deletions crates/iceberg/public-api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ pub fn iceberg::encryption::SecureKey::clone(&self) -> iceberg::encryption::Secu
impl core::cmp::Eq for iceberg::encryption::SecureKey
impl core::cmp::PartialEq for iceberg::encryption::SecureKey
pub fn iceberg::encryption::SecureKey::eq(&self, other: &iceberg::encryption::SecureKey) -> bool
impl core::convert::From<iceberg::encryption::SecureKey> for iceberg::encryption::StandardKeyMetadata
pub fn iceberg::encryption::StandardKeyMetadata::from(encryption_key: iceberg::encryption::SecureKey) -> Self
impl core::convert::TryFrom<iceberg::encryption::SensitiveBytes> for iceberg::encryption::SecureKey
pub type iceberg::encryption::SecureKey::Error = iceberg::Error
pub fn iceberg::encryption::SecureKey::try_from(key: iceberg::encryption::SensitiveBytes) -> iceberg::Result<Self>
Expand Down Expand Up @@ -350,15 +352,16 @@ pub fn iceberg::encryption::StandardKeyMetadata::decode(bytes: &[u8]) -> iceberg
pub fn iceberg::encryption::StandardKeyMetadata::encode(&self) -> iceberg::Result<alloc::boxed::Box<[u8]>>
pub fn iceberg::encryption::StandardKeyMetadata::encryption_key(&self) -> &iceberg::encryption::SecureKey
pub fn iceberg::encryption::StandardKeyMetadata::file_length(&self) -> core::option::Option<u64>
pub fn iceberg::encryption::StandardKeyMetadata::from_secure_key(encryption_key: iceberg::encryption::SecureKey) -> Self
pub fn iceberg::encryption::StandardKeyMetadata::new(encryption_key: &[u8]) -> iceberg::Result<Self>
pub fn iceberg::encryption::StandardKeyMetadata::try_new(encryption_key: &[u8]) -> iceberg::Result<Self>
pub fn iceberg::encryption::StandardKeyMetadata::with_aad_prefix(self, aad_prefix: &[u8]) -> Self
pub fn iceberg::encryption::StandardKeyMetadata::with_file_length(self, length: u64) -> Self
impl core::clone::Clone for iceberg::encryption::StandardKeyMetadata
pub fn iceberg::encryption::StandardKeyMetadata::clone(&self) -> iceberg::encryption::StandardKeyMetadata
impl core::cmp::Eq for iceberg::encryption::StandardKeyMetadata
impl core::cmp::PartialEq for iceberg::encryption::StandardKeyMetadata
pub fn iceberg::encryption::StandardKeyMetadata::eq(&self, other: &iceberg::encryption::StandardKeyMetadata) -> bool
impl core::convert::From<iceberg::encryption::SecureKey> for iceberg::encryption::StandardKeyMetadata
pub fn iceberg::encryption::StandardKeyMetadata::from(encryption_key: iceberg::encryption::SecureKey) -> Self
impl core::fmt::Debug for iceberg::encryption::StandardKeyMetadata
pub fn iceberg::encryption::StandardKeyMetadata::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
impl core::marker::StructuralPartialEq for iceberg::encryption::StandardKeyMetadata
Expand Down
4 changes: 2 additions & 2 deletions crates/iceberg/src/arrow/delete_file_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ mod tests {
let del_path = format!("{table_location}/encrypted-pos-del.parquet");
write_encrypted_parquet(&del_path, &batch, encryption_key, Some(aad_prefix));

let key_metadata = StandardKeyMetadata::new(encryption_key)
let key_metadata = StandardKeyMetadata::try_new(encryption_key)
.unwrap()
.with_aad_prefix(aad_prefix)
.encode()
Expand Down Expand Up @@ -283,7 +283,7 @@ mod tests {
let del_path = format!("{table_location}/encrypted-eq-del.parquet");
write_encrypted_parquet(&del_path, &batch, encryption_key, Some(aad_prefix));

let key_metadata = StandardKeyMetadata::new(encryption_key)
let key_metadata = StandardKeyMetadata::try_new(encryption_key)
.unwrap()
.with_aad_prefix(aad_prefix)
.encode()
Expand Down
4 changes: 2 additions & 2 deletions crates/iceberg/src/arrow/reader/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ mod tests {
let file_path = format!("{table_location}/encrypted.parquet");
write_encrypted_parquet(&file_path, &batch, encryption_key, Some(aad_prefix));

let key_metadata = crate::encryption::StandardKeyMetadata::new(encryption_key)
let key_metadata = crate::encryption::StandardKeyMetadata::try_new(encryption_key)
.unwrap()
.with_aad_prefix(aad_prefix)
.encode()
Expand Down Expand Up @@ -863,7 +863,7 @@ mod tests {
let file_path = format!("{table_location}/encrypted_wrong_key.parquet");
write_encrypted_parquet(&file_path, &batch, encryption_key, None);

let wrong_key_metadata = crate::encryption::StandardKeyMetadata::new(wrong_key)
let wrong_key_metadata = crate::encryption::StandardKeyMetadata::try_new(wrong_key)
.unwrap()
.encode()
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/iceberg/src/encryption/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ mod tests {
use crate::io::FileIO;

fn key_metadata() -> StandardKeyMetadata {
StandardKeyMetadata::new(b"0123456789abcdef")
StandardKeyMetadata::try_new(b"0123456789abcdef")
.unwrap()
.with_aad_prefix(b"test-aad-prefix!")
}
Expand Down
36 changes: 20 additions & 16 deletions crates/iceberg/src/encryption/key_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,8 @@ impl fmt::Debug for StandardKeyMetadata {

impl StandardKeyMetadata {
/// Creates a new `StandardKeyMetadata` from raw key bytes.
pub fn new(encryption_key: &[u8]) -> Result<Self> {
Ok(Self::from_secure_key(SecureKey::new(encryption_key)?))
}

/// Creates a new `StandardKeyMetadata` from an already-validated key.
pub fn from_secure_key(encryption_key: SecureKey) -> Self {
Self {
encryption_key,
aad_prefix: None,
file_length: None,
}
pub fn try_new(encryption_key: &[u8]) -> Result<Self> {
Ok(Self::from(SecureKey::new(encryption_key)?))
}

/// Adds an AAD prefix.
Expand Down Expand Up @@ -106,6 +97,17 @@ impl StandardKeyMetadata {
}
}

impl From<SecureKey> for StandardKeyMetadata {
/// Creates a `StandardKeyMetadata` from an already-validated key.
fn from(encryption_key: SecureKey) -> Self {
Self {
encryption_key,
aad_prefix: None,
file_length: None,
}
}
}

mod _serde {
use std::io::Cursor;
use std::sync::{Arc, LazyLock};
Expand Down Expand Up @@ -247,7 +249,9 @@ mod tests {
let key = b"0123456789012345";
let aad = b"1234567890123456";

let metadata = StandardKeyMetadata::new(key).unwrap().with_aad_prefix(aad);
let metadata = StandardKeyMetadata::try_new(key)
.unwrap()
.with_aad_prefix(aad);
let serialized = metadata.encode().unwrap();
let parsed = StandardKeyMetadata::decode(&serialized).unwrap();

Expand All @@ -262,7 +266,7 @@ mod tests {
let aad = b"1234567890123456";

let file_length = 100_000;
let metadata = StandardKeyMetadata::new(key)
let metadata = StandardKeyMetadata::try_new(key)
.unwrap()
.with_aad_prefix(aad)
.with_file_length(file_length);
Expand Down Expand Up @@ -292,7 +296,7 @@ mod tests {
#[test]
fn test_roundtrip_without_aad() {
let key = b"0123456789012345";
let metadata = StandardKeyMetadata::new(key).unwrap();
let metadata = StandardKeyMetadata::try_new(key).unwrap();
let serialized = metadata.encode().unwrap();
let parsed = StandardKeyMetadata::decode(&serialized).unwrap();

Expand All @@ -304,13 +308,13 @@ mod tests {
fn test_new_rejects_invalid_key_length() {
// 24-byte (AES-192) and 32-byte (AES-256) keys are accepted.
for len in [16usize, 24, 32] {
assert!(StandardKeyMetadata::new(&vec![0u8; len]).is_ok());
assert!(StandardKeyMetadata::try_new(&vec![0u8; len]).is_ok());
}

// Invalid lengths are rejected at construction, so an invalid
// `StandardKeyMetadata` can never exist.
for len in [0usize, 4, 15, 20, 33] {
assert!(StandardKeyMetadata::new(&vec![0u8; len]).is_err());
assert!(StandardKeyMetadata::try_new(&vec![0u8; len]).is_err());
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/iceberg/src/encryption/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl EncryptionManager {
pub fn encrypt(&self, raw_output: OutputFile) -> EncryptedOutputFile {
let dek = SecureKey::generate(self.key_size);
let aad_prefix = Self::generate_aad_prefix();
let metadata = StandardKeyMetadata::from_secure_key(dek).with_aad_prefix(&aad_prefix);
let metadata = StandardKeyMetadata::from(dek).with_aad_prefix(&aad_prefix);
EncryptedOutputFile::new(raw_output, metadata)
}

Expand Down Expand Up @@ -460,7 +460,7 @@ mod tests {
}

fn sample_key_metadata() -> StandardKeyMetadata {
StandardKeyMetadata::new(b"0123456789abcdef")
StandardKeyMetadata::try_new(b"0123456789abcdef")
.unwrap()
.with_aad_prefix(b"test-aad-prefix!")
}
Expand Down
10 changes: 5 additions & 5 deletions crates/iceberg/src/spec/manifest_list/manifest_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ mod test {

#[tokio::test]
async fn test_load_manifest_decrypts_when_key_metadata_present() {
let key_metadata = StandardKeyMetadata::new(b"0123456789abcdef")
let key_metadata = StandardKeyMetadata::try_new(b"0123456789abcdef")
.unwrap()
.with_aad_prefix(b"test-aad-prefix!");
let encoded_key_metadata = key_metadata.encode().unwrap().to_vec();
Expand All @@ -341,7 +341,7 @@ mod test {

#[tokio::test]
async fn test_load_manifest_fails_with_wrong_key() {
let key_metadata = StandardKeyMetadata::new(b"0123456789abcdef")
let key_metadata = StandardKeyMetadata::try_new(b"0123456789abcdef")
.unwrap()
.with_aad_prefix(b"test-aad-prefix!");

Expand All @@ -353,7 +353,7 @@ mod test {
// the same AAD prefix). The bytes on disk were encrypted with the
// original key, so GCM authentication must fail rather than silently
// returning garbage.
let wrong_key_metadata = StandardKeyMetadata::new(b"fedcba9876543210")
let wrong_key_metadata = StandardKeyMetadata::try_new(b"fedcba9876543210")
.unwrap()
.with_aad_prefix(b"test-aad-prefix!");
manifest_file.key_metadata = Some(wrong_key_metadata.encode().unwrap().to_vec());
Expand All @@ -367,7 +367,7 @@ mod test {

#[tokio::test]
async fn test_load_manifest_fails_with_wrong_aad() {
let key_metadata = StandardKeyMetadata::new(b"0123456789abcdef")
let key_metadata = StandardKeyMetadata::try_new(b"0123456789abcdef")
.unwrap()
.with_aad_prefix(b"test-aad-prefix!");

Expand All @@ -378,7 +378,7 @@ mod test {
// Point the manifest file at key metadata carrying the correct DEK but a
// different AAD prefix. The per-block AAD is `aad_prefix || block_index`,
// so GCM authentication must fail even though the key is right.
let wrong_aad_metadata = StandardKeyMetadata::new(b"0123456789abcdef")
let wrong_aad_metadata = StandardKeyMetadata::try_new(b"0123456789abcdef")
.unwrap()
.with_aad_prefix(b"wrong-aad-prefix");
manifest_file.key_metadata = Some(wrong_aad_metadata.encode().unwrap().to_vec());
Expand Down
Loading