mbutrovich commented on code in PR #3700:
URL: https://github.com/apache/iceberg-rust/pull/3700#discussion_r4591068547


##########
crates/iceberg/src/encryption/stream.rs:
##########
@@ -91,6 +91,29 @@ pub(crate) fn stream_block_aad(aad_prefix: &[u8], 
block_index: u32) -> Vec<u8> {
     }
 }
 
+/// Checks that `header` is an AGS1 header declaring the supported plaintext 
block size.
+fn check_stream_header(header: &[u8]) -> Result<()> {
+    let (magic, plain_block_size) = header.split_at(GCM_STREAM_MAGIC.len());
+    if magic != GCM_STREAM_MAGIC {
+        return Err(invalid_data!(
+            "Invalid AGS1 header: magic \"{}\" does not match \"AGS1\"",
+            magic.escape_ascii()
+        ));
+    }
+
+    let plain_block_size = u32::from_le_bytes(
+        plain_block_size
+            .try_into()
+            .map_err(|_| invalid_data!("Invalid AGS1 header length: {}", 
header.len()))?,
+    );

Review Comment:
   Even better!



-- 
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