Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
*/
package org.apache.iceberg.encryption;

import java.io.IOException;
import java.io.UncheckedIOException;
import org.apache.iceberg.io.InputFile;
import org.apache.iceberg.io.SeekableInputStream;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;

public class AesGcmInputFile implements InputFile {
private final InputFile sourceFile;
Expand All @@ -40,29 +39,20 @@ public AesGcmInputFile(InputFile sourceFile, byte[] dataKey, byte[] fileAADPrefi
public long getLength() {
if (plaintextLength == -1) {
// Presumes all streams use hard-coded plaintext block size.
// Actual plaintext block size is checked upon stream creation (exception if different).
plaintextLength =
AesGcmInputStream.calculatePlaintextLength(
sourceFile.getLength(), AesGcmOutputStream.plainBlockSize);
plaintextLength = AesGcmInputStream.calculatePlaintextLength(sourceFile.getLength());
}

return plaintextLength;
}

@Override
public SeekableInputStream newStream() {
getLength();
AesGcmInputStream result;

try {
result =
new AesGcmInputStream(
sourceFile.newStream(), sourceFile.getLength(), dataKey, fileAADPrefix);
} catch (IOException e) {
throw new UncheckedIOException(e);
}

return result;
long ciphertextLength = sourceFile.getLength();
Preconditions.checkState(
ciphertextLength >= Ciphers.GCM_STREAM_HEADER_LENGTH,
"Invalid encrypted stream: %d is shorter than the GCM stream header length",
ciphertextLength);
return new AesGcmInputStream(sourceFile.newStream(), ciphertextLength, dataKey, fileAADPrefix);
}

@Override
Expand Down
Loading