diff options
author | Brian Carlstrom <bdc@google.com> | 2012-05-21 11:55:20 -0700 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2012-05-21 13:18:10 -0700 |
commit | c1e57ed799a4fea200144330823f4acbb5330395 (patch) | |
tree | 3f8dd40c2064529516548e3d0b62b065dc394f09 /luni/src/main/java/javax/crypto/Cipher.java | |
parent | 6b3f9499cf6647263b51741e4187a26a54500072 (diff) | |
download | libcore-c1e57ed799a4fea200144330823f4acbb5330395.zip libcore-c1e57ed799a4fea200144330823f4acbb5330395.tar.gz libcore-c1e57ed799a4fea200144330823f4acbb5330395.tar.bz2 |
Revert "Revert "Cut down on object allocation in CipherInputStream""
This reverts commit 6b3f9499cf6647263b51741e4187a26a54500072.
Bug: 6523748
Bug: 6478569
Change-Id: Ic422e5fa320995600bdae7a42816652e16b8728b
Diffstat (limited to 'luni/src/main/java/javax/crypto/Cipher.java')
-rw-r--r-- | luni/src/main/java/javax/crypto/Cipher.java | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/luni/src/main/java/javax/crypto/Cipher.java b/luni/src/main/java/javax/crypto/Cipher.java index c8cb601..1dacd46 100644 --- a/luni/src/main/java/javax/crypto/Cipher.java +++ b/luni/src/main/java/javax/crypto/Cipher.java @@ -886,17 +886,25 @@ public class Cipher { if (input == null) { throw new IllegalArgumentException("input == null"); } - if (inputOffset < 0 || inputLen < 0 - || inputLen > input.length - || inputOffset > input.length - inputLen) { - throw new IllegalArgumentException("Incorrect inputOffset/inputLen parameters"); - } + checkInputOffsetAndCount(input.length, inputOffset, inputLen); if (input.length == 0) { return null; } return spiImpl.engineUpdate(input, inputOffset, inputLen); } + private static void checkInputOffsetAndCount(int inputArrayLength, + int inputOffset, + int inputLen) { + if ((inputOffset | inputLen) < 0 + || inputOffset > inputArrayLength + || inputArrayLength - inputOffset < inputLen) { + throw new IllegalArgumentException("input.length=" + inputArrayLength + + "; inputOffset=" + inputOffset + + "; inputLen=" + inputLen); + } + } + /** * Continues a multi-part transformation (encryption or decryption). The * transformed bytes are stored in the {@code output} buffer. @@ -972,12 +980,9 @@ public class Cipher { throw new IllegalArgumentException("output == null"); } if (outputOffset < 0) { - throw new IllegalArgumentException("outputOffset < 0"); - } - if (inputOffset < 0 || inputLen < 0 || inputLen > input.length - || inputOffset > input.length - inputLen) { - throw new IllegalArgumentException("Incorrect inputOffset/inputLen parameters"); + throw new IllegalArgumentException("outputOffset < 0. outputOffset=" + outputOffset); } + checkInputOffsetAndCount(input.length, inputOffset, inputLen); if (input.length == 0) { return 0; } @@ -1075,7 +1080,7 @@ public class Cipher { throw new IllegalStateException(); } if (outputOffset < 0) { - throw new IllegalArgumentException("outputOffset < 0"); + throw new IllegalArgumentException("outputOffset < 0. outputOffset=" + outputOffset); } return spiImpl.engineDoFinal(null, 0, 0, output, outputOffset); } @@ -1137,9 +1142,7 @@ public class Cipher { if (mode != ENCRYPT_MODE && mode != DECRYPT_MODE) { throw new IllegalStateException(); } - if (inputOffset < 0 || inputLen < 0 || inputOffset + inputLen > input.length) { - throw new IllegalArgumentException("Incorrect inputOffset/inputLen parameters"); - } + checkInputOffsetAndCount(input.length, inputOffset, inputLen); return spiImpl.engineDoFinal(input, inputOffset, inputLen); } @@ -1217,9 +1220,7 @@ public class Cipher { if (mode != ENCRYPT_MODE && mode != DECRYPT_MODE) { throw new IllegalStateException(); } - if (inputOffset < 0 || inputLen < 0 || inputOffset + inputLen > input.length) { - throw new IllegalArgumentException("Incorrect inputOffset/inputLen parameters"); - } + checkInputOffsetAndCount(input.length, inputOffset, inputLen); return spiImpl.engineDoFinal(input, inputOffset, inputLen, output, outputOffset); } |