bad-antics commented on issue #2035:
URL: https://github.com/apache/iceberg-rust/issues/2035#issuecomment-3832219485
Great addition for the Rust implementation! Looking at the Java Ciphers.java
implementation, here's a suggested approach for Rust:
**AES-GCM utilities in Rust:**
```rust
use aes_gcm::{
aead::{Aead, KeyInit},
Aes256Gcm, Nonce
};
pub struct IcebergCipher {
cipher: Aes256Gcm,
}
impl IcebergCipher {
const NONCE_SIZE: usize = 12;
const TAG_SIZE: usize = 16;
pub fn new(key: &[u8; 32]) -> Self {
Self {
cipher: Aes256Gcm::new(key.into()),
}
}
pub fn encrypt(&self, plaintext: &[u8], aad: &[u8]) -> Result<Vec<u8>,
Error> {
let nonce = generate_nonce();
let mut ciphertext = self.cipher
.encrypt(&nonce.into(), plaintext)?;
// Prepend nonce to ciphertext (matching Java impl)
let mut result = nonce.to_vec();
result.append(&mut ciphertext);
Ok(result)
}
pub fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>, Error> {
let (nonce, encrypted) = ciphertext.split_at(Self::NONCE_SIZE);
self.cipher.decrypt(nonce.into(), encrypted)
}
}
```
**Dependencies:**
```toml
aes-gcm = "0.10"
rand = "0.8"
```
Key considerations:
- Match Java's nonce/IV handling for interoperability
- Use `ring` or `aes-gcm` crate
- Consider async variants for large files
Happy to help contribute!
--
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]