Module: WebhookSystem::Payload

Defined in:
lib/webhook_system/encoder.rb

Overview

private class to just wrap the outer wrapping of the response format not exposed to the outside :nodoc:

Class Method Summary collapse

Class Method Details

.decode(payload_string) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/webhook_system/encoder.rb', line 60

def decode(payload_string)
  payload = JSON.load(payload_string)
  unless payload['format'] == 'base64+aes256'
    raise ArgumentError, 'only know how to handle base64+aes256 payloads'
  end
  [Base64.decode64(payload['payload']), Base64.decode64(payload['iv'])]
end

.encode(raw_encrypted_data, iv) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/webhook_system/encoder.rb', line 52

def encode(raw_encrypted_data, iv)
  JSON.dump(
    'format' => 'base64+aes256',
    'payload' => Base64.encode64(raw_encrypted_data),
    'iv' => Base64.encode64(iv)
  )
end