Class: Melos::Struct::PublicMessage

Inherits:
Base
  • Object
show all
Defined in:
lib/melos/struct/structs.rb

Overview

6.2

Constant Summary collapse

STRUCT =
[
  [:content, :class, Melos::Struct::FramedContent],
  [:auth, :framed_content_auth_data],
  [:membership_tag, :select, ->(ctx){ctx[:content].sender.sender_type == Melos::Constants::SenderType::MEMBER}, :vec] # MAC is opaque <V>
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#deserialize_select_elem_with_context, #initialize, #raw

Constructor Details

This class inherits a constructor from Melos::Struct::Base

Instance Attribute Details

#authObject (readonly)

Returns the value of attribute auth.



769
770
771
# File 'lib/melos/struct/structs.rb', line 769

def auth
  @auth
end

#contentObject (readonly)

Returns the value of attribute content.



769
770
771
# File 'lib/melos/struct/structs.rb', line 769

def content
  @content
end

#membership_tagObject (readonly)

Returns the value of attribute membership_tag.



769
770
771
# File 'lib/melos/struct/structs.rb', line 769

def membership_tag
  @membership_tag
end

Class Method Details

.protect(authenticated_content, suite, membership_key, group_context) ⇒ Object



776
777
778
779
780
781
782
783
784
# File 'lib/melos/struct/structs.rb', line 776

def self.protect(authenticated_content, suite, membership_key, group_context)
  message = self.allocate
  message.instance_variable_set(:@content, authenticated_content.content)
  message.instance_variable_set(:@auth, authenticated_content.auth)
  if message.content.sender.sender_type == Melos::Constants::SenderType::MEMBER # member
    message.instance_variable_set(:@membership_tag, message.membership_mac(suite, membership_key, group_context))
  end
  message
end

Instance Method Details

#membership_mac(suite, membership_key, group_context) ⇒ Object



798
799
800
801
802
803
804
805
# File 'lib/melos/struct/structs.rb', line 798

def membership_mac(suite, membership_key, group_context)
  authenticated_content_tbm = content.content_tbs(
    Melos::Constants::Version::MLS10,
    Melos::Constants::WireFormat::MLS_PUBLIC_MESSAGE,
    group_context
  ) + auth.raw
  Melos::Crypto.mac(suite, membership_key, authenticated_content_tbm)
end

#unprotect(suite, membership_key, group_context) ⇒ Object



786
787
788
789
790
791
792
793
794
795
796
# File 'lib/melos/struct/structs.rb', line 786

def unprotect(suite, membership_key, group_context)
  ## if sender type is member then membershipMac(suite, membership_key, group_context)
  if (content.sender.sender_type == Melos::Constants::SenderType::MEMBER)
    return nil if membership_tag != membership_mac(suite, membership_key, group_context)
  end
  Melos::Struct::AuthenticatedContent.create(
    wire_format: Melos::Constants::WireFormat::MLS_PUBLIC_MESSAGE, # public_message
    content: content,
    auth: auth
  )
end