8266103: Better specified spec values

Reviewed-by: mullan, rhalade, mschoene
This commit is contained in:
Valerie Peng 2021-06-03 22:42:55 +00:00 committed by Henry Jen
parent dd199ee063
commit 470e8a0fda
3 changed files with 20 additions and 9 deletions

View file

@ -157,13 +157,16 @@ public class SecretKeySpec implements KeySpec, SecretKey {
if (key.length == 0) {
throw new IllegalArgumentException("Empty key");
}
if (key.length-offset < len) {
throw new IllegalArgumentException
("Invalid offset/length combination");
if (offset < 0) {
throw new ArrayIndexOutOfBoundsException("offset is negative");
}
if (len < 0) {
throw new ArrayIndexOutOfBoundsException("len is negative");
}
if (key.length - offset < len) {
throw new IllegalArgumentException
("Invalid offset/length combination");
}
this.key = new byte[len];
System.arraycopy(key, offset, this.key, 0, len);
this.algorithm = algorithm;