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


##########
crates/iceberg/src/encryption/stream.rs:
##########
@@ -0,0 +1,1180 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! AGS1 stream encryption/decryption for Iceberg.
+//!
+//! Implements the block-based AES-GCM stream format used by Iceberg for
+//! encrypting manifest lists and manifest files. The format is
+//! byte-compatible with Java's `AesGcmInputStream` / `AesGcmOutputStream`.
+//!
+//! # AGS1 File Format
+//!
+//! ```text
+//! ┌─────────────────────────────────────────────┐
+//! │ Header (8 bytes)                            │
+//! │   Magic: "AGS1" (4 bytes, ASCII)            │
+//! │   Plain block size: u32 LE (4 bytes)        │
+//! │     Default: 1,048,576 (1 MiB)              │
+//! ├─────────────────────────────────────────────┤
+//! │ Block 0                                     │
+//! │   Nonce (12 bytes)                          │
+//! │   Ciphertext (up to plain_block_size bytes) │
+//! │   GCM Tag (16 bytes)                        │
+//! ├─────────────────────────────────────────────┤
+//! │ Block 1..N (same structure)                 │
+//! ├─────────────────────────────────────────────┤
+//! │ Final block (may be shorter)                │
+//! └─────────────────────────────────────────────┘
+//! ```
+//!
+//! Each block's AAD is: `aad_prefix || block_index (4 bytes, LE)`.
+
+use std::ops::Range;
+use std::sync::Arc;
+
+use bytes::{Bytes, BytesMut};
+
+use super::AesGcmCipher;
+use crate::io::{FileRead, FileWrite};
+use crate::{Error, ErrorKind, Result};
+
+/// Default plaintext block size (1 MiB), matching Java's 
`Ciphers.PLAIN_BLOCK_SIZE`.
+pub const PLAIN_BLOCK_SIZE: u32 = 1024 * 1024;
+
+/// AES-GCM nonce length in bytes.
+pub const NONCE_LENGTH: u32 = 12;
+
+/// AES-GCM authentication tag length in bytes.
+pub const GCM_TAG_LENGTH: u32 = 16;
+
+/// Cipher block size = plaintext block size + nonce + GCM tag.
+pub const CIPHER_BLOCK_SIZE: u32 = PLAIN_BLOCK_SIZE + NONCE_LENGTH + 
GCM_TAG_LENGTH;
+
+/// AGS1 stream magic bytes.
+pub const GCM_STREAM_MAGIC: [u8; 4] = *b"AGS1";
+
+/// AGS1 stream header length (4-byte magic + 4-byte block size).
+pub const GCM_STREAM_HEADER_LENGTH: u32 = 8;
+
+/// Minimum valid AGS1 stream length (header + one empty block).
+#[allow(dead_code)]

Review Comment:
   Can this be `#[cfg(test)]` instead?



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