summaryrefslogtreecommitdiffstats
path: root/luni/src/main/java/javax/crypto
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2010-12-03 16:04:54 -0800
committerElliott Hughes <enh@google.com>2010-12-03 16:53:17 -0800
commitb9cc455ed89df1a0cf4186c92b352c9649995d96 (patch)
tree136be3e17f5e76a9bbd1025ebd506365321650f4 /luni/src/main/java/javax/crypto
parent5f13d2214de3c5904f94462609cfd2268c9b5862 (diff)
downloadlibcore-b9cc455ed89df1a0cf4186c92b352c9649995d96.zip
libcore-b9cc455ed89df1a0cf4186c92b352c9649995d96.tar.gz
libcore-b9cc455ed89df1a0cf4186c92b352c9649995d96.tar.bz2
Use our canonical Arrays range-checking methods.
There are a handful of manual range-checkers left, thanks to specified API that throws IllegalArgumentException instead, and a few other weird cases. Change-Id: I80914c2257288fc184100545aff4fd6f57bf32c9
Diffstat (limited to 'luni/src/main/java/javax/crypto')
-rw-r--r--luni/src/main/java/javax/crypto/spec/IvParameterSpec.java25
-rw-r--r--luni/src/main/java/javax/crypto/spec/RC5ParameterSpec.java2
2 files changed, 10 insertions, 17 deletions
diff --git a/luni/src/main/java/javax/crypto/spec/IvParameterSpec.java b/luni/src/main/java/javax/crypto/spec/IvParameterSpec.java
index eac721d..581ff0d 100644
--- a/luni/src/main/java/javax/crypto/spec/IvParameterSpec.java
+++ b/luni/src/main/java/javax/crypto/spec/IvParameterSpec.java
@@ -22,6 +22,7 @@
package javax.crypto.spec;
import java.security.spec.AlgorithmParameterSpec;
+import java.util.Arrays;
/**
* The algorithm parameter specification for an <i>initialization vector</i>.
@@ -48,32 +49,24 @@ public class IvParameterSpec implements AlgorithmParameterSpec {
}
/**
- * Creates a new <code>IvParameterSpec</code> instance with <code>len</code>
+ * Creates a new <code>IvParameterSpec</code> instance with <code>byteCount</code>
* bytes from the specified buffer <code>iv</code> starting at
* <code>offset</code>.
*
- * @param iv
- * the buffer used as initialization vector.
- * @param offset
- * the offset to start in the buffer.
- * @param len
- * the length of the data.
* @throws IllegalArgumentException
* if the specified buffer is null or <code>offset</code> and
- * <code>len</code> do not specify a valid chunk in the
+ * <code>byteCount</code> do not specify a valid chunk in the
* specified buffer.
* @throws ArrayIndexOutOfBoundsException
- * if <code>offset</code> or <code>len</code> are negative.
+ * if <code>offset</code> or <code>byteCount</code> are negative.
*/
- public IvParameterSpec(byte[] iv, int offset, int len) {
- if ((iv == null) || (iv.length - offset < len)) {
+ public IvParameterSpec(byte[] iv, int offset, int byteCount) {
+ if ((iv == null) || (iv.length - offset < byteCount)) {
throw new IllegalArgumentException();
}
- if (offset < 0 || len < 0) {
- throw new ArrayIndexOutOfBoundsException();
- }
- this.iv = new byte[len];
- System.arraycopy(iv, offset, this.iv, 0, len);
+ Arrays.checkOffsetAndCount(iv.length, offset, byteCount);
+ this.iv = new byte[byteCount];
+ System.arraycopy(iv, offset, this.iv, 0, byteCount);
}
/**
diff --git a/luni/src/main/java/javax/crypto/spec/RC5ParameterSpec.java b/luni/src/main/java/javax/crypto/spec/RC5ParameterSpec.java
index 4726321..08a890f 100644
--- a/luni/src/main/java/javax/crypto/spec/RC5ParameterSpec.java
+++ b/luni/src/main/java/javax/crypto/spec/RC5ParameterSpec.java
@@ -114,7 +114,7 @@ public class RC5ParameterSpec implements AlgorithmParameterSpec {
throw new IllegalArgumentException("iv == null");
}
if (offset < 0) {
- throw new ArrayIndexOutOfBoundsException("offset < 0");
+ throw new ArrayIndexOutOfBoundsException("offset < 0: " + offset);
}
if (iv.length - offset < 2 * (wordSize / 8)) {
throw new IllegalArgumentException("iv.length - offset < 2 * (wordSize / 8)");