Class: RubyHome::HAP::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_home/hap/session.rb,
lib/ruby_home/hap/encrypter.rb

Defined Under Namespace

Classes: Encrypter

Constant Summary collapse

PARSE_BUFFER_SIZE =
65536

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socket, decrypter_class: Decrypter, encrypter_class: Encrypter) ⇒ Session

Returns a new instance of Session.



6
7
8
9
10
# File 'lib/ruby_home/hap/session.rb', line 6

def initialize(socket, decrypter_class: Decrypter, encrypter_class: Encrypter)
  @socket = socket
  @encrypter_class = encrypter_class
  @decrypter_class = decrypter_class
end

Instance Attribute Details

#accessory_to_controller_keyObject

Returns the value of attribute accessory_to_controller_key.



12
13
14
# File 'lib/ruby_home/hap/session.rb', line 12

def accessory_to_controller_key
  @accessory_to_controller_key
end

#controller_to_accessory_keyObject

Returns the value of attribute controller_to_accessory_key.



12
13
14
# File 'lib/ruby_home/hap/session.rb', line 12

def controller_to_accessory_key
  @controller_to_accessory_key
end

#session_keyObject

Returns the value of attribute session_key.



12
13
14
# File 'lib/ruby_home/hap/session.rb', line 12

def session_key
  @session_key
end

#shared_secretObject

Returns the value of attribute shared_secret.



12
13
14
# File 'lib/ruby_home/hap/session.rb', line 12

def shared_secret
  @shared_secret
end

#srp_sessionObject

Returns the value of attribute srp_session.



12
13
14
# File 'lib/ruby_home/hap/session.rb', line 12

def srp_session
  @srp_session
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ruby_home/hap/session.rb', line 24

def active?
  !socket.closed?
end

#parseObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ruby_home/hap/session.rb', line 38

def parse
  if decryption_time?
    received_encrypted_request!
    StringIO.new(
      decrypter.decrypt(
        socket.read_nonblock(PARSE_BUFFER_SIZE)
      )
    )
  else
    socket
  end
end

#received_encrypted_request!Object



51
52
53
# File 'lib/ruby_home/hap/session.rb', line 51

def received_encrypted_request!
  @received_encrypted_request ||= true
end

#sufficient_privileges?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/ruby_home/hap/session.rb', line 20

def sufficient_privileges?
  controller_to_accessory_key? && accessory_to_controller_key?
end

#write(data) ⇒ Object Also known as: <<



28
29
30
31
32
33
34
# File 'lib/ruby_home/hap/session.rb', line 28

def write(data)
  if encryption_time?
    socket.write(encrypter.encrypt(data))
  else
    socket.write(data)
  end
end