summaryrefslogtreecommitdiffstats
path: root/luni/src/main/java/javax/crypto/Cipher.java
diff options
context:
space:
mode:
Diffstat (limited to 'luni/src/main/java/javax/crypto/Cipher.java')
-rw-r--r--luni/src/main/java/javax/crypto/Cipher.java35
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);
}