Module: SelfSDK::Messages

Defined in:
lib/messages/base.rb,
lib/messages/fact.rb,
lib/messages/message.rb,
lib/messages/attestation.rb,
lib/messages/fact_request.rb,
lib/messages/fact_response.rb,
lib/messages/authentication_req.rb,
lib/messages/authentication_resp.rb,
lib/messages/authentication_message.rb
more...

Defined Under Namespace

Classes: Attestation, AuthenticationMessage, AuthenticationReq, AuthenticationResp, Base, Fact, FactRequest, FactResponse

Class Method Summary collapse

Class Method Details

.parse(input, messaging, original = nil) ⇒ Object

[View source]

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/messages/message.rb', line 12

def self.parse(input, messaging, original=nil)
  envelope = nil
  body = if input.is_a? String
            input
         else
            envelope = input
            issuer = input.sender.split(":")
            messaging.encryption_client.decrypt(input.ciphertext, issuer.first, issuer.last)
         end

  jwt = JSON.parse(body, symbolize_names: true)
  payload = JSON.parse(messaging.jwt.decode(jwt[:payload]), symbolize_names: true)

  case payload[:typ]
  when "identities.facts.query.req"
    m = FactRequest.new(messaging)
    m.parse(body, envelope)
  when "identities.facts.query.resp"
    m = FactResponse.new(messaging)
    m.parse(body, envelope)
  when "identities.authenticate.resp"
    m = AuthenticationResp.new(messaging)
    m.parse(body, envelope)
  when "identities.authenticate.req"
    m = AuthenticationReq.new(messaging)
    m.parse(body, envelope)
  else
    raise StandardError.new("Invalid message type.")
  end
  return m
end