feat(encryption): [2/N] Add standard key metadata - #3948
Merged
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kevinjqliu
approved these changes
Sep 11, 2026
kevinjqliu
left a comment
Contributor
There was a problem hiding this comment.
LGTM
i pushed a change to redact encryption_key in repr
6f6ceaa
Comment on lines
+24
to
+26
| from pyiceberg.avro.decoder import new_decoder | ||
| from pyiceberg.avro.encoder import BinaryEncoder | ||
| from pyiceberg.avro.resolver import construct_reader, construct_writer |
Contributor
There was a problem hiding this comment.
BTW we want to rip out the current pyiceberg avro reader (which is written with cython) and replace with rust's avro reader. maybe this would be a good integration point 😄
Contributor
There was a problem hiding this comment.
just spitballing, maybe something like
@dataclass(frozen=True)
class StandardKeyMetadata:
encryption_key: bytes = field(repr=False)
aad_prefix: bytes | None = None
file_length: int | None = None
@classmethod
def from_bytes(cls, data: bytes) -> StandardKeyMetadata:
key, aad, length = pyiceberg_core.encryption.decode_standard_key_metadata(data)
return cls(key, aad, length)
def to_bytes(self) -> bytes:
return pyiceberg_core.encryption.encode_standard_key_metadata(
self.encryption_key, self.aad_prefix, self.file_length
)
and in rust side:
// iceberg-rust/bindings/python/src/encryption.rs
#[pyfunction]
fn decode_standard_key_metadata(data: &[u8])
-> PyResult<(Vec<u8>, Option<Vec<u8>>, Option<i64>)>
{
let metadata = StandardKeyMetadata::from_bytes(data).map_err(to_py_err)?;
Ok((metadata.key_bytes(), metadata.aad_prefix(), metadata.file_length()))
}
#[pyfunction]
fn encode_standard_key_metadata(
key: &[u8],
aad_prefix: Option<&[u8]>,
file_length: Option<i64>,
) -> PyResult<Vec<u8>> {
StandardKeyMetadata::new(key, aad_prefix, file_length)
.and_then(|metadata| metadata.to_bytes())
.map_err(to_py_err)
}
Contributor
Author
There was a problem hiding this comment.
This is pretty cool, let me have a look at this on Monday!
Contributor
There was a problem hiding this comment.
cheers, im pretty excited about this. we can brainstorm and write it up as an issue.
Contributor
Author
There was a problem hiding this comment.
Okay gave it a go here apache/iceberg-rust#3206 let me know what you think!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Python version of
StandardKeyMetadatadirect port of the logic added in https://github.com/apache/iceberg-rust/pull/2340/changesRationale for this change
Are these changes tested?
Are there any user-facing changes?