blackmwk commented on code in PR #3236:
URL: https://github.com/apache/iceberg-rust/pull/3236#discussion_r4045087675


##########
crates/iceberg/src/encryption/io.rs:
##########
@@ -58,8 +58,7 @@ impl EncryptedInputFile {
     ///
     /// The returned size is the **plaintext** size.
     pub async fn metadata(&self) -> Result<FileMetadata> {
-        let raw_meta = self.inner.metadata().await?;
-        let plaintext_size = 
AesGcmFileRead::calculate_plaintext_length(raw_meta.size)?;
+        let plaintext_size = 
AesGcmFileRead::calculate_plaintext_length(self.encrypted_length()?)?;

Review Comment:
   nit: Should we removve the async now?



##########
crates/iceberg/src/encryption/io.rs:
##########
@@ -138,8 +153,8 @@ impl EncryptedOutputFile {
         )))
     }
 
-    /// Write bytes to file (transparently encrypted).
-    pub async fn write(&self, bs: Bytes) -> Result<()> {
+    /// Write bytes to the file and return its encrypted size.
+    pub async fn write(&self, bs: Bytes) -> Result<FileMetadata> {

Review Comment:
   While I agree the `key_metadata_with_file_length` is the right direction, 
could we have a more meaningful name? For example 
`key_metadta_with_saved_file_metadata(&self, file_metadata: &FileMetadata)` 



##########
crates/iceberg/src/encryption/io.rs:
##########
@@ -74,14 +73,30 @@ impl EncryptedInputFile {
 
     /// Creates a reader that transparently decrypts on each read.
     pub async fn reader(&self) -> Result<Box<dyn FileRead>> {
-        let raw_meta = self.inner.metadata().await?;
+        let encrypted_length = self.encrypted_length()?;
         let raw_reader = self.inner.reader().await?;
         let cipher = build_cipher(&self.key_metadata)?;
         let aad_prefix: Box<[u8]> = 
self.key_metadata.aad_prefix().unwrap_or_default().into();
-        let decrypting = AesGcmFileRead::new(raw_reader, cipher, aad_prefix, 
raw_meta.size)?;
+        let decrypting = AesGcmFileRead::new(raw_reader, cipher, aad_prefix, 
encrypted_length)?;
         Ok(Box::new(decrypting))
     }
 
+    fn encrypted_length(&self) -> Result<u64> {

Review Comment:
   Please add comments to this method to explain why this change.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to