Documentation
¶
Index ¶
- Variables
- type Envelope
- type Headers
- type Message
- func New(from string, to string, content []byte, contentType string, ...) (*Message, error)
- func NewBroadcast(from string, content []byte, contentType string, priv_key ed25519.PrivateKey) (*Message, error)
- func UnmarshalAndVerifyMessageFromCBOR(b []byte) (*Message, error)
- func UnmarshalMessageFromCBOR(b []byte) (*Message, error)
- func (m *Message) Broadcast(ctx context.Context, t *pubsub.Topic) error
- func (m *Message) Enclose() (*Envelope, error)
- func (m *Message) Headers() Headers
- func (m *Message) Send(ctx context.Context, t *pubsub.Topic) error
- func (m *Message) Sign(privKey ed25519.PrivateKey) error
- func (m *Message) Verify() error
Constants ¶
This section is empty.
Variables ¶
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
Bask the encrypted message and the encrypted symmetric key in a CBOR envelope.
func UnmarshalAndVerifyEnvelopeFromCBOR ¶ added in v0.4.1
func UnmarshalEnvelopeFromCBOR ¶ added in v0.2.1
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.
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 UnmarshalMessageFromCBOR ¶ added in v0.4.1
UnmarshalMessageFromCBOR unmarshals a Message from a CBOR byte slice and verifies the signature