Skip to content

Commit 122c03d

Browse files
committed
handle equals/hashCode on SSL::Session and raise on timeout int overflow
1 parent 226a278 commit 122c03d

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/main/java/org/jruby/ext/openssl/SSLSession.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828

2929
import org.jruby.Ruby;
3030
import org.jruby.RubyClass;
31+
import org.jruby.RubyFixnum;
3132
import org.jruby.RubyModule;
33+
import org.jruby.RubyNumeric;
3234
import org.jruby.RubyObject;
3335
import org.jruby.RubyString;
3436
import org.jruby.RubyTime;
@@ -96,15 +98,30 @@ final javax.net.ssl.SSLSession sslSession() {
9698

9799
@JRubyMethod(name = "==")
98100
public IRubyObject op_eqq(final ThreadContext context, final IRubyObject other) {
101+
return context.runtime.newBoolean( equals(other) );
102+
}
103+
104+
@Override
105+
public boolean equals(final Object other) {
99106
if ( other instanceof SSLSession ) {
100107
final SSLSession that = (SSLSession) other;
101108
if ( this.sslSession.getProtocol().equals( that.sslSession.getProtocol() ) ) {
102109
if ( Arrays.equals( this.sslSession.getId(), that.sslSession.getId() ) ) {
103-
return context.runtime.getTrue();
110+
return true;
104111
}
105112
}
106113
}
107-
return context.runtime.getFalse();
114+
return false;
115+
}
116+
117+
@Override
118+
public final int hashCode() {
119+
return 17 * sslSession.hashCode();
120+
}
121+
122+
@Override
123+
public RubyFixnum hash() {
124+
return getRuntime().newFixnum(hashCode());
108125
}
109126

110127
@JRubyMethod(name = "id")
@@ -146,8 +163,7 @@ public IRubyObject set_timeout(final ThreadContext context, IRubyObject timeout)
146163
warn(context, "WARNING: can not set Session#timeout=("+ timeout +") no session context");
147164
return context.nil;
148165
}
149-
final long t = timeout.convertToInteger().getLongValue();
150-
sessionContext.setSessionTimeout((int) t); // in seconds as well
166+
sessionContext.setSessionTimeout(RubyNumeric.fix2int(timeout)); // in seconds as well
151167
return timeout;
152168
}
153169

0 commit comments

Comments
 (0)