Class: RubyHome::HAP::HTTPEncryption

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_home/hap/http_encryption.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, count: 0) ⇒ HTTPEncryption

Returns a new instance of HTTPEncryption.



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

def initialize(key, count: 0)
  @key = key
  @count = count
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



22
23
24
# File 'lib/ruby_home/hap/http_encryption.rb', line 22

def count
  @count
end

Instance Method Details

#encrypt(data) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/ruby_home/hap/http_encryption.rb', line 11

def encrypt(data)
  data.chars.each_slice(1024).map(&:join).map do |message|
    additional_data = [message.length].pack('v')

    encrypted_data = chacha20poly1305ietf.encrypt(nonce, message, additional_data)
    increment_count!

    [additional_data, encrypted_data].join
  end
end