about summary refs log tree commit diff
path: root/app/serializers/activitypub/encrypted_message_serializer.rb
blob: 3c525d23e5cee5688057b2662353b23a2b86a61b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# frozen_string_literal: true

class ActivityPub::EncryptedMessageSerializer < ActivityPub::Serializer
  context :security

  context_extensions :olm

  class DeviceSerializer < ActivityPub::Serializer
    attributes :type, :device_id

    def type
      'Device'
    end

    def device_id
      object
    end
  end

  class DigestSerializer < ActivityPub::Serializer
    attributes :type, :digest_algorithm, :digest_value

    def type
      'Digest'
    end

    def digest_algorithm
      'http://www.w3.org/2000/09/xmldsig#hmac-sha256'
    end

    def digest_value
      object
    end
  end

  attributes :type, :message_type, :cipher_text, :message_franking

  has_one :attributed_to, serializer: DeviceSerializer
  has_one :to, serializer: DeviceSerializer
  has_one :digest, serializer: DigestSerializer

  def type
    'EncryptedMessage'
  end

  def attributed_to
    object.source_device.device_id
  end

  def to
    object.target_device_id
  end

  def message_type
    object.type
  end

  def cipher_text
    object.body
  end
end