Class: Melos::Struct::AuthenticatedContent

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

Constant Summary collapse

STRUCT =
[
  [:wire_format, :uint16],
  [:content, :class, Melos::Struct::FramedContent],
  [:auth, :framed_content_auth_data]
]

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.



718
719
720
# File 'lib/melos/struct/structs.rb', line 718

def auth
  @auth
end

#contentObject (readonly)

Returns the value of attribute content.



718
719
720
# File 'lib/melos/struct/structs.rb', line 718

def content
  @content
end

#wire_formatObject (readonly)

Returns the value of attribute wire_format.



718
719
720
# File 'lib/melos/struct/structs.rb', line 718

def wire_format
  @wire_format
end

Class Method Details

.create(wire_format:, content:, auth:) ⇒ Object



745
746
747
748
749
750
751
# File 'lib/melos/struct/structs.rb', line 745

def self.create(wire_format:, content:, auth:)
  new_instance = self.allocate
  new_instance.instance_variable_set(:@wire_format, wire_format)
  new_instance.instance_variable_set(:@content, content)
  new_instance.instance_variable_set(:@auth, auth)
  new_instance
end

Instance Method Details

#confirmed_transcript_hash_inputObject



729
730
731
732
733
734
735
# File 'lib/melos/struct/structs.rb', line 729

def confirmed_transcript_hash_input
  Melos::Struct::ConfirmedTranscriptHashInput.create(
    wire_format: wire_format,
    content: content,
    signature: auth.signature
  )
end

#content_tbmObject



725
726
727
# File 'lib/melos/struct/structs.rb', line 725

def content_tbm
  content.content_tbs(Melos::Constants::Version::MLS10, wire_format) + auth.raw
end

#sign(suite, signature_private_key, group_context) ⇒ Object

populate auth with values

Raises:

  • (ArgumentError)


754
755
756
757
758
759
760
761
762
763
# File 'lib/melos/struct/structs.rb', line 754

def sign(suite, signature_private_key, group_context)
  raise ArgumentError.new('Application data cannot be sent as a PublicMessage') if wire_format == Melos::Constants::WireFormat::MLS_PUBLIC_MESSAGE && content.content_type == Melos::Constants::ContentType::APPLICATION
  content_tbs = content.content_tbs(Melos::Constants::Version::MLS10, wire_format, group_context)
  signature = Melos::Crypto.sign_with_label(suite, signature_private_key, "FramedContentTBS", content_tbs)
  @auth = Melos::Struct::FramedContentAuthData.create(
    signature: signature,
    content_type: content.content_type,
    confirmation_tag: nil
  )
end

#verify(suite, signature_public_key, context) ⇒ Object



737
738
739
740
741
742
743
# File 'lib/melos/struct/structs.rb', line 737

def verify(suite, signature_public_key, context)
  return false if (wire_format == Melos::Constants::WireFormat::MLS_PUBLIC_MESSAGE && content.content_type == Melos::Constants::ContentType::APPLICATION)

  content_tbs = content.content_tbs(Melos::Constants::Version::MLS10, wire_format, context)

  return Melos::Crypto.verify_with_label(suite, signature_public_key, "FramedContentTBS", content_tbs, auth.signature)
end