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

@ -132,6 +132,7 @@ final class ProviderConfig {
return (provider != null);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
@ -144,8 +145,9 @@ final class ProviderConfig {
}
@Override
public int hashCode() {
return provName.hashCode() + argument.hashCode();
return Objects.hash(provName, argument);
}
public String toString() {

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,8 @@
package sun.security.pkcs;
import java.io.*;
import java.util.Arrays;
import sun.security.x509.*;
import sun.security.util.DerValue;
import sun.security.util.DerOutputStream;
@ -134,33 +136,20 @@ public class EncryptedPrivateKeyInfo {
return this.encoded.clone();
}
public boolean equals(Object other) {
if (this == other)
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
if (!(other instanceof EncryptedPrivateKeyInfo))
return false;
byte[] thisEncrInfo = this.getEncoded();
byte[] otherEncrInfo
= ((EncryptedPrivateKeyInfo) other).getEncoded();
if (thisEncrInfo.length != otherEncrInfo.length)
return false;
for (int i = 0; i < thisEncrInfo.length; i++)
if (thisEncrInfo[i] != otherEncrInfo[i])
return false;
return true;
}
return obj instanceof EncryptedPrivateKeyInfo other
&& Arrays.equals(this.getEncoded(), other.getEncoded());
}
/**
* Returns a hashcode for this EncryptedPrivateKeyInfo.
*
* @return a hashcode for this EncryptedPrivateKeyInfo.
* {@return a hashcode for this EncryptedPrivateKeyInfo}
*/
@Override
public int hashCode() {
int retval = 0;
for (int i = 0; i < this.encryptedData.length; i++)
retval += this.encryptedData[i] * i;
return retval;
return Arrays.hashCode(encryptedData);
}
}

View file

