aboutsummaryrefslogtreecommitdiffstats
path: root/ext/openssl/ossl_ssl_session.c
diff options
context:
space:
mode:
authornahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-23 10:36:09 +0000
committernahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-23 10:36:09 +0000
commit544daf1f7abc19fd1577b1aafd7abebef4ee19d7 (patch)
treeb90a9bb3bdf32244a81205a4a2028779ccdce07c /ext/openssl/ossl_ssl_session.c
parenta02504ba843f476edfe6cb41b93fefe01c9594c8 (diff)
downloadruby-544daf1f7abc19fd1577b1aafd7abebef4ee19d7.tar.gz
* ext/openssl/ossl_ssl_session.c (ossl_ssl_session_set_time): Check
argument type with NUM2LONG if the arg is not a Time object. See #4919. * ext/openssl/ossl_ssl_session.c (ossl_ssl_session_set_timeout): Check type with NUM2LONG. Time as an arg is not allowed. See #4919. * test/openssl/test_ssl_session.rb (test_session_time, test_session_timeout): Test it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32211 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/openssl/ossl_ssl_session.c')
-rw-r--r--ext/openssl/ossl_ssl_session.c64
1 files changed, 40 insertions, 24 deletions
diff --git a/ext/openssl/ossl_ssl_session.c b/ext/openssl/ossl_ssl_session.c
index 80abed7e67..a7437caf37 100644
--- a/ext/openssl/ossl_ssl_session.c
+++ b/ext/openssl/ossl_ssl_session.c
@@ -104,6 +104,8 @@ static VALUE ossl_ssl_session_eq(VALUE val1, VALUE val2)
* call-seq:
* session.time -> Time
*
+ * Gets start time of the session.
+ *
*/
static VALUE ossl_ssl_session_get_time(VALUE self)
{
@@ -124,7 +126,7 @@ static VALUE ossl_ssl_session_get_time(VALUE self)
* call-seq:
* session.timeout -> integer
*
- * How long until the session expires in seconds.
+ * Gets how long until the session expires in seconds.
*
*/
static VALUE ossl_ssl_session_get_timeout(VALUE self)
@@ -139,31 +141,45 @@ static VALUE ossl_ssl_session_get_timeout(VALUE self)
return TIMET2NUM(t);
}
-#define SSLSESSION_SET_TIME(func) \
- static VALUE ossl_ssl_session_set_##func(VALUE self, VALUE time_v) \
- { \
- SSL_SESSION *ctx; \
- unsigned long t; \
- \
- GetSSLSession(self, ctx); \
- \
- if (rb_obj_is_instance_of(time_v, rb_cTime)) { \
- time_v = rb_funcall(time_v, rb_intern("to_i"), 0); \
- } else if (FIXNUM_P(time_v) || TYPE(time_v) == T_BIGNUM) { \
- ; \
- } else { \
- ossl_raise(rb_eArgError, "unknown type"); \
- } \
- \
- t = NUM2ULONG(time_v); \
- \
- SSL_SESSION_set_##func(ctx, t); \
- \
- return ossl_ssl_session_get_##func(self); \
+/*
+ * call-seq:
+ * session.time=(Time) -> Time
+ * session.time=(integer) -> Time
+ *
+ * Sets start time of the session. Time resolution is in seconds.
+ *
+*/
+static VALUE ossl_ssl_session_set_time(VALUE self, VALUE time_v)
+{
+ SSL_SESSION *ctx;
+ long t;
+
+ GetSSLSession(self, ctx);
+ if (rb_obj_is_instance_of(time_v, rb_cTime)) {
+ time_v = rb_funcall(time_v, rb_intern("to_i"), 0);
}
+ t = NUM2LONG(time_v);
+ SSL_SESSION_set_time(ctx, t);
+ return ossl_ssl_session_get_time(self);
+}
-SSLSESSION_SET_TIME(time)
-SSLSESSION_SET_TIME(timeout)
+/*
+ * call-seq:
+ * session.timeout=(integer) -> integer
+ *
+ * Sets how long until the session expires in seconds.
+ *
+*/
+static VALUE ossl_ssl_session_set_timeout(VALUE self, VALUE time_v)
+{
+ SSL_SESSION *ctx;
+ long t;
+
+ GetSSLSession(self, ctx);
+ t = NUM2LONG(time_v);
+ SSL_SESSION_set_timeout(ctx, t);
+ return ossl_ssl_session_get_timeout(self);
+}
#ifdef HAVE_SSL_SESSION_GET_ID
/*