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


##########
core/src/main/java/org/apache/iceberg/encryption/Ciphers.java:
##########
@@ -101,37 +117,52 @@ public AesGcmDecryptor(byte[] keyBytes) {
     }
 
     public byte[] decrypt(byte[] ciphertext, byte[] aad) {
-      int plainTextLength = ciphertext.length - GCM_TAG_LENGTH - NONCE_LENGTH;
+      return decrypt(ciphertext, 0, ciphertext.length, aad);
+    }
+
+    public byte[] decrypt(
+        byte[] ciphertext, int ciphertextOffset, int ciphertextLength, byte[] 
aad) {
       Preconditions.checkState(
-          plainTextLength >= 1,
+          ciphertextLength - GCM_TAG_LENGTH - NONCE_LENGTH >= 1,
           "Cannot decrypt cipher text of length "
               + ciphertext.length
               + " because text must longer than GCM_TAG_LENGTH + NONCE_LENGTH 
bytes. Text may not be encrypted"
               + " with AES GCM cipher");
 
       // Get the nonce from ciphertext
       byte[] nonce = new byte[NONCE_LENGTH];
-      System.arraycopy(ciphertext, 0, nonce, 0, NONCE_LENGTH);
+      System.arraycopy(ciphertext, ciphertextOffset, nonce, 0, NONCE_LENGTH);
 
-      byte[] plainText = new byte[plainTextLength];
-      int inputLength = ciphertext.length - NONCE_LENGTH;
+      int inputLength = ciphertextLength - NONCE_LENGTH;

Review Comment:
   This looks okay, but I'd want to double check how the tag bytes are handled. 
Here, the length includes the tag bytes so this isn't the same as the plaintext 
length that is used for encryption.



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