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


##########
crates/iceberg/src/encryption/crypto.rs:
##########
@@ -0,0 +1,383 @@
+// 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.
+
+//! Core cryptographic operations for Iceberg encryption.
+
+use std::str::FromStr;
+
+use aes_gcm::aead::generic_array::typenum::Unsigned;
+use aes_gcm::aead::{Aead, AeadCore, KeyInit, KeySizeUser, OsRng, Payload};
+use aes_gcm::{Aes128Gcm, Key, Nonce};
+use rand::RngCore;
+use zeroize::Zeroizing;
+
+use crate::{Error, ErrorKind, Result};
+
+/// Supported encryption algorithm.
+/// Currently only AES-128-GCM is supported as it's the only algorithm
+/// compatible with arrow-rs Parquet encryption.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum EncryptionAlgorithm {
+    /// AES-128 in GCM mode
+    Aes128Gcm,
+}
+
+impl EncryptionAlgorithm {
+    /// Returns the key length in bytes for this algorithm.
+    pub fn key_length(&self) -> usize {
+        match self {
+            Self::Aes128Gcm => <Aes128Gcm as KeySizeUser>::KeySize::USIZE,
+        }
+    }
+
+    /// Returns the nonce/IV length in bytes for this algorithm.
+    pub fn nonce_length(&self) -> usize {
+        match self {
+            Self::Aes128Gcm => <Aes128Gcm as AeadCore>::NonceSize::USIZE,
+        }
+    }
+
+    /// Returns the string identifier for this algorithm.
+    pub fn as_str(&self) -> &'static str {
+        match self {
+            Self::Aes128Gcm => "AES_GCM_128",
+        }
+    }
+}
+
+impl FromStr for EncryptionAlgorithm {
+    type Err = Error;
+
+    fn from_str(s: &str) -> Result<Self> {
+        match s {
+            "AES_GCM_128" | "AES128_GCM" => Ok(Self::Aes128Gcm),
+            _ => Err(Error::new(
+                ErrorKind::DataInvalid,
+                format!("Unsupported encryption algorithm: {s}"),
+            )),
+        }
+    }
+}
+
+/// A secure encryption key that zeroes its memory on drop.
+pub struct SecureKey {
+    key: Zeroizing<Vec<u8>>,

Review Comment:
   Good, clears it.



##########
crates/iceberg/src/encryption/crypto.rs:
##########
@@ -0,0 +1,383 @@
+// 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.
+
+//! Core cryptographic operations for Iceberg encryption.
+
+use std::str::FromStr;
+
+use aes_gcm::aead::generic_array::typenum::Unsigned;
+use aes_gcm::aead::{Aead, AeadCore, KeyInit, KeySizeUser, OsRng, Payload};
+use aes_gcm::{Aes128Gcm, Key, Nonce};
+use rand::RngCore;
+use zeroize::Zeroizing;
+
+use crate::{Error, ErrorKind, Result};
+
+/// Supported encryption algorithm.
+/// Currently only AES-128-GCM is supported as it's the only algorithm
+/// compatible with arrow-rs Parquet encryption.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum EncryptionAlgorithm {
+    /// AES-128 in GCM mode
+    Aes128Gcm,

Review Comment:
   We're trying to get 256 added to Arrow-rs, this approach should work with 
that?



##########
crates/iceberg/src/encryption/crypto.rs:
##########
@@ -0,0 +1,383 @@
+// 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.
+
+//! Core cryptographic operations for Iceberg encryption.
+
+use std::str::FromStr;
+
+use aes_gcm::aead::generic_array::typenum::Unsigned;
+use aes_gcm::aead::{Aead, AeadCore, KeyInit, KeySizeUser, OsRng, Payload};
+use aes_gcm::{Aes128Gcm, Key, Nonce};
+use rand::RngCore;
+use zeroize::Zeroizing;
+
+use crate::{Error, ErrorKind, Result};
+
+/// Supported encryption algorithm.
+/// Currently only AES-128-GCM is supported as it's the only algorithm
+/// compatible with arrow-rs Parquet encryption.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum EncryptionAlgorithm {
+    /// AES-128 in GCM mode
+    Aes128Gcm,
+}
+
+impl EncryptionAlgorithm {
+    /// Returns the key length in bytes for this algorithm.
+    pub fn key_length(&self) -> usize {
+        match self {
+            Self::Aes128Gcm => <Aes128Gcm as KeySizeUser>::KeySize::USIZE,

Review Comment:
   Same question about 256 for these following functions.



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