payload

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2019 License: Unlicense Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxSigBundleCount is the upper limit of signatures
	// allowed for a single payload
	MaxSigBundleCount = 4
	// MaxPayloadSize is intended to by used by a LimitedReader
	// to enforce a strict upper limit on payload size
	MaxPayloadSize = 128 * 1024 // 128 KB
	// MaxMessageSize Payload.Data
	MaxMessageSize = 512 // bytes
	// MaxSubmitWindow is the time drift allow between a submission
	// to hashmap server and the time reflected on a signed payload
	MaxSubmitWindow = 5 * time.Second
	// MinTTL is the minimum value of a TTL for a payload
	MinTTL = 0 * time.Second
	// MaxTTL is the maximum value of a TTL for a payload
	MaxTTL = 24 * 7 * time.Hour // 1 week
)
View Source
const (
	// DefaultTTL is set to 24 hours
	DefaultTTL = 24 * time.Hour
)

Variables

This section is empty.

Functions

func Marshal

func Marshal(p Payload) ([]byte, error)

Marshal takes a Payload and encodes it into the protobuf wire format. This does not apply any Payload verification. Verification should happen before marshalling.

Types

type Option

type Option func(*options)

Option is used for interacting with Context when setting options for Generate and Verify

func WithReferenceTime

func WithReferenceTime(t time.Time) Option

WithReferenceTime sets time for options.validate.referenceTime and is used for the Verify method. referenceTime defaults to time.Now

func WithServerMode

func WithServerMode(b bool) Option

WithServerMode sets options.validate.submitTime boolean. Defaults to false. Setting to false will skip validation when using the payload Verify method

func WithTTL

func WithTTL(d time.Duration) Option

WithTTL takes a time.Duration and returns an Option

func WithTimestamp

func WithTimestamp(t time.Time) Option

WithTimestamp takes a time.Time and returns an Option

func WithValidateDataSize

func WithValidateDataSize(b bool) Option

WithValidateDataSize sets options.validate.dataSize boolean. Defaults to true. Setting to false will skip validation when using the payload Verify method

func WithValidateEndpoint

func WithValidateEndpoint(e string) Option

WithValidateEndpoint sets the endpoint string for options.validate.endpoint and is used for the Verify method. endpoint defaults to and empty string.

func WithValidateExpiration

func WithValidateExpiration(b bool) Option

WithValidateExpiration sets options.validate.expiration boolean. Defaults to true. Setting to false will skip validation when using the payload Verify method

func WithValidateFuture

func WithValidateFuture(b bool) Option

WithValidateFuture sets options.validate.futureTime boolean. Defaults to true. Setting to false will skip validation when using the payload Verify method

func WithValidatePayloadSize

func WithValidatePayloadSize(b bool) Option

WithValidatePayloadSize sets options.validate.payloadSize boolean. Defaults to true. Setting to false will skip validation when using the payload Verify method

func WithValidateTTL

func WithValidateTTL(b bool) Option

WithValidateTTL sets options.validate.ttl boolean. Defaults to true. Setting to false will skip validation when using the payload Verify method

func WithValidateVersion

func WithValidateVersion(b bool) Option

WithValidateVersion sets options.validate.version boolean. Defaults to true. Setting to false will skip validation when using the payload Verify method

func WithVersion

func WithVersion(v Version) Option

WithVersion takes a Version and returns an Option

type Payload

type Payload struct {
	Version    Version
	Timestamp  time.Time
	TTL        time.Duration
	SigBundles []sig.Bundle
	Data       []byte
}

Payload holds all information related to a Hashmap Payload that will be handled for signing and validation. This struct is used by both client and server and includes all necessary methods for encoding, decoding, signing, an verifying itself.

func Generate

func Generate(message []byte, signers []sig.Signer, opts ...Option) (Payload, error)

Generate takes a message, signers, and a set of options and returns a payload or error. This function defaults to time.Now() and the default TTL of 24 hours. Generate Requires at least one signer, but can sign with many signers. Sort order is important though, The unique order of the signers pubkeys are what is responsible for generating the endpoint hash.

func Unmarshal

func Unmarshal(b []byte) (Payload, error)

Unmarshal takes a byte slice and attempts to decode the protobuf wire format into a Payload. This does not apply any Payload verification. Verification should happen after Unmarshalling.

func (Payload) Endpoint

func (p Payload) Endpoint() string

Endpoint returns a url-safe base64 encoded endpoint string of PubKeyHash

func (Payload) IsExpired

func (p Payload) IsExpired(t time.Time) bool

IsExpired checks the reference time t against the timestamp and TTL of a payload and returns a boolean value on whether or not the TTL has been exceeded

func (Payload) IsInFuture

func (p Payload) IsInFuture(t time.Time) bool

IsInFuture checks if the payload timestamp is too far into the future based on the reference time t plus the MaxSubmitWindow.

func (Payload) PubKeyBytes

func (p Payload) PubKeyBytes() []byte

PubKeyBytes returns a byte slice of all pubkeys concatenated in the index order of the slice of sig.Bundles. This is intended to be used with a hash function to derive the unique endpoint for a payload on hashmap server.

func (Payload) PubKeyHash

func (p Payload) PubKeyHash() []byte

PubKeyHash returns a byte slice of the blake2b-512 hash of PubKeyBytes

func (Payload) SigningBytes

func (p Payload) SigningBytes() []byte

SigningBytes returns a byte slice of version|timestamp|ttl|len|data used as the message to be signed by a Signer.

func (Payload) ValidDataSize

func (p Payload) ValidDataSize() bool

ValidDataSize checks that the length of Payload.Data is less than or equal to the MaxMessageSize and returns a boolean value.

func (Payload) ValidEndpoint

func (p Payload) ValidEndpoint(e string) bool

ValidEndpoint takes a string and attempts to match the URL safe base64 string encoded PubKeyHash and returns a boolean

func (Payload) ValidPayloadSize

func (p Payload) ValidPayloadSize() bool

ValidPayloadSize checks that the wire protocol bytes are less than or equal to the MaxPayloadSize allowed and returns a boolean value.

func (Payload) ValidTTL

func (p Payload) ValidTTL() bool

ValidTTL checks that a TTL falls within an acceptable range.

func (Payload) ValidVersion

func (p Payload) ValidVersion() bool

ValidVersion returns whether version is supported by Hashmap Currently only V1 is supported.

func (Payload) Verify

func (p Payload) Verify(options ...Option) error

Verify method takes a set of options and implements the Verify function

func (Payload) VerifySignatures

func (p Payload) VerifySignatures() bool

VerifySignatures checks all signatures in the sigBundles. If all signatures are valid, it returns `true`.

func (Payload) WithinSubmitWindow

func (p Payload) WithinSubmitWindow(t time.Time) bool

WithinSubmitWindow checks reference time t against the payload timestamp, validates that it exists within the MaxSubmitWindow and returns a boolean.

type Version

type Version int32

Version type is used for setting the hashmap implementation version.

const (
	// V0 is deprecated and should be deemed invalid
	V0 Version = iota
	// V1 is the current version of the payload spec
	V1
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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