msg

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: GPL-3.0 Imports: 18 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBroadcastHasRecipient = errors.New("broadcast message must not have a recipient")
	ErrBroadcastInvalidTopic = fmt.Errorf("broadcast topic must be %s", ma.BROADCAST_TOPIC)
	ErrBroadcastInvalidType  = fmt.Errorf("broadcast message must not %s", ma.BROADCAST_MESSAGE_TYPE)
	ErrEmptyID               = errors.New("id must be non-empty")
	ErrInvalidID             = errors.New("invalid message id")
	ErrFetchDoc              = errors.New("failed to fetch entity document")
	ErrMessageInvalidType    = errors.New("invalid Message type")
	ErrInvalidSender         = errors.New("invalid sender")
	ErrInvalidRecipient      = errors.New("invalid recipient")
	ErrMissingContentType    = errors.New("empty ContentType")
	ErrMissingContent        = errors.New("empty ContentType")
	ErrMissingFrom           = errors.New("mmissing From sender")
	ErrMissinSignature       = errors.New("mmissing signature")
	ErrNilMessage            = errors.New("nil Message provided")
	ErrNilEnvelope           = errors.New("nil Envelope provided")
	ErrSameActor             = errors.New("header From and To be different")
	ErrVersionInvalid        = fmt.Errorf("version not %s", ma.VERSION)
	ErrVersionTooHigh        = fmt.Errorf("version is higher %s", ma.VERSION)
	ErrVersionTooLow         = fmt.Errorf("version is less than %s", ma.VERSION)
)

Functions

This section is empty.

Types

type Envelope added in v0.1.0

type Envelope struct {
	EphemeralKey     []byte
	EncryptedContent []byte
	EncryptedHeaders []byte
}

Bask the encrypted message and the encrypted symmetric key in a CBOR envelope.

func UnmarshalAndVerifyEnvelopeFromCBOR added in v0.4.1

func UnmarshalAndVerifyEnvelopeFromCBOR(data []byte) (*Envelope, error)

func UnmarshalEnvelopeFromCBOR added in v0.2.1

func UnmarshalEnvelopeFromCBOR(data []byte) (*Envelope, error)

Takes the envelope as a byte array and returns a pointer to an Envelope struct Basically this is what you do with a receieved message envelope, eg. in an Open() function.

func (*Envelope) Open added in v0.2.1

func (e *Envelope) Open(privateKey []byte) (*Message, error)

func (*Envelope) Send added in v0.6.1

func (e *Envelope) Send(ctx context.Context, t *pubsub.Topic) error

func (*Envelope) Verify added in v0.4.1

func (e *Envelope) Verify() error

type Headers added in v0.1.0

type Headers struct {
	// Version of the message format
	Id string `cbor:"id"`
	// MIME type of the message
	Type string `cbor:"type"`
	// Sender of the message
	From string `cbor:"from"`
	// Recipient of the message
	To string `cbor:"to"`
	// MIME type of the message body
	ContentType string `cbor:"contentType"`
	// Hexadecimal string representation of the SHA-256 hash of the message body
	Signature []byte `cbor:"signature"`
}

This struct mimicks the Headers format, but it's *not* Headers. It should enable using Headers later, if that's a good idea. NB! Content is *not* a part of the headers

type Message

type Message struct {
	// Unique identifier of the message
	Id string `cbor:"id"`
	// MIME type of the message
	Type string `cbor:"mimeType"`
	// Sender of the message
	From string `cbor:"from"`
	// Recipient of the message
	To string `cbor:"to"`
	// MIME type of the message body
	ContentType string `cbor:"contentType"`
	// Byte slice of the content
	Content []byte `cbor:"content"`
	// Signature of the message headers. NB! This includes the ContentHash field,
	// which can be used to verify the integrity of the message body.
	Signature []byte `cbor:"signature"`
}

This struct mimicks the Message format, but it's *not* Message. It should enable using Message later, if that's a good idea.

func New

func New(
	from string,
	to string,
	content []byte,
	contentType string,
	priv_key ed25519.PrivateKey) (*Message, error)

New creates a new Message instance

func NewBroadcast added in v0.4.0

func NewBroadcast(
	from string,
	content []byte,
	contentType string,
	priv_key ed25519.PrivateKey) (*Message, error)

A Broadcast message is just a message with no recipient. This packages tries to enforce this, so as to avoid mistakes.

func UnmarshalAndVerifyMessageFromCBOR added in v0.4.1

func UnmarshalAndVerifyMessageFromCBOR(b []byte) (*Message, error)

func UnmarshalMessageFromCBOR added in v0.4.1

func UnmarshalMessageFromCBOR(b []byte) (*Message, error)

UnmarshalMessageFromCBOR unmarshals a Message from a CBOR byte slice and verifies the signature

func (*Message) Broadcast added in v0.4.0

func (m *Message) Broadcast(ctx context.Context, t *pubsub.Topic) error

Send message to a pubsub topic

func (*Message) Enclose added in v0.0.3

func (m *Message) Enclose() (*Envelope, error)

Use a pointer here, this might be arbitrarily big.

func (*Message) Headers added in v0.1.0

func (m *Message) Headers() Headers

Returns the all the imprimatur headers

func (*Message) Send added in v0.0.3

func (m *Message) Send(ctx context.Context, t *pubsub.Topic) error
message send is meant to send the message signed, but not encrypted

Create an envelope by calling Enclose() first and then send *that* with Send()

func (*Message) Sign

func (m *Message) Sign(privKey ed25519.PrivateKey) error

func (*Message) Verify

func (m *Message) Verify() error

Verify verifies the Message's signature Returns nil if the signature is valid

Jump to

Keyboard shortcuts

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