8311170: Simplify and modernize equals and hashCode in security area

Reviewed-by: djelinski, rriggs, valeriep
This commit is contained in:
Pavel Rappo 2023-08-09 12:34:40 +00:00
parent e9f751ab16
commit 19ae62ae2c
96 changed files with 567 additions and 951 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,6 +26,7 @@
package javax.crypto.spec;
import java.security.spec.AlgorithmParameterSpec;
import java.util.Arrays;
/**
* This class specifies the parameters used with the
@ -176,6 +177,7 @@ public class RC5ParameterSpec implements AlgorithmParameterSpec {
* @return true if the objects are considered equal, false if
* {@code obj} is null or otherwise.
*/
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
@ -187,21 +189,15 @@ public class RC5ParameterSpec implements AlgorithmParameterSpec {
return ((version == other.version) &&
(rounds == other.rounds) &&
(wordSize == other.wordSize) &&
java.util.Arrays.equals(iv, other.iv));
Arrays.equals(iv, other.iv));
}
/**
* Calculates a hash code value for the object.
* Objects that are equal will also have the same hashcode.
*/
@Override
public int hashCode() {
int retval = 0;
if (iv != null) {
for (int i = 1; i < iv.length; i++) {
retval += iv[i] * i;
}
}
retval += (version + rounds + wordSize);
return retval;
return Arrays.hashCode(iv) + version + rounds + wordSize;
}
}