ggershinsky commented on code in PR #3231:
URL: https://github.com/apache/iceberg/pull/3231#discussion_r1265042174


##########
core/src/main/java/org/apache/iceberg/encryption/AesGcmInputStream.java:
##########
@@ -0,0 +1,218 @@
+/*
+ * 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.
+ */
+
+package org.apache.iceberg.encryption;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.Arrays;
+import org.apache.iceberg.io.SeekableInputStream;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+
+public class AesGcmInputStream extends SeekableInputStream {
+  private final SeekableInputStream sourceStream;
+  private final boolean emptyCipherStream;
+  private final long netSourceFileSize;
+  private final Ciphers.AesGcmDecryptor gcmDecryptor;
+  private final byte[] ciphertextBlockBuffer;
+  private final int cipherBlockSize;
+  private final int plainBlockSize;
+  private final int numberOfBlocks;
+  private final int lastCipherBlockSize;
+  private final long plainStreamSize;
+  private final byte[] fileAadPrefix;
+
+  private long plainStreamPosition;
+  private int currentBlockIndex;
+  private int currentOffsetInPlainBlock;
+
+  AesGcmInputStream(SeekableInputStream sourceStream, long sourceLength,
+                    byte[] aesKey, byte[] fileAadPrefix) throws IOException {
+    this.netSourceFileSize = sourceLength - Ciphers.GCM_STREAM_PREFIX_LENGTH;
+    Preconditions.checkArgument(netSourceFileSize >= 0,
+        "Source length " + sourceLength + " is shorter than GCM prefix. File 
is not encrypted");

Review Comment:
   I've tried this, and ran into the following issue. If the execution has 
reached this place, it means we expect an encrypted file (for example - reading 
manifests with non-null key_metadata). Maybe we should be stricter here, and 
simply throw an exception for empty cipher streams; these classes are designed 
for encryption of non-empty content; also, this will help to detect wrong 
situations earlier. What do you think?



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