Class: AbstractSymmetricCrypt

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-common/v5/AbstractSymmetricCrypt.rb

Direct Known Subclasses

MyOpenSSL, OpenSSLAEAD, Secretbox

Constant Summary collapse

@@method_size =
2

Instance Method Summary collapse

Instance Method Details

#parse(payload, lengths) ⇒ Object

Raises:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ruby-common/v5/AbstractSymmetricCrypt.rb', line 6

def parse(payload, lengths)
  total_length = @@method_size + lengths.values.inject(0) { |sum, value| sum + value }

  raise DecryptError, "Premature data end" if payload.size < total_length

  decrypt_result = DecryptResult.new

  decrypt_result.method = PhpUnpack.unpack("vX", payload)['X'].first

  lengths.each do |key, length|
    bytes_for_key = payload.byteslice(0,length)
    payload.slice!(0,length)
    decrypt_result.byte_buffer_map[key] = bytes_for_key
  end

  decrypt_result.data = payload

  decrypt_result
end