message

package
v0.23.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2025 License: MPL-2.0 Imports: 7 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder added in v0.23.1

type Decoder struct {
	*bytes.Buffer
}

func NewDecoder added in v0.23.1

func NewDecoder(buf []byte) *Decoder

func (*Decoder) ReadVarBytes added in v0.23.1

func (d *Decoder) ReadVarBytes() ([]byte, error)

func (*Decoder) ReadVarInt added in v0.23.1

func (d *Decoder) ReadVarInt() (uint64, error)

type Encoder added in v0.23.1

type Encoder struct {
	// contains filtered or unexported fields
}

func (*Encoder) Bytes added in v0.23.1

func (e *Encoder) Bytes() []byte

func (*Encoder) PutByte added in v0.23.1

func (e *Encoder) PutByte(val byte)

func (*Encoder) PutVarBytes added in v0.23.1

func (e *Encoder) PutVarBytes(data []byte)

func (*Encoder) PutVarInt added in v0.23.1

func (e *Encoder) PutVarInt(val uint64)

type GroupMessage

type GroupMessage struct {
	Version         byte   `json:"version"`
	MessageIndex    uint32 `json:"index"`
	Ciphertext      []byte `json:"ciphertext"`
	HasMessageIndex bool   `json:"has_index"`
}

GroupMessage represents a message in the group message format.

func (*GroupMessage) Decode

func (r *GroupMessage) Decode(input []byte) (err error)

Decodes decodes the input and populates the corresponding fileds. MAC and signature are ignored but have to be present.

func (*GroupMessage) EncodeAndMACAndSign added in v0.23.1

func (r *GroupMessage) EncodeAndMACAndSign(cipher aessha2.AESSHA2, signKey crypto.Ed25519KeyPair) ([]byte, error)

EncodeAndMACAndSign encodes the message, creates the mac with the key and the cipher and signs the message. If macKey or cipher is nil, no mac is appended. If signKey is nil, no signature is appended.

func (*GroupMessage) MAC

func (r *GroupMessage) MAC(cipher aessha2.AESSHA2, ciphertext []byte) ([]byte, error)

MAC returns the MAC of the message calculated with cipher and key. The length of the MAC is truncated to the correct length.

func (*GroupMessage) VerifyMAC

func (r *GroupMessage) VerifyMAC(cipher aessha2.AESSHA2, ciphertext, givenMAC []byte) (bool, error)

VerifyMAC verifies the givenMAC to the calculated MAC of the message.

func (*GroupMessage) VerifyMACInline

func (r *GroupMessage) VerifyMACInline(cipher aessha2.AESSHA2, message []byte) (bool, error)

VerifyMACInline verifies the MAC taken from the message to the calculated MAC of the message.

func (*GroupMessage) VerifySignatureInline

func (r *GroupMessage) VerifySignatureInline(key crypto.Ed25519PublicKey, message []byte) bool

VerifySignature verifies the signature taken from the message to the calculated signature of the message.

type MegolmSessionExport

type MegolmSessionExport struct {
	Counter     uint32                  `json:"counter"`
	RatchetData [128]byte               `json:"data"`
	PublicKey   crypto.Ed25519PublicKey `json:"public_key"`
}

MegolmSessionExport represents a message in the session export format.

func (*MegolmSessionExport) Decode

func (s *MegolmSessionExport) Decode(input []byte) error

Decode populates the struct with the data encoded in input.

func (MegolmSessionExport) Encode

func (s MegolmSessionExport) Encode() []byte

Encode returns the encoded message in the correct format.

type MegolmSessionSharing

type MegolmSessionSharing struct {
	Counter     uint32                  `json:"counter"`
	RatchetData [128]byte               `json:"data"`
	PublicKey   crypto.Ed25519PublicKey `json:"-"` //only used when decrypting messages
}

MegolmSessionSharing represents a message in the session sharing format.

func (MegolmSessionSharing) EncodeAndSign

func (s MegolmSessionSharing) EncodeAndSign(key crypto.Ed25519KeyPair) ([]byte, error)

Encode returns the encoded message in the correct format with the signature by key appended.

func (*MegolmSessionSharing) VerifyAndDecode

func (s *MegolmSessionSharing) VerifyAndDecode(input []byte) error

VerifyAndDecode verifies the input and populates the struct with the data encoded in input.

type Message

type Message struct {
	Version    byte                       `json:"version"`
	HasCounter bool                       `json:"has_counter"`
	Counter    uint32                     `json:"counter"`
	RatchetKey crypto.Curve25519PublicKey `json:"ratchet_key"`
	Ciphertext []byte                     `json:"ciphertext"`
}

GroupMessage represents a message in the message format.

func (*Message) Decode

func (r *Message) Decode(input []byte) (err error)

Decodes decodes the input and populates the corresponding fileds. MAC is ignored but has to be present.

func (*Message) EncodeAndMAC

func (r *Message) EncodeAndMAC(cipher aessha2.AESSHA2) ([]byte, error)

EncodeAndMAC encodes the message and creates the MAC with the key and the cipher. If key or cipher is nil, no MAC is appended.

func (*Message) VerifyMAC

func (r *Message) VerifyMAC(key []byte, cipher aessha2.AESSHA2, ciphertext, givenMAC []byte) (bool, error)

VerifyMAC verifies the givenMAC to the calculated MAC of the message.

func (*Message) VerifyMACInline

func (r *Message) VerifyMACInline(key []byte, cipher aessha2.AESSHA2, message []byte) (bool, error)

VerifyMACInline verifies the MAC taken from the message to the calculated MAC of the message.

type PreKeyMessage

type PreKeyMessage struct {
	Version     byte                       `json:"version"`
	IdentityKey crypto.Curve25519PublicKey `json:"id_key"`
	BaseKey     crypto.Curve25519PublicKey `json:"base_key"`
	OneTimeKey  crypto.Curve25519PublicKey `json:"one_time_key"`
	Message     []byte                     `json:"message"`
}

func (*PreKeyMessage) CheckFields

func (r *PreKeyMessage) CheckFields(theirIdentityKey *crypto.Curve25519PublicKey) bool

CheckField verifies the fields. If theirIdentityKey is nil, it is not compared to the key in the message.

func (*PreKeyMessage) Decode

func (r *PreKeyMessage) Decode(input []byte) (err error)

Decodes decodes the input and populates the corresponding fileds.

func (*PreKeyMessage) Encode

func (r *PreKeyMessage) Encode() ([]byte, error)

Encode encodes the message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL