Index | Files

package message

import ""


Package Files

containers.go data.go encryption.go messages.go network.go signing.go

func ConnectToServer Uses

func ConnectToServer(remote string) (net.Conn, error)

ConnectToServer is a convenience method that attempts to dial a tcp connection to a server specified by a string.

func SendMessageAndReceive Uses

func SendMessageAndReceive(m Message, sender *identity.Identity, addr *identity.Address) ([]byte, string, Header, error)

SendMessageAndReceive does exactly what you think:

- Signs, Encrypts, and sends a message to a connection - Receives, Decrypts, Verifies, and Reconstructs a message from a connection (without timestamp support)

func SendMessageAndReceiveWithTimestamp Uses

func SendMessageAndReceiveWithTimestamp(m Message, sender *identity.Identity, addr *identity.Address) ([]byte, string, Header, error)

SendMessageAndReceiveWithTimestamp does exactly the same as SendMessageAndReceive but includes timestamp support.

func SignAndSend Uses

func SignAndSend(m Message, from *identity.Identity, to *identity.Address) error

SignAndSend will take a message, a from identity, and a to address, and send it to the address (so long as to already contains key information).

func SignAndSendToConnection Uses

func SignAndSendToConnection(m Message, from *identity.Identity, to *identity.Address, conn net.Conn) error

SignAndSendToConnection performs exactly the same function as SignAndSend, but it can utilize an already open connection. Useful for responding to messages.

type Component Uses

