Class: RubyHome::HAP::HTTPDecryption
- Inherits:
-
Object
- Object
- RubyHome::HAP::HTTPDecryption
- Defined in:
- lib/ruby_home/hap/http_decryption.rb
Constant Summary collapse
- AAD_LENGTH_BYTES =
2- AUTHENTICATE_TAG_LENGTH_BYTES =
16
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
Instance Method Summary collapse
- #decrypt(data) ⇒ Object
-
#initialize(key, count: 0) ⇒ HTTPDecryption
constructor
A new instance of HTTPDecryption.
Constructor Details
#initialize(key, count: 0) ⇒ HTTPDecryption
Returns a new instance of HTTPDecryption.
9 10 11 12 |
# File 'lib/ruby_home/hap/http_decryption.rb', line 9 def initialize(key, count: 0) @key = key @count = count end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
39 40 41 |
# File 'lib/ruby_home/hap/http_decryption.rb', line 39 def count @count end |
Instance Method Details
#decrypt(data) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ruby_home/hap/http_decryption.rb', line 14 def decrypt(data) decrypted_data = [] read_pointer = 0 while read_pointer < data.length little_endian_length_of_encrypted_data = data[read_pointer...read_pointer+AAD_LENGTH_BYTES] length_of_encrypted_data = little_endian_length_of_encrypted_data.unpack('v').first read_pointer += AAD_LENGTH_BYTES = data[read_pointer...read_pointer+length_of_encrypted_data] read_pointer += length_of_encrypted_data auth_tag = data[read_pointer...read_pointer+AUTHENTICATE_TAG_LENGTH_BYTES] read_pointer += AUTHENTICATE_TAG_LENGTH_BYTES ciphertext = + auth_tag additional_data = little_endian_length_of_encrypted_data decrypted_data << chacha20poly1305ietf.decrypt(nonce, ciphertext, additional_data) increment_count! end decrypted_data end |