[前][次][番号順一覧][スレッド一覧]

ruby-changes:39294

From: tenderlove <ko1@a...>
Date: Sun, 26 Jul 2015 03:45:11 +0900 (JST)
Subject: [ruby-changes:39294] tenderlove:r51375 (trunk): * ext/openssl/lib/openssl/ssl.rb (module OpenSSL): move

tenderlove	2015-07-26 03:44:54 +0900 (Sun, 26 Jul 2015)

  New Revision: 51375

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51375

  Log:
    * ext/openssl/lib/openssl/ssl.rb (module OpenSSL): move
      OpenSSL::SSL::SSLContext#initialize implementation to pure Ruby.
    
    * ext/openssl/ossl_ssl.c (ossl_sslctx_initialize): ditto
    
    * ext/openssl/ossl_ssl.c (Init_ossl_ssl): ditto

  Modified files:
    trunk/ChangeLog
    trunk/ext/openssl/lib/openssl/ssl.rb
    trunk/ext/openssl/ossl_ssl.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51374)
+++ ChangeLog	(revision 51375)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jul 26 03:42:19 2015  Aaron Patterson <tenderlove@r...>
+
+	* ext/openssl/lib/openssl/ssl.rb (module OpenSSL): move 
+	  OpenSSL::SSL::SSLContext#initialize implementation to pure Ruby.
+
+	* ext/openssl/ossl_ssl.c (ossl_sslctx_initialize): ditto
+
+	* ext/openssl/ossl_ssl.c (Init_ossl_ssl): ditto
+
 Sat Jul 25 21:03:45 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* random.c (fill_random_bytes_syscall): get rid of blocking when
Index: ext/openssl/ossl_ssl.c
===================================================================
--- ext/openssl/ossl_ssl.c	(revision 51374)
+++ ext/openssl/ossl_ssl.c	(revision 51375)
@@ -69,22 +69,6 @@ static VALUE eSSLErrorWaitWritable; https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L69
 #define ossl_sslctx_get_tmp_dh_cb(o)     	rb_iv_get((o),"@tmp_dh_callback")
 #define ossl_sslctx_get_sess_id_ctx(o)   	rb_iv_get((o),"@session_id_context")
 
-static const char *ossl_sslctx_attrs[] = {
-    "cert", "key", "client_ca", "ca_file", "ca_path",
-    "timeout", "verify_mode", "verify_depth", "renegotiation_cb",
-    "verify_callback", "options", "cert_store", "extra_chain_cert",
-    "client_cert_cb", "tmp_dh_callback", "session_id_context",
-    "session_get_cb", "session_new_cb", "session_remove_cb",
-    "tmp_ecdh_callback",
-#ifdef HAVE_SSL_SET_TLSEXT_HOST_NAME
-    "servername_cb",
-#endif
-#ifdef HAVE_OPENSSL_NPN_NEGOTIATED
-    "npn_protocols",
-    "npn_select_cb",
-#endif
-};
-
 #define ossl_ssl_get_io(o)           rb_iv_get((o),"@io")
 #define ossl_ssl_get_ctx(o)          rb_iv_get((o),"@context")
 #define ossl_ssl_get_sync_close(o)   rb_iv_get((o),"@sync_close")
@@ -232,33 +216,6 @@ ossl_sslctx_set_ssl_version(VALUE self, https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L216
     return ssl_method;
 }
 
-/*
- * call-seq:
- *    SSLContext.new => ctx
- *    SSLContext.new(:TLSv1) => ctx
- *    SSLContext.new("SSLv23_client") => ctx
- *
- * You can get a list of valid methods with OpenSSL::SSL::SSLContext::METHODS
- */
-static VALUE
-ossl_sslctx_initialize(int argc, VALUE *argv, VALUE self)
-{
-    VALUE ssl_method;
-    int i;
-
-    for(i = 0; i < numberof(ossl_sslctx_attrs); i++){
-	char buf[32];
-	snprintf(buf, sizeof(buf), "@%s", ossl_sslctx_attrs[i]);
-	rb_iv_set(self, buf, Qnil);
-    }
-    if (rb_scan_args(argc, argv, "01", &ssl_method) == 0){
-        return self;
-    }
-    ossl_sslctx_set_ssl_version(self, ssl_method);
-
-    return self;
-}
-
 static VALUE
 ossl_call_client_cert_cb(VALUE obj)
 {
@@ -2315,7 +2272,6 @@ Init_ossl_ssl(void) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L2272
 
     rb_define_alias(cSSLContext, "ssl_timeout", "timeout");
     rb_define_alias(cSSLContext, "ssl_timeout=", "timeout=");
-    rb_define_method(cSSLContext, "initialize",  ossl_sslctx_initialize, -1);
     rb_define_method(cSSLContext, "ssl_version=", ossl_sslctx_set_ssl_version, 1);
     rb_define_method(cSSLContext, "ciphers",     ossl_sslctx_get_ciphers, 0);
     rb_define_method(cSSLContext, "ciphers=",    ossl_sslctx_set_ciphers, 1);
Index: ext/openssl/lib/openssl/ssl.rb
===================================================================
--- ext/openssl/lib/openssl/ssl.rb	(revision 51374)
+++ ext/openssl/lib/openssl/ssl.rb	(revision 51375)
@@ -74,6 +74,26 @@ module OpenSSL https://github.com/ruby/ruby/blob/trunk/ext/openssl/lib/openssl/ssl.rb#L74
         DEFAULT_CERT_STORE.flags = OpenSSL::X509::V_FLAG_CRL_CHECK_ALL
       end
 
+      INIT_VARS = ["cert", "key", "client_ca", "ca_file", "ca_path",
+        "timeout", "verify_mode", "verify_depth", "renegotiation_cb",
+        "verify_callback", "options", "cert_store", "extra_chain_cert",
+        "client_cert_cb", "tmp_dh_callback", "session_id_context",
+        "session_get_cb", "session_new_cb", "session_remove_cb",
+        "tmp_ecdh_callback", "servername_cb", "npn_protocols",
+        "npn_select_cb"].map { |x| "@#{x}" }
+
+      # call-seq:
+      #    SSLContext.new => ctx
+      #    SSLContext.new(:TLSv1) => ctx
+      #    SSLContext.new("SSLv23_client") => ctx
+      #
+      # You can get a list of valid methods with OpenSSL::SSL::SSLContext::METHODS
+      def initialize(version = nil)
+        INIT_VARS.each { |v| instance_variable_set v, nil }
+        return unless version
+        self.ssl_version = version
+      end
+
       ##
       # Sets the parameters for this SSL context to the values in +params+.
       # The keys in +params+ must be assignment methods on SSLContext.

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]