message

package
v5.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: BSD-2-Clause, BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRequestContentsSize

func GetRequestContentsSize(payloadSize int) int

GetRequestContentsSize returns the size of the contents of a RequestPayload given the payload size.

func GetRequestPartContentsSize

func GetRequestPartContentsSize(externalPayloadSize int) int

GetRequestPartContentsSize returns the size of the contents for the given external payload size.

func GetRequestPayloadSize

func GetRequestPayloadSize(externalPayloadSize, pubKeySize int) int

GetRequestPayloadSize returns the size of the payload for the given external payload size and public key size.

Types

type Collator

type Collator struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Collator stores the list of payloads in the correct order.

func NewCollator

func NewCollator(messageCount uint8) *Collator

NewCollator generates an empty list of payloads to fit the max number of possible messages. maxNum is set to indicate that it is not yet set.

func (*Collator) Collate

func (c *Collator) Collate(part Part) ([]byte, bool, error)

Collate collects message payload parts. Once all parts are received, the full collated payload is returned along with true. Otherwise, returns false.

type Part

type Part interface {
	// GetNumParts returns the total number of parts in the message.
	GetNumParts() uint8

	// GetPartNum returns the index of this part in the message.
	GetPartNum() uint8

	// GetContents returns the contents of the message part.
	GetContents() []byte
}

type Request

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

func NewRequest

func NewRequest(externalPayloadSize, pubKeySize int) Request

NewRequest generates a new empty message for a request that is the size of the specified external payload.

func UnmarshalRequest

func UnmarshalRequest(b []byte, pubKeySize int) (Request, error)

UnmarshalRequest unmarshalls a byte slice into a Request. An error is returned if the slice is not large enough for the public key size.

func (Request) GetPayload

func (m Request) GetPayload() []byte

GetPayload returns the encrypted payload of the message.

func (Request) GetPayloadSize

func (m Request) GetPayloadSize() int

GetPayloadSize returns the length of the encrypted payload.

func (Request) GetPubKey

func (m Request) GetPubKey(grp *cyclic.Group) *cyclic.Int

GetPubKey returns the public key that is part of the given group.

func (Request) GetPubKeySize

func (m Request) GetPubKeySize() int

GetPubKeySize returns the length of the public key.

func (Request) Marshal

func (m Request) Marshal() []byte

Marshal returns the serialised data of a Request.

func (Request) SetPayload

func (m Request) SetPayload(payload []byte)

SetPayload saves the supplied bytes as the payload of the message, if the size is correct.

func (Request) SetPubKey

func (m Request) SetPubKey(pubKey *cyclic.Int)

SetPubKey saves the public key to the message as bytes.

func (Request) Version

func (m Request) Version() uint8

Version returns the version of the message.

type RequestPart

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

func NewRequestPart

func NewRequestPart(externalPayloadSize int) RequestPart

NewRequestPart generates a new request message part of the specified size.

func UnmarshalRequestPart

func UnmarshalRequestPart(b []byte) (RequestPart, error)

UnmarshalRequestPart converts a byte buffer into a request message part.

func (RequestPart) GetContents

func (m RequestPart) GetContents() []byte

GetContents returns the contents of the message part.

func (RequestPart) GetContentsSize

func (m RequestPart) GetContentsSize() int

GetContentsSize returns the length of the contents.

func (RequestPart) GetMaxContentsSize

func (m RequestPart) GetMaxContentsSize() int

GetMaxContentsSize returns the max capacity of the contents.

func (RequestPart) GetNumParts

func (m RequestPart) GetNumParts() uint8

GetNumParts always returns 0. It is here so that RequestPart adheres to th Part interface.

func (RequestPart) GetPartNum

func (m RequestPart) GetPartNum() uint8

GetPartNum returns the index of this part in the message.

func (RequestPart) Marshal

func (m RequestPart) Marshal() []byte

Marshal returns the bytes of the message part.

func (RequestPart) SetContents

func (m RequestPart) SetContents(contents []byte)

SetContents sets the contents of the message part. Does not zero out previous contents.

func (RequestPart) SetPartNum

func (m RequestPart) SetPartNum(num uint8)

SetPartNum sets the part number of the message.

type RequestPayload

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

RequestPayload is the structure of Request's payload.

func NewRequestPayload

func NewRequestPayload(payloadSize int, payload []byte, maxMsgs uint8) RequestPayload

NewRequestPayload generates a new empty message for request that is the size of the specified payload, which should match the size of the payload in the corresponding Request.

