Class MegolmMessage

java.lang.Object
io.github.fherbreteau.vodozemac.megolm.MegolmMessage

public final class MegolmMessage extends Object
A structured Megolm message, containing the ciphertext, message index, MAC, and Ed25519 signature.

A MegolmMessage is produced by OutboundGroupSession.encrypt(byte[]) and consumed by InboundGroupSession.decrypt(MegolmMessage).

The toString() method produces the base64-encoded wire representation of the message, which is what the native vodozemac layer expects for serialisation and deserialisation.

To reconstruct a MegolmMessage from a base64 string received over the wire, use fromBase64(String).

Author:
François HERBRETEAU
See Also:
  • Method Details

    • ciphertext

      public String ciphertext()
      Returns the base64-encoded ciphertext of the message.
      Returns:
      the ciphertext as a base64 string
    • messageIndex

      public int messageIndex()
      Returns the message index, which indicates the ratchet position at which the message was encrypted.
      Returns:
      the message index
    • mac

      public String mac()
      Returns the base64-encoded MAC (message authentication code) of the message.
      Returns:
      the MAC as a base64 string
    • signature

      public Ed25519Signature signature()
      Returns the Ed25519 signature of the message.
      Returns:
      the signature
    • toString

      public String toString()
      Returns the base64-encoded wire representation of this message.

      This format is compatible with the Megolm message serialisation used by the native vodozemac layer and the Matrix protocol.

      Overrides:
      toString in class Object
      Returns:
      the base64-encoded message
    • fromBase64

      public static MegolmMessage fromBase64(String base64)
      Reconstructs a MegolmMessage from its base64-encoded wire representation.
      Parameters:
      base64 - the base64-encoded Megolm message
      Returns:
      a new MegolmMessage instance
      Throws:
      VodozemacException - if the input is not a valid Megolm message
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object