Class: Krakow::ConnectionFeatures::Ssl::Io

Inherits:
Object
  • Object
show all
Defined in:
lib/krakow/connection_features/ssl.rb

Overview

SSL-able IO

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, args = {}) ⇒ Io

Create new SSL-able IO

Parameters:

  • io (IO)

    IO to wrap

  • args (Hash) (defaults to: {})

Options Hash (args):

  • :ssl_context (Hash)


19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/krakow/connection_features/ssl.rb', line 19

def initialize(io, args={})
  ssl_socket_arguments = [io]
  if(args[:ssl_context])
    validate_ssl_args!(args[:ssl_context])
    context = OpenSSL::SSL::SSLContext.new
    context.cert = OpenSSL::X509::Certificate.new(File.open(args[:ssl_context][:certificate]))
    context.key = OpenSSL::PKey::RSA.new(File.open(args[:ssl_context][:key]))
    ssl_socket_arguments << context
  end
  @_socket = Celluloid::IO::SSLSocket.new(*ssl_socket_arguments)
  _socket.sync = true
  _socket.connect
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object

Proxy to underlying socket

Parameters:

  • args (Object)

Returns:

  • (Object)


37
38
39
# File 'lib/krakow/connection_features/ssl.rb', line 37

def method_missing(*args)
  _socket.send(*args)
end

Instance Attribute Details

#_socketObject (readonly)

Returns the value of attribute _socket.



11
12
13
# File 'lib/krakow/connection_features/ssl.rb', line 11

def _socket
  @_socket
end

Instance Method Details

#recv(len) ⇒ String

Receive bytes from the IO

Parameters:

  • len (Integer)

    nuber of bytes

Returns:

  • (String)


45
46
47
48
49
50
51
# File 'lib/krakow/connection_features/ssl.rb', line 45

def recv(len)
  str = readpartial(len)
  if(len > str.length)
    str << sysread(len - str.length)
  end
  str
end