Module: DiasporaFederation::Federation::Receiver

Extended by:
Logging
Defined in:
lib/diaspora_federation/federation/receiver.rb,
lib/diaspora_federation/federation/receiver/public.rb,
lib/diaspora_federation/federation/receiver/private.rb,
lib/diaspora_federation/federation/receiver/exceptions.rb,
lib/diaspora_federation/federation/receiver/abstract_receiver.rb

Overview

This module parses and receives entities.

Defined Under Namespace

Classes: AbstractReceiver, InvalidSender, NotPublic, Private, Public, RecipientRequired

Class Method Summary collapse

Methods included from Logging

included

Class Method Details

.receive_private(data, recipient_private_key, recipient_id, legacy = false) ⇒ Object

Receive a private message


30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/diaspora_federation/federation/receiver.rb', line 30

def self.receive_private(data, recipient_private_key, recipient_id, legacy=false)
  raise ArgumentError, "no recipient key provided" unless recipient_private_key.instance_of?(OpenSSL::PKey::RSA)
  magic_env = if legacy
                Salmon::EncryptedSlap.from_xml(data, recipient_private_key)
              else
                magic_env_xml = Salmon::EncryptedMagicEnvelope.decrypt(data, recipient_private_key)
                Salmon::MagicEnvelope.unenvelop(magic_env_xml)
              end
  Private.new(magic_env, recipient_id).receive
rescue => e # rubocop:disable Style/RescueStandardError
  logger.error "failed to receive private message for #{recipient_id}: #{e.class}: #{e.message}"
  logger.debug "received data:\n#{data}"
  raise e
end

.receive_public(data, legacy = false) ⇒ Object

Receive a public message


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/diaspora_federation/federation/receiver.rb', line 10

def self.receive_public(data, legacy=false)
  magic_env = if legacy
                Salmon::Slap.from_xml(data)
              else
                magic_env_xml = Nokogiri::XML(data).root
                Salmon::MagicEnvelope.unenvelop(magic_env_xml)
              end
  Public.new(magic_env).receive
rescue => e # rubocop:disable Style/RescueStandardError
  logger.error "failed to receive public message: #{e.class}: #{e.message}"
  logger.debug "received data:\n#{data}"
  raise e
end