Class: RubyHome::HAP::HTTPEncryption
- Inherits:
-
Object
- Object
- RubyHome::HAP::HTTPEncryption
- Defined in:
- lib/ruby_home/hap/http_encryption.rb
Constant Summary collapse
- MAX_FRAME_LENGTH =
1024.freeze
- NONCE_32_BIT_FIX_COMMENT_PART =
[0].pack('L').freeze
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
Instance Method Summary collapse
- #encrypt(data) ⇒ Object
-
#initialize(key, count: 0) ⇒ HTTPEncryption
constructor
A new instance of HTTPEncryption.
Constructor Details
#initialize(key, count: 0) ⇒ HTTPEncryption
Returns a new instance of HTTPEncryption.
7 8 9 10 |
# File 'lib/ruby_home/hap/http_encryption.rb', line 7 def initialize(key, count: 0) @key = key @count = count end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
34 35 36 |
# File 'lib/ruby_home/hap/http_encryption.rb', line 34 def count @count end |
Instance Method Details
#encrypt(data) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ruby_home/hap/http_encryption.rb', line 12 def encrypt(data) encrypted_data = [] read_pointer = 0 while read_pointer < data.length encrypted_frame = "" frame = data[read_pointer...read_pointer+MAX_FRAME_LENGTH] length_of_encrypted_data = frame.length little_endian_length_of_encrypted_data = [length_of_encrypted_data].pack('v') encrypted_frame += little_endian_length_of_encrypted_data encrypted_frame += chacha20poly1305ietf.encrypt(nonce, frame, little_endian_length_of_encrypted_data) encrypted_data << encrypted_frame read_pointer += length_of_encrypted_data increment_count! end encrypted_data end |