rdblue commented on code in PR #3231:
URL: https://github.com/apache/iceberg/pull/3231#discussion_r1292844218
##########
core/src/main/java/org/apache/iceberg/encryption/Ciphers.java:
##########
@@ -53,29 +70,61 @@ public AesGcmEncryptor(byte[] keyBytes) {
}
this.randomGenerator = new SecureRandom();
+ this.nonce = new byte[NONCE_LENGTH];
}
- public byte[] encrypt(byte[] plainText, byte[] aad) {
- byte[] nonce = new byte[NONCE_LENGTH];
- randomGenerator.nextBytes(nonce);
- int cipherTextLength = NONCE_LENGTH + plainText.length + GCM_TAG_LENGTH;
+ public byte[] encrypt(byte[] plaintext, byte[] aad) {
+ return encrypt(plaintext, 0, plaintext.length, aad);
+ }
+
+ public byte[] encrypt(byte[] plaintext, int plaintextOffset, int
plaintextLength, byte[] aad) {
+ int cipherTextLength = NONCE_LENGTH + plaintextLength + GCM_TAG_LENGTH;
byte[] cipherText = new byte[cipherTextLength];
+ encrypt(plaintext, plaintextOffset, plaintextLength, cipherText, 0, aad);
+ return cipherText;
+ }
+
+ public int encrypt(
+ byte[] plaintext,
+ int plaintextOffset,
+ int plaintextLength,
+ byte[] ciphertextBuffer,
+ int ciphertextOffset,
+ byte[] aad) {
+ Preconditions.checkArgument(plaintextLength > 0, "Wrong plaintextLength
" + plaintextLength);
Review Comment:
We typically use `Invalid plain text length: %s`:
* "Invalid" is used more often and signals that the value cannot be used,
while "wrong" could indicate that the value was not equal to some expected
value or failed a different type of check.
* Variable names like `plaintextLength` aren't helpful to people reading
error messages because they aren't familiar with this code. Using plain English
to describe the problem is better.
--
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]