@ -259,6 +259,7 @@ public class PKCS8Key implements PrivateKey, InternalPrivateKey {
* @return {@code true} if this key has the same encoding as the
* object argument; {@code false} otherwise.
*/
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
@ -288,6 +289,7 @@ public class PKCS8Key implements PrivateKey, InternalPrivateKey {
* Calculates a hash code value for this object. Objects
* which are equal will also have the same hashcode.
*/
@Override
public int hashCode() {
return Arrays.hashCode(getEncodedInternal());
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 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
@ -32,6 +32,7 @@ import java.math.BigInteger;
import java.security.*;
import java.util.Arrays;
import java.util.Base64;
import sun.security.util.*;
@ -324,41 +325,37 @@ public class PKCS10 {
/**
* Compares this object for equality with the specified
* object. If the <code>other</code> object is an
* object. If the <code>obj</code> object is an
* <code>instanceof</code> <code>PKCS10</code>, then
* its encoded form is retrieved and compared with the
* encoded form of this certificate request.
*
* @param other the object to test for equality with this object.
* @param obj the object to test for equality with this object.
* @return true iff the encoded forms of the two certificate
* requests match, false otherwise.
*/
public boolean equals(Object other) {
if (this == other)
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!(other instanceof PKCS10))
if (!(obj instanceof PKCS10 other))
return false;
if (encoded == null) // not signed yet
return false;
byte[] otherEncoded = ((PKCS10)other).getEncoded();
byte[] otherEncoded = other.getEncoded();
if (otherEncoded == null)
return false;
return java.util.Arrays.equals(encoded, otherEncoded);
return Arrays.equals(encoded, otherEncoded);
}
/**
* Returns a hashcode value for this certificate request from its
* encoded form.
*
* @return the hashcode value.
* {@return the hashcode value for this certificate request from its
* encoded form}
*/
@Override
public int hashCode() {
int retval = 0;
if (encoded != null)
for (int i = 1; i < encoded.length; i++)
retval += encoded[i] * i;
return(retval);
return Arrays.hashCode(encoded);
}
private X500Name subject;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -153,6 +153,7 @@ public class PKCS10Attributes implements DerEncoder {
* @return true if all the entries match that of the Other,
* false otherwise.
*/
@Override
public boolean equals(Object other) {
if (this == other)
return true;
@ -166,26 +167,24 @@ public class PKCS10Attributes implements DerEncoder {
int len = attrs.length;
if (len != map.size())
return false;
PKCS10Attribute thisAttr, otherAttr;
PKCS10Attribute thisAttr;
String key;
for (int i=0; i < len; i++) {
otherAttr = attrs[i];
for (PKCS10Attribute otherAttr : attrs) {
key = otherAttr.getAttributeId().toString();
thisAttr = map.get(key);
if (thisAttr == null)
return false;
if (! thisAttr.equals(otherAttr))
if (!thisAttr.equals(otherAttr))
return false;
}
return true;
}
/**
* Returns a hashcode value for this PKCS10Attributes.
*
* @return the hashcode value.
* {@return the hashcode value for this PKCS10Attributes}
*/
@Override
public int hashCode() {
return map.hashCode();
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -2129,17 +2129,11 @@ public class PolicyFile extends java.security.Policy {
}
/**
* Returns the hash code value for this object.
*
* @return a hash code value for this object.
* {@return the hash code value for this object}
*/
@Override public int hashCode() {
int hash = type.hashCode();
if (name != null)
hash ^= name.hashCode();
if (actions != null)
hash ^= actions.hashCode();
return hash;
return type.hashCode() ^ Objects.hashCode(name)
^ Objects.hashCode(actions);
}
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -1058,9 +1058,7 @@ public class PolicyParser {
}
/**
* Return a hashcode for this PrincipalEntry.
*
* @return a hashcode for this PrincipalEntry
* {@return a hashcode for this PrincipalEntry}
*/
@Override
public int hashCode() {
@ -1119,10 +1117,7 @@ public class PolicyParser {
*/
@Override
public int hashCode() {
int retval = permission.hashCode();
if (name != null) retval ^= name.hashCode();
if (action != null) retval ^= action.hashCode();
return retval;
return Objects.hash(permission, name, action);
}
@Override
@ -1130,32 +1125,11 @@ public class PolicyParser {
if (obj == this)
return true;
if (! (obj instanceof PermissionEntry that))
return false;
if (this.permission == null) {
if (that.permission != null) return false;
} else {
if (!this.permission.equals(that.permission)) return false;
}
if (this.name == null) {
if (that.name != null) return false;
} else {
if (!this.name.equals(that.name)) return false;
}
if (this.action == null) {
if (that.action != null) return false;
} else {
if (!this.action.equals(that.action)) return false;
}
if (this.signedBy == null) {
return that.signedBy == null;
} else {
return this.signedBy.equals(that.signedBy);
}
return obj instanceof PermissionEntry that
&& Objects.equals(this.permission, that.permission)
&& Objects.equals(this.name, that.name)
&& Objects.equals(this.action, that.action)
&& Objects.equals(this.signedBy, that.signedBy);
}
public void write(PrintWriter out) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 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
@ -172,19 +172,13 @@ public class CertId implements DerEncoder {
}
/**
* Returns a hashcode value for this CertId.
*
* @return the hashcode value.
* {@return a hashcode value for this CertId}
*/
@Override public int hashCode() {
if (myhash == -1) {
myhash = hashAlgId.hashCode();
for (int i = 0; i < issuerNameHash.length; i++) {
myhash += issuerNameHash[i] * i;
}
for (int i = 0; i < issuerKeyHash.length; i++) {
myhash += issuerKeyHash[i] * i;
}
myhash += Arrays.hashCode(issuerNameHash);
myhash += Arrays.hashCode(issuerKeyHash);
myhash += certSerialNumber.getNumber().hashCode();
}
return myhash;

View file

@ -226,25 +226,16 @@ public final class ResponderId {
*/
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (this == obj) {
return true;
}
if (obj instanceof ResponderId respObj) {
return Arrays.equals(encodedRid, respObj.getEncoded());
}
return false;
return obj instanceof ResponderId respObj
&& Arrays.equals(encodedRid, respObj.getEncoded());
}
/**
* Returns the hash code value for this {@code ResponderId}
*
* @return the hash code value for this {@code ResponderId}
* {@return the hash code value for this {@code ResponderId}}
*/
@Override
public int hashCode() {

View file

@ -985,7 +985,7 @@ final class SSLSessionImpl extends ExtendedSSLSession {
}
/**
* Returns the hashcode for this session
* {@return the hashcode for this session}
*/
@Override
public int hashCode() {
@ -1002,12 +1002,9 @@ final class SSLSessionImpl extends ExtendedSSLSession {
return true;
}
if (obj instanceof SSLSessionImpl sess) {
return (sessionId != null) && (sessionId.equals(
sess.getSessionId()));
}
return false;
return obj instanceof SSLSessionImpl other
&& sessionId != null
&& sessionId.equals(other.getSessionId());
}

View file

@ -5315,13 +5315,15 @@ class Pair<A, B> {
return "Pair[" + fst + "," + snd + "]";
}
public boolean equals(Object other) {
@Override
public boolean equals(Object obj) {
return
other instanceof Pair &&
Objects.equals(fst, ((Pair)other).fst) &&
Objects.equals(snd, ((Pair)other).snd);
obj instanceof Pair<?, ?> other &&
Objects.equals(fst, other.fst) &&
Objects.equals(snd, other.snd);
}
@Override
public int hashCode() {
if (fst == null) return (snd == null) ? 0 : snd.hashCode() + 1;
else if (snd == null) return fst.hashCode() + 2;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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 sun.security.util;
import java.io.ByteArrayOutputStream;
import java.util.Arrays;
import jdk.internal.util.Preconditions;
@ -68,7 +69,7 @@ public class BitArray {
* Creates a BitArray of the specified size, initialized from the
* specified byte array. The most significant bit of {@code a[0]} gets
* index zero in the BitArray. The array must be large enough to specify
* a value for every bit of the BitArray. i.e. {@code 8*a.length <= length}.
* a value for every bit of the BitArray, i.e. {@code 8*a.length >= length}.
*/
public BitArray(int length, byte[] a) throws IllegalArgumentException {
this(length, a, 0);
@ -79,7 +80,7 @@ public class BitArray {
* specified byte array starting at the specified offset. The most
* significant bit of {@code a[ofs]} gets index zero in the BitArray.
* The array must be large enough to specify a value for every bit of
* the BitArray, i.e. {@code 8*(a.length - ofs) <= length}.
* the BitArray, i.e. {@code 8*(a.length - ofs) >= length}.
*/
public BitArray(int length, byte[] a, int ofs)
throws IllegalArgumentException {
@ -177,16 +178,13 @@ public class BitArray {
return repn.clone();
}
@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (!(obj instanceof BitArray ba)) return false;
if (ba.length != length) return false;
for (int i = 0; i < repn.length; i += 1) {
if (repn[i] != ba.repn[i]) return false;
}
return true;
return obj instanceof BitArray other
&& length == other.length
&& Arrays.equals(repn, other.repn);
}
/**
@ -202,17 +200,11 @@ public class BitArray {
}
/**
* Returns a hash code value for this bit array.
*
* @return a hash code value for this bit array.
* {@return a hash code value for this bit array}
*/
@Override
public int hashCode() {
int hashCode = 0;
for (int i = 0; i < repn.length; i++)
hashCode = 31*hashCode + repn[i];
return hashCode ^ length;
return Arrays.hashCode(repn) ^ length;
}

View file

@ -1261,9 +1261,7 @@ public class DerValue {
}
/**
* Returns a hashcode for this DerValue.
*
* @return a hashcode for this DerValue.
* {@return a hashcode for this DerValue}
*/
@Override
public int hashCode() {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 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
@ -596,6 +596,7 @@ public class AVA implements DerEncoder {
this(in.getDerValue());
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
@ -608,10 +609,9 @@ public class AVA implements DerEncoder {
}
/**
* Returns a hashcode for this AVA.
*
* @return a hashcode for this AVA.
* {@return a hashcode for this AVA}
*/
@Override
public int hashCode() {
return toRFC2253CanonicalString().hashCode();
}

View file

@ -339,9 +339,7 @@ public class AlgorithmId implements Serializable, DerEncoder {
}
/**
* Returns a hashcode for this AlgorithmId.
*
* @return a hashcode for this AlgorithmId.
* {@return a hashcode for this AlgorithmId}
*/
@Override
public int hashCode() {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -218,6 +218,7 @@ public class CRLExtensions {
* @return true iff all the entries match that of the Other,
* false otherwise.
*/
@Override
public boolean equals(Object other) {
if (this == other)
return true;
@ -242,10 +243,9 @@ public class CRLExtensions {
}
/**
* Returns a hashcode value for this CRLExtensions.
*
* @return the hashcode value.
* {@return a hashcode value for this CRLExtensions}
*/
@Override
public int hashCode() {
return map.hashCode();
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -247,6 +247,7 @@ public class CertificateExtensions implements DerEncoder {
* @return true iff all the entries match that of the Other,
* false otherwise.
*/
@Override
public boolean equals(Object other) {
if (this == other)
return true;
@ -272,12 +273,11 @@ public class CertificateExtensions implements DerEncoder {
}
/**
* Returns a hashcode value for this CertificateExtensions.
*
* @return the hashcode value.
* {@return a hashcode value for this CertificateExtensions}
*/
@Override
public int hashCode() {
return map.hashCode() + getUnparseableExtensions().hashCode();
return Objects.hash(map, getUnparseableExtensions());
}
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -92,18 +92,16 @@ public class CertificatePolicyId implements DerEncoder {
*
* @return true iff the ids are identical.
*/
public boolean equals(Object other) {
if (other instanceof CertificatePolicyId)
return id.equals(((CertificatePolicyId) other).getIdentifier());
else
return false;
@Override
public boolean equals(Object obj) {
return obj instanceof CertificatePolicyId other
&& id.equals(other.getIdentifier());
}
/**
* Returns a hash code value for this object.
*
* @return a hash code value
* {@return a hash code value for this object}
*/
@Override
public int hashCode() {
return id.hashCode();
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -169,6 +169,7 @@ public class DNSName implements GeneralNameInterface {
* @return true iff the names are equivalent
* according to RFC5280.
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
@ -182,10 +183,9 @@ public class DNSName implements GeneralNameInterface {
}
/**
* Returns the hash code value for this object.
*
* @return a hash code value for this object.
* {@return the hash code value for this object}
*/
@Override
public int hashCode() {
return name.toUpperCase(Locale.ENGLISH).hashCode();
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 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
@ -325,6 +325,7 @@ public class DistributionPoint implements DerEncoder {
* @param obj Object to be compared to this
* @return true if objects match; false otherwise
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
@ -339,26 +340,14 @@ public class DistributionPoint implements DerEncoder {
&& Arrays.equals(this.reasonFlags, other.reasonFlags);
}
@Override
public int hashCode() {
int hash = hashCode;
if (hash == 0) {
hash = 1;
if (fullName != null) {
hash += fullName.hashCode();
}
if (relativeName != null) {
hash += relativeName.hashCode();
}
if (crlIssuer != null) {
hash += crlIssuer.hashCode();
}
if (reasonFlags != null) {
for (int i = 0; i < reasonFlags.length; i++) {
if (reasonFlags[i]) {
hash += i;
}
}
}
hash = 1 + Objects.hashCode(fullName)
+ Objects.hashCode(relativeName)
+ Objects.hash(crlIssuer)
+ Arrays.hashCode(reasonFlags);
hashCode = hash;
}
return hash;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 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
@ -192,6 +192,7 @@ public class DistributionPointName implements DerEncoder {
* @param obj Object to be compared to this
* @return true if objects match; false otherwise
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
@ -205,17 +206,15 @@ public class DistributionPointName implements DerEncoder {
}
/**
* Returns the hash code for this distribution point name.
*
* @return the hash code.
* {@return the hash code for this distribution point name}
*/
@Override
public int hashCode() {
int hash = hashCode;
if (hash == 0) {
hash = 1;
if (fullName != null) {
hash += fullName.hashCode();
} else {
hash += relativeName.hashCode();
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -170,30 +170,20 @@ public class EDIPartyName implements GeneralNameInterface {
*
* @return true if the two names match
*/
public boolean equals(Object other) {
if (!(other instanceof EDIPartyName))
return false;
String otherAssigner = ((EDIPartyName)other).assigner;
if (this.assigner == null) {
if (otherAssigner != null)
return false;
} else {
if (!(this.assigner.equals(otherAssigner)))
return false;
}
String otherParty = ((EDIPartyName)other).party;
if (this.party == null) {
return otherParty == null;
} else {
return this.party.equals(otherParty);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
return obj instanceof EDIPartyName other
&& Objects.equals(this.assigner, other.assigner)
&& Objects.equals(this.party, other.party);
}
/**
* Returns the hash code value for this EDIPartyName.
*
* @return a hash code value.
* {@return the hash code value for this EDIPartyName}
*/
@Override
public int hashCode() {
if (myhash == -1) {
myhash = 37 + (party == null ? 1 : party.hashCode());

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -242,20 +242,13 @@ public class Extension implements java.security.cert.Extension, DerEncoder {
private static final int hashMagic = 31;
/**
* Returns a hashcode value for this Extension.
*
* @return the hashcode value.
* {@return a hashcode value for this Extension}
*/
@Override
public int hashCode() {
int h = 0;
if (extensionValue != null) {
byte[] val = extensionValue;
int len = val.length;
while (len > 0)
h += len * val[--len];
}
int h = Arrays.hashCode(extensionValue);
h = h * hashMagic + extensionId.hashCode();
h = h * hashMagic + (critical?1231:1237);
h = h * hashMagic + Boolean.hashCode(critical);
return h;
}
@ -271,6 +264,7 @@ public class Extension implements java.security.cert.Extension, DerEncoder {
* criticality flag, object identifier and encoded extension value of
* the two Extensions match, false otherwise.
*/
@Override
public boolean equals(Object other) {
if (this == other)
return true;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -201,28 +201,28 @@ public class GeneralName implements DerEncoder {
/**
* Compare this GeneralName with another
*
* @param other GeneralName to compare to this
* @param obj GeneralName to compare to this
* @return true if match
*/
public boolean equals(Object other) {
if (this == other) {
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(other instanceof GeneralName))
if (!(obj instanceof GeneralName other))
return false;
GeneralNameInterface otherGNI = ((GeneralName)other).name;
try {
return name.constrains(otherGNI) == GeneralNameInterface.NAME_MATCH;
return name.constrains(other.name)
== GeneralNameInterface.NAME_MATCH;
} catch (UnsupportedOperationException ioe) {
return false;
}
}
/**
* Returns the hash code for this GeneralName.
*
* @return a hash code value.
* {@return the hash code for this GeneralName}
*/
@Override
public int hashCode() {
return name.hashCode();
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -149,30 +149,24 @@ public class GeneralSubtree implements DerEncoder {
/**
* Compare this GeneralSubtree with another
*
* @param other GeneralSubtree to compare to this
* @param obj GeneralSubtree to compare to this
* @return true if match
*/
public boolean equals(Object other) {
if (!(other instanceof GeneralSubtree otherGS))
return false;
if (this.name == null) {
if (otherGS.name != null) {
return false;
}
} else {
if (!((this.name).equals(otherGS.name)))
return false;
}
if (this.minimum != otherGS.minimum)
return false;
return this.maximum == otherGS.maximum;
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
return obj instanceof GeneralSubtree other
&& Objects.equals(this.name, other.name)
&& this.minimum == other.minimum
&& this.maximum == other.maximum;
}
/**
* Returns the hash code for this GeneralSubtree.
*
* @return a hash code value.
* {@return the hash code for this GeneralSubtree}
*/
@Override
public int hashCode() {
if (myhash == -1) {
myhash = 17;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -310,6 +310,7 @@ public class IPAddressName implements GeneralNameInterface {
*
* @return true iff the names are identical.
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
@ -334,10 +335,8 @@ public class IPAddressName implements GeneralNameInterface {
}
}
// Now compare masks
for (int i=maskLen; i < address.length; i++)
if (address[i] != other[i])
return false;
return true;
return Arrays.equals(address, maskLen, address.length, other,
maskLen, address.length);
} else {
// Two IPv4 host addresses or two IPv6 host addresses
// Compare bytes
@ -346,17 +345,11 @@ public class IPAddressName implements GeneralNameInterface {
}
/**
* Returns the hash code value for this object.
*
* @return a hash code value for this object.
* {@return the hash code value for this object}
*/
@Override
public int hashCode() {
int retval = 0;
for (int i=0; i<address.length; i++)
retval += address[i] * i;
return retval;
return Arrays.hashCode(address);
}
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -29,6 +29,7 @@ import java.io.IOException;
import java.security.PublicKey;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import sun.security.util.HexDumpEncoder;
import sun.security.util.*;
@ -133,22 +134,19 @@ public class KeyIdentifier {
* Returns a hash code value for this object.
* Objects that are equal will also have the same hashcode.
*/
@Override
public int hashCode () {
int retval = 0;
for (int i = 0; i < octetString.length; i++)
retval += octetString[i] * i;
return retval;
return Arrays.hashCode(octetString);
}
/**
* Indicates whether some other object is "equal to" this one.
*/
public boolean equals(Object other) {
if (this == other)
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!(other instanceof KeyIdentifier))
return false;
byte[] otherString = ((KeyIdentifier)other).octetString;
return java.util.Arrays.equals(octetString, otherString);
return obj instanceof KeyIdentifier other
&& Arrays.equals(octetString, other.octetString);
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -111,21 +111,19 @@ public class OIDName implements GeneralNameInterface {
*
* @return true iff the names are identical
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!(obj instanceof OIDName other))
return false;
return oid.equals(other.oid);
return obj instanceof OIDName other
&& oid.equals(other.oid);
}
/**
* Returns the hash code value for this object.
*
* @return a hash code value for this object.
* {@return the hash code value for this object}
*/
@Override
public int hashCode() {
return oid.hashCode();
}

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
@ -171,6 +171,7 @@ public class OtherName implements GeneralNameInterface {
*
* @return true iff the names are identical.
*/
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
@ -203,16 +204,12 @@ public class OtherName implements GeneralNameInterface {
}
/**
* Returns the hash code for this OtherName.
*
* @return a hash code value.
* {@return the hash code for this OtherName}
*/
@Override
public int hashCode() {
if (myhash == -1) {
myhash = 37 + oid.hashCode();
for (int i = 0; i < nameValue.length; i++) {
myhash = 37 * myhash + nameValue[i];
}
myhash = oid.hashCode() + Arrays.hashCode(nameValue);
}
return myhash;
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 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
@ -122,28 +122,22 @@ public class PolicyInformation implements DerEncoder {
/**
* Compare this PolicyInformation with another object for equality
*
* @param other object to be compared with this
* @param obj object to be compared with this
* @return true iff the PolicyInformation objects match
*/
public boolean equals(Object other) {
if (!(other instanceof PolicyInformation piOther))
return false;
if (!policyIdentifier.equals(piOther.getPolicyIdentifier()))
return false;
return policyQualifiers.equals(piOther.getPolicyQualifiers());
@Override
public boolean equals(Object obj) {
return obj instanceof PolicyInformation other
&& policyIdentifier.equals(other.getPolicyIdentifier())
&& policyQualifiers.equals(other.getPolicyQualifiers());
}
/**
* Returns the hash code for this PolicyInformation.
*
* @return a hash code value.
* {@return the hash code for this PolicyInformation}
*/
@Override
public int hashCode() {
int myhash = 37 + policyIdentifier.hashCode();
myhash = 37 * myhash + policyQualifiers.hashCode();
return myhash;
return Objects.hash(policyIdentifier, policyQualifiers);
}
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -133,6 +133,7 @@ public class RFC822Name implements GeneralNameInterface
* @return true iff the names are equivalent
* according to RFC 5280.
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
@ -146,10 +147,9 @@ public class RFC822Name implements GeneralNameInterface
}
/**
* Returns the hash code value for this object.
*
* @return a hash code value for this object.
* {@return the hash code value for this object}
*/
@Override
public int hashCode() {
return name.toUpperCase(Locale.ENGLISH).hashCode();
}

View file

@ -215,6 +215,7 @@ public class URIName implements GeneralNameInterface {
*
* @return true iff the names are equivalent according to RFC 5280.
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
@ -275,10 +276,9 @@ public class URIName implements GeneralNameInterface {
}
/**
* Returns the hash code value for this object.
*
* @return a hash code value for this object.
* {@return the hash code value for this object}
*/
@Override
public int hashCode() {
return uri.hashCode();
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 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
@ -395,6 +395,7 @@ public class X500Name implements GeneralNameInterface, Principal {
* Calculates a hash code value for the object. Objects
* which are equal will also have the same hashcode.
*/
@Override
public int hashCode() {
return getRFC2253CanonicalName().hashCode();
}
@ -404,6 +405,7 @@ public class X500Name implements GeneralNameInterface, Principal {
*
* @return true iff the names are identical.
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;

View file

@ -1296,6 +1296,7 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
* @param o the other object to compare with
* @return true if equal, false otherwise
*/
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
@ -1310,16 +1311,13 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
}
/**
* Returns a hash code value for this X509IssuerSerial.
*
* @return the hash code value
* {@return a hash code value for this X509IssuerSerial}
*/
@Override
public int hashCode() {
int h = hashcode;
if (h == 0) {
h = 17;
h = 37*h + issuer.hashCode();
h = 37*h + serial.hashCode();
h = Objects.hash(issuer, serial);
if (h != 0) {
hashcode = h;
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -179,51 +179,27 @@ public class X509CertInfo {
* certificates are not both X.509 certs, otherwise it
* compares them as binary data.
*
* @param other the object being compared with this one
* @param obj the object being compared with this one
* @return true iff the certificates are equivalent
*/
public boolean equals(Object other) {
if (other instanceof X509CertInfo) {
return equals((X509CertInfo) other);
} else {
return false;
}
}
/**
* Compares two certificates, returning false if any data
* differs between the two.
*
* @param other the object being compared with this one
* @return true iff the certificates are equivalent
*/
public boolean equals(X509CertInfo other) {
if (this == other) {
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (rawCertInfo == null || other.rawCertInfo == null) {
return false;
} else if (rawCertInfo.length != other.rawCertInfo.length) {
return false;
}
for (int i = 0; i < rawCertInfo.length; i++) {
if (rawCertInfo[i] != other.rawCertInfo[i]) {
return false;
}
}
return true;
return obj instanceof X509CertInfo other
&& rawCertInfo != null
&& other.rawCertInfo != null
&& Arrays.equals(rawCertInfo, other.rawCertInfo);
}
/**
* Calculates a hash code value for the object. Objects
* which are equal will also have the same hashcode.
*/
@Override
public int hashCode() {
int retval = 0;
for (int i = 1; i < rawCertInfo.length; i++) {
retval += rawCertInfo[i] * i;
}
return retval;
return Arrays.hashCode(rawCertInfo);
}
/**

View file

@ -36,6 +36,7 @@ import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import java.util.Objects;
import sun.security.util.HexDumpEncoder;
import sun.security.util.*;
@ -398,6 +399,7 @@ public class X509Key implements PublicKey, DerEncoder {
}
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
@ -419,13 +421,9 @@ public class X509Key implements PublicKey, DerEncoder {
* Calculates a hash code value for the object. Objects
* which are equal will also have the same hashcode.
*/
@Override
public int hashCode() {
byte[] b1 = getEncodedInternal();
int r = b1.length;
for (int i = 0; i < b1.length; i++) {
r += (b1[i] & 0xff) * 37;
}
return r;
return Arrays.hashCode(getEncodedInternal());
}
/*