type Component struct {
    Name string
    Data []byte

Component is a basic unit in an AirDispatch message. It has a name, generally a string akin to Apple's bundle ids.

E.G. if I am creating an AirDispatch application at I may have a data type called "ch.airdispat.notes.title".

func CreateComponent Uses

func CreateComponent(name string, data []byte) Component

CreateComponent will return a new component given a name and data.

func CreateStringComponent Uses

func CreateStringComponent(name string, data string) Component

CreateStringComponent will return a new component given a name and a UTF-8 string.

func (Component) Key Uses

func (c Component) Key() string

Key will return the name of the component.

func (Component) String Uses

func (c Component) String() string

String will return the bytes of the component interpreted as UTF-8.

func (Component) Value Uses

func (c Component) Value() []byte

Value will return the bytes of the component.

type ComponentList Uses

type ComponentList map[string]Component

ComponentList maps keys (strings) to components.

func (ComponentList) AddComponent Uses

func (c ComponentList) AddComponent(comp Component)

AddComponent will add a new component object into the list.

func (ComponentList) GetComponent Uses

func (c ComponentList) GetComponent(name string) []byte

GetComponent will return the []byte associated with a component name.

func (ComponentList) GetStringComponent Uses

func (c ComponentList) GetStringComponent(name string) string

GetStringComponent will return the []byte associated with a component name interpreted as UTF-8.

func (ComponentList) HasComponent Uses

func (c ComponentList) HasComponent(name string) bool

HasComponent will return whether a Mail object contains a component.

func (ComponentList) ToArray Uses

func (c ComponentList) ToArray() []Component

ToArray will return the ComponentList as an array of components.

type DataMessage Uses

type DataMessage struct {
    Hash     []byte
    Length   uint64
    Key      []byte
    DataType string
    Name     string
    Filename string
    // contains filtered or unexported fields

DataMessage allows transfer of arbitrarily large bytestreams.

func CreateDataMessage Uses

func CreateDataMessage(hash []byte, length uint64, typ, name, filename string, r io.ReadCloser, h Header) (*DataMessage, io.ReadCloser, error)

func CreateDataMessageFromBytes Uses

func CreateDataMessageFromBytes(by []byte, h Header) (*DataMessage, error)

CreateMailFromBytes will unmarshall a mail message given its bytes and header.

func (*DataMessage) DecryptReader Uses

func (m *DataMessage) DecryptReader(r io.Reader) (io.Reader, error)

func (*DataMessage) Header Uses

func (m *DataMessage) Header() Header

func (*DataMessage) ToBytes Uses

func (m *DataMessage) ToBytes() []byte

ToBytes will marshal a mail message to its component bytes.

func (*DataMessage) TrueLength Uses

func (m *DataMessage) TrueLength() uint64

func (*DataMessage) Type Uses

func (m *DataMessage) Type() string

func (*DataMessage) VerifyPayload Uses

func (m *DataMessage) VerifyPayload() bool

type EncryptedMessage Uses

type EncryptedMessage struct {
    Data   []byte
    Header map[string]EncryptionHeader
    // contains filtered or unexported fields

EncryptedMessage represents an AirDispatch message encrypted for one or many recipients.

func CreateEncryptedMessageFromBytes Uses

func CreateEncryptedMessageFromBytes(theBytes []byte) (*EncryptedMessage, error)

CreateEncryptedMessageFromBytes will take a series of bytes (usually read read from a connection) and Unmarshal them into the EncryptedMessage struct.

func ReadMessageFromConnection Uses

func ReadMessageFromConnection(conn net.Conn) (*EncryptedMessage, error)

ReadMessageFromConnection will return a read EncryptedMessage off a specified net.Conn.

func (*EncryptedMessage) AddRecipient Uses

func (e *EncryptedMessage) AddRecipient(addr *identity.Address) error

AddRecipient will take an *identity.Address and add information for it to decrypt the message.

func (*EncryptedMessage) Decrypt Uses

func (e *EncryptedMessage) Decrypt(id *identity.Identity) (*SignedMessage, error)

Decrypt will use an *identity.Identity to decrypt the EncryptedMessage into a SignedMessage.

func (*EncryptedMessage) Reconstruct Uses

func (e *EncryptedMessage) Reconstruct(receiver *identity.Identity, ts bool) ([]byte, string, Header, error)

Reconstruct will take an change an encrypted message into a message blob Message Type, Header, and Error by Decrypting with the receiver's identity, verifying the signed message, and reconstructing the signed message (optionally with timestamp support).

func (*EncryptedMessage) Send Uses

func (e *EncryptedMessage) Send() error

Send will connect to each recipient's server and send the message to them.

func (*EncryptedMessage) SendMessageToConnection Uses

func (e *EncryptedMessage) SendMessageToConnection(conn net.Conn) error

SendMessageToConnection will send an encryptedMessage to a connection.

func (*EncryptedMessage) ToBytes Uses

func (e *EncryptedMessage) ToBytes() ([]byte, error)

ToBytes will marshal an EncryptedMessage to an array of bytes suitable for sending on a wire.

func (*EncryptedMessage) UnencryptedMessage Uses

func (e *EncryptedMessage) UnencryptedMessage() (*SignedMessage, error)

UnencryptedMessage will downgrade an EncryptedMessage into a SignedMessage if you know that the message is not encrypted.

type EncryptionHeader Uses

type EncryptionHeader struct {
    EncryptionKey  []byte
    EncryptionType []byte
    To             *identity.Address

EncryptionHeader holds the information necessary for a recipient to decrypt the message.

type Header struct {
    From      *identity.Address
    To        []*identity.Address
    Timestamp int64
    // Location Options
    EncryptionKey []byte
    Alias         string

Header is a message header that is sent across the wire signed and encrypted.

Each public field is an object that is important to be protected.

func CreateHeader Uses

func CreateHeader(from *identity.Address, to ...*identity.Address) Header

CreateHeader will return a basic header for a from address and a to address.

type Mail Uses

type Mail struct {
    Name       string
    Components ComponentList
    // contains filtered or unexported fields

Mail is the basic form of a user-visible AirDispatch message.

It contains a list of components that effectively serve as a key-value dictionary of string -> []byte. Most of the time, the []byte can be interpreted as a UTF-8 string.

func CreateMail Uses

func CreateMail(from *identity.Address, ts time.Time, name string, to ...*identity.Address) *Mail

CreateMail will return a new Mail object with the correct header, ready for adding components.

func CreateMailFromBytes Uses

func CreateMailFromBytes(by []byte, h Header) (*Mail, error)

CreateMailFromBytes will unmarshall a mail message given its bytes and header.

func (*Mail) Header Uses

func (m *Mail) Header() Header

Header just returns the stored header with the message.

func (*Mail) ToBytes Uses

func (m *Mail) ToBytes() []byte

ToBytes will marshal a mail message to its component bytes.

func (*Mail) Type Uses

func (m *Mail) Type() string

Type is used to satisfy the (message.Message) interface. Mail objects have type wire.MailCode (or "MAI").

type Message Uses

type Message interface {
    Header() Header
    Type() string
    ToBytes() []byte

Message is an interface that allows something to be sent on the AirDispatch wire. It requires a message that knows how to marshal itself to bytes (ToBytes()), retrieve a header (Header()), and return a message type (Type()).

type SignedMessage Uses

type SignedMessage struct {
    Data        []byte
    Signature   []*wire.Signature
    SigningFunc []byte
    // contains filtered or unexported fields

SignedMessage represents a chunk of data that has been signed by a user of AirDispatch.

func SignMessage Uses

func SignMessage(m Message, id *identity.Identity) (*SignedMessage, error)

SignMessage will sign an object that implements the message interface with an id and return the corresponding SignedMessage.

func (*SignedMessage) AddSignature Uses

func (s *SignedMessage) AddSignature(id *identity.Identity) error

AddSignature will add a new signature of the data by id onto the message. This is useful if you need a SignedMessage to be signed by multiple parties.

func (*SignedMessage) Encrypt Uses

func (s *SignedMessage) Encrypt(addr string, router routing.Router) (*EncryptedMessage, error)

Encrypt will take an address string and a router, and encrypt the message with the key received. This is generally not used, as the application should lookup the key itself based on the routing.LookupType needed.

func (*SignedMessage) EncryptWithKey Uses

func (s *SignedMessage) EncryptWithKey(addr *identity.Address) (*EncryptedMessage, error)

EncryptWithKey will take an *identity.Address that already has a key associated with it and encrypt the SignedMessage with it.

func (*SignedMessage) ReconstructMessage Uses

func (s *SignedMessage) ReconstructMessage() (data []byte, messageType string, header Header, err error)

ReconstructMessage will take the signed chunk of data and return the data, the messageType, the header on the data, and any errors.

Additionally, it will ensure that the Header.From field matches one of the signatures verified during Verify().

func (*SignedMessage) ReconstructMessageWithTimestamp Uses

func (s *SignedMessage) ReconstructMessageWithTimestamp() (data []byte, messageType string, header Header, err error)

ReconstructMessageWithTimestamp will do the same thing as ReconstructMessage but it will ensure that the timestamp is within the last five minutes.

func (*SignedMessage) UnencryptedMessage Uses

func (s *SignedMessage) UnencryptedMessage(addr *identity.Address) (*EncryptedMessage, error)

UnencryptedMessage will take a signed message and an address and turn it into an "EncryptedMessage" to send on the wire without actually encrypting the data.

func (*SignedMessage) Verify Uses

func (s *SignedMessage) Verify() bool

Verify that a signed message is genuine.

Unwinds the R and S values of the ECDSA keypair from the Airdispatch Signature then passes them to the verifyPayload function.

Additionally, it will save which addresses had signatures that were verified to match with Header{} verification later.

Package message imports 17 packages (graph) and is imported by 23 packages. Updated 2018-02-25. Refresh now. Tools for package owners.