-
Notifications
You must be signed in to change notification settings - Fork 3k
AES GCM Stream changes #9453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AES GCM Stream changes #9453
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,8 @@ public class AesGcmOutputStream extends PositionOutputStream { | |
| private int currentBlockIndex; | ||
| private boolean isHeaderWritten; | ||
| private boolean lastBlockWritten; | ||
| private boolean isClosed; | ||
| private long finalPosition; | ||
|
|
||
| AesGcmOutputStream(PositionOutputStream targetStream, byte[] aesKey, byte[] fileAadPrefix) { | ||
| this.targetStream = targetStream; | ||
|
|
@@ -56,6 +58,8 @@ public class AesGcmOutputStream extends PositionOutputStream { | |
| this.currentBlockIndex = 0; | ||
| this.isHeaderWritten = false; | ||
| this.lastBlockWritten = false; | ||
| this.isClosed = false; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: initialize
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| this.finalPosition = 0; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -66,6 +70,10 @@ public void write(int b) throws IOException { | |
|
|
||
| @Override | ||
| public void write(byte[] b, int off, int len) throws IOException { | ||
| if (isClosed) { | ||
| throw new IOException("Writing to closed stream"); | ||
| } | ||
|
|
||
| if (!isHeaderWritten) { | ||
| writeHeader(); | ||
| } | ||
|
|
@@ -95,6 +103,10 @@ public void write(byte[] b, int off, int len) throws IOException { | |
|
|
||
| @Override | ||
| public long getPos() throws IOException { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Iceberg manifest writer calls getPos after closing the avro stream. Wrong value was returned. |
||
| if (isClosed) { | ||
| return finalPosition; | ||
| } | ||
|
|
||
| return (long) currentBlockIndex * Ciphers.PLAIN_BLOCK_SIZE + positionInPlainBlock; | ||
| } | ||
|
|
||
|
|
@@ -109,6 +121,9 @@ public void close() throws IOException { | |
| writeHeader(); | ||
| } | ||
|
|
||
| finalPosition = getPos(); | ||
| isClosed = true; | ||
|
|
||
| encryptAndWriteBlock(); | ||
|
|
||
| targetStream.close(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html#read-byte:A-int-int-