aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorthekuwayama <thekuwayama@gmail.com>2019-10-31 08:43:47 +0900
committerSamuel Williams <samuel.williams@oriontransfer.co.nz>2019-10-31 14:19:30 +1300
commit56e874d3f1cd4a35e3e1730a3a40eb2326bedce5 (patch)
tree62c9b69d1f80cf2469b36acbac0bb657e78c8183 /lib
parentdd87110a12dba028ab96ecd885970ba04094f9a4 (diff)
downloadruby-openssl-56e874d3f1cd4a35e3e1730a3a40eb2326bedce5.tar.gz
update SSLSocket.open to match TCPSocket.open method signature
Diffstat (limited to 'lib')
-rw-r--r--lib/openssl/ssl.rb24
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/openssl/ssl.rb b/lib/openssl/ssl.rb
index 9f3afc2f..6380b965 100644
--- a/lib/openssl/ssl.rb
+++ b/lib/openssl/ssl.rb
@@ -448,18 +448,28 @@ YoaOffgTf5qxiwkjnlVZQc3whgnEt9FpVMvQ9eknyeGB5KHfayAc3+hUAvI3/Cr3
#
# Creates a new instance of SSLSocket.
# _remote\_host_ and _remote_port_ are used to open TCPSocket.
- # If _context_ is provided,
- # the SSL Sockets initial params will be taken from the context.
# If _local\_host_ and _local\_port_ are specified,
# then those parameters are used on the local end to establish the connection.
+ # If _context_ is provided,
+ # the SSL Sockets initial params will be taken from the context.
#
- # === Example
- # ctx = OpenSSL::SSL::SSLContext.new
- # sock = OpenSSL::SSL::SSLSocket.open('localhost', 443, ctx)
+ # === Examples
+ #
+ # sock = OpenSSL::SSL::SSLSocket.open('localhost', 443)
# sock.connect # Initiates a connection to localhost:443
- def open(remote_host, remote_port, context=nil, local_host=nil, local_port=nil)
+ #
+ # with SSLContext:
+ #
+ # ctx = OpenSSL::SSL::SSLContext.new
+ # sock = OpenSSL::SSL::SSLSocket.open('localhost', 443, context: ctx)
+ # sock.connect # Initiates a connection to localhost:443 with SSLContext
+ def open(remote_host, remote_port, local_host=nil, local_port=nil, context: nil)
sock = ::TCPSocket.open(remote_host, remote_port, local_host, local_port)
- OpenSSL::SSL::SSLSocket.new(sock, context)
+ if context.nil?
+ return OpenSSL::SSL::SSLSocket.new(sock)
+ else
+ return OpenSSL::SSL::SSLSocket.new(sock, context)
+ end
end
end
end