Skip to content

Commit

Permalink
Correctly override equals and hashCode for our OpenSslSession sub-typ…
Browse files Browse the repository at this point in the history
…es (#13829)

Motivation:

We did not correct override equals and hashcode methods for some of the
OpenSslSession implementations

Modifications:

Override methods

Result:

Be able to correctly understand if a session is equal or not
  • Loading branch information
normanmaurer authored Feb 8, 2024
1 parent f0e9b40 commit 94d0cfb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.security.cert.Certificate;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
* Delegates all operations to a wrapped {@link OpenSslSession} except the methods defined by {@link ExtendedSSLSession}
Expand Down Expand Up @@ -249,6 +248,16 @@ public void handshakeFinished(byte[] id, String cipher, String protocol, byte[]
wrapped.handshakeFinished(id, cipher, protocol, peerCertificate, peerCertificateChain, creationTime, timeout);
}

@Override
public boolean equals(Object o) {
return wrapped.equals(o);
}

@Override
public int hashCode() {
return wrapped.hashCode();
}

@Override
public String toString() {
return "ExtendedOpenSslSession{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2714,6 +2714,23 @@ public String toString() {
", id=" + id +
'}';
}

@Override
public int hashCode() {
return sessionId().hashCode();
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
// We trust all sub-types as we use different types but the interface is package-private
if (!(o instanceof OpenSslSession)) {
return false;
}
return sessionId().equals(((OpenSslSession) o).sessionId());
}
}

private interface NativeSslException {
Expand Down

0 comments on commit 94d0cfb

Please sign in to comment.