func UnmarshalRequestPayload

func UnmarshalRequestPayload(b []byte) (RequestPayload, error)

UnmarshalRequestPayload unmarshalls a byte slice into a RequestPayload. An error is returned if the slice is not large enough for the reception ID and message count.

func (RequestPayload) GetContents

func (mp RequestPayload) GetContents() []byte

GetContents returns the payload's contents.

func (RequestPayload) GetContentsSize

func (mp RequestPayload) GetContentsSize() int

GetContentsSize returns the length of payload's contents.

func (RequestPayload) GetMaxContentsSize

func (mp RequestPayload) GetMaxContentsSize() int

GetMaxContentsSize returns the max capacity of the contents.

func (RequestPayload) GetMaxResponseParts

func (mp RequestPayload) GetMaxResponseParts() uint8

GetMaxResponseParts returns the maximum number of response messages allowed.

func (RequestPayload) GetNonce

func (mp RequestPayload) GetNonce() uint64

GetNonce returns the nonce as an uint64.

func (RequestPayload) GetNumParts

func (mp RequestPayload) GetNumParts() uint8

GetNumParts returns the number of messages in the request. This function wraps GetMaxRequestParts so that RequestPayload adheres to the Part interface.

func (RequestPayload) GetNumRequestParts

func (mp RequestPayload) GetNumRequestParts() uint8

GetNumRequestParts returns the number of messages in the request.

func (RequestPayload) GetPartNum

func (mp RequestPayload) GetPartNum() uint8

GetPartNum always returns 0 since it is the first message.

func (RequestPayload) GetRecipientID

func (mp RequestPayload) GetRecipientID(pubKey *cyclic.Int) *id.ID

GetRecipientID generates the recipient ID from the bytes of the payload.

func (RequestPayload) Marshal

func (mp RequestPayload) Marshal() []byte

Marshal returns the serialised data of a RequestPayload.

func (RequestPayload) SetContents

func (mp RequestPayload) SetContents(contents []byte)

SetContents saves the contents to the payload, if the size is correct. Does not zero out previous content.

func (RequestPayload) SetMaxResponseParts

func (mp RequestPayload) SetMaxResponseParts(num uint8)

SetMaxResponseParts sets the maximum number of response messages allowed.

func (RequestPayload) SetNonce

func (mp RequestPayload) SetNonce(rng io.Reader) error

SetNonce generates a random nonce from the RNG. An error is returned if the reader fails.

func (RequestPayload) SetNumRequestParts

func (mp RequestPayload) SetNumRequestParts(num uint8)

SetNumRequestParts sets the number of messages in the request.

func (RequestPayload) String

func (mp RequestPayload) String() string

String returns the contents of a RequestPayload as a human-readable string. This function adheres to the fmt.Stringer interface.

type ResponsePart

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

func NewResponsePart

func NewResponsePart(externalPayloadSize int) ResponsePart

NewResponsePart generates a new response message part of the specified size.

func UnmarshalResponsePart

func UnmarshalResponsePart(data []byte) (ResponsePart, error)

UnmarshalResponsePart converts a byte buffer into a response message part.

func (ResponsePart) GetContents

func (m ResponsePart) GetContents() []byte

GetContents returns the contents of the message part.

func (ResponsePart) GetContentsSize

func (m ResponsePart) GetContentsSize() int

GetContentsSize returns the length of the contents.

func (ResponsePart) GetMaxContentsSize

func (m ResponsePart) GetMaxContentsSize() int

GetMaxContentsSize returns the max capacity of the contents.

func (ResponsePart) GetNumParts

func (m ResponsePart) GetNumParts() uint8

GetNumParts returns the number of parts in the message.

func (ResponsePart) GetPartNum

func (m ResponsePart) GetPartNum() uint8

GetPartNum returns the index of this part in the message.

func (ResponsePart) Marshal

func (m ResponsePart) Marshal() []byte

Marshal returns the bytes of the message part.

func (ResponsePart) SetContents

func (m ResponsePart) SetContents(contents []byte)

SetContents sets the contents of the message part. Does not zero out previous contents.

func (ResponsePart) SetNumParts

func (m ResponsePart) SetNumParts(max uint8)

SetNumParts sets the number of parts in the message.

func (ResponsePart) SetPartNum

func (m ResponsePart) SetPartNum(num uint8)

SetPartNum sets the part number of the message.

Jump to

Keyboard shortcuts

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