object

package
v0.15.6 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: MIT Imports: 17 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ErrInvalidSigner    = errors.Error("signer is does not match owner")
	ErrMissingSignature = errors.Error("missing signature")
	ErrCouldNotVerify   = errors.Error("could not verify signature")
)
View Source
const (
	// AlgorithmObjectHash for creating ObjectHash+ES256 based signatures
	AlgorithmObjectHash = "OH_ES256"
)
View Source
const (
	EmptyHash = Hash("")
)
View Source
const (
	ErrReaderDone = errors.Error("reader done")
)
View Source
const (
	ErrSourceNotSupported = errors.Error("encoding source not supported")
)

Variables

View Source
var (
	// ErrInvalidObjectType is returned when the signature being verified
	// is not an encoded object of type "signature".
	ErrInvalidObjectType = errors.New("invalid object type")
	// ErrAlgorithNotImplemented is returned when the algorithm specified
	// has not been implemented
	ErrAlgorithNotImplemented = errors.New("algorithm not implemented")
)
View Source
var (
	ErrTimeout = errors.New("timeout")
)

Functions

func Decode added in v0.12.0

func Decode(o *Object, v Typed) error

func MetadataToMap added in v0.14.2

func MetadataToMap(m *Metadata) map[string]interface{}

func Normalize added in v0.5.0

func Normalize(
	i interface{},
	c *NormalizeConfig,
) (map[string]interface{}, error)

Normalize maps to get them ready to be used as objects. This is supposed to convert a map's values into something more usable by using the type hints from the key as guide. A lot of what this does is due to the types go's JSON unmarshaller uses when unmarshalling into an `interface{}`. More info about this here: https://golang.org/pkg/encoding/json/#Unmarshal

For example: * `"some-data:d": []float64{1, 2}` becomes `"some-data:d": []byte{1, 2}` * `"some-data:d": "AQI="` becomes `"some-data:d": []byte{1, 2}` * `"some-int:i": float64(7)` becomes `"some-int:i": uint64(7)` * `"some-int:i": "7"` becomes `"some-int:i": uint64(7)`

NOTE: This should work for the most part but needs additional testing.

func NormalizeData added in v0.5.0

func NormalizeData(i interface{}) ([]byte, error)

func SignatureToMap added in v0.14.2

func SignatureToMap(s *Signature) map[string]interface{}

func Traverse added in v0.10.0

func Traverse(v interface{}, f func(string, interface{}) bool)

func UnloadReferences added in v0.11.0

func UnloadReferences(
	ctx context.Context,
	obj *Object,
) (
	result *Object,
	unloaded []*Object,
	err error,
)

func Verify added in v0.5.0

func Verify(o *Object) error

Verify object TODO should this verify nested objects as well?

Types

type Certificate added in v0.5.0

type Certificate struct {
	Metadata Metadata `nimona:"metadata:m,omitempty"`
	Nonce    string   `nimona:"nonce:s,omitempty"`
	Created  string   `nimona:"created:s,omitempty"`
	Expires  string   `nimona:"expires:s,omitempty"`
}

func NewCertificate added in v0.5.0

func NewCertificate(
	subject crypto.PublicKey,
	issuer crypto.PrivateKey,
) (*Certificate, error)

func NewCertificateSelfSigned added in v0.11.0

func NewCertificateSelfSigned(k crypto.PrivateKey) (*Certificate, error)

func (*Certificate) FromObject added in v0.5.0

func (e *Certificate) FromObject(o *Object) error

func (Certificate) ToObject added in v0.5.0

func (e Certificate) ToObject() *Object

func (Certificate) ToObjectMap added in v0.14.4

func (e Certificate) ToObjectMap() map[string]interface{}

func (*Certificate) Type added in v0.12.0

func (e *Certificate) Type() string

type CertificateRequest added in v0.11.0

type CertificateRequest struct {
	Metadata               Metadata `nimona:"metadata:m,omitempty"`
	ApplicationName        string   `nimona:"applicationName:s,omitempty"`
	ApplicationDescription string   `nimona:"applicationDescription:s,omitempty"`
	ApplicationURL         string   `nimona:"applicationURL:s,omitempty"`
	Subject                string   `nimona:"subject:s,omitempty"`
	Resources              []string `nimona:"resources:as,omitempty"`
	Actions                []string `nimona:"actions:as,omitempty"`
	Nonce                  string   `nimona:"nonce:s,omitempty"`
}

func (*CertificateRequest) FromObject added in v0.11.0

func (e *CertificateRequest) FromObject(o *Object) error

func (CertificateRequest) ToObject added in v0.11.0

func (e CertificateRequest) ToObject() *Object

func (CertificateRequest) ToObjectMap added in v0.14.4

func (e CertificateRequest) ToObjectMap() map[string]interface{}

func (*CertificateRequest) Type added in v0.12.0

func (e *CertificateRequest) Type() string

type Getter added in v0.11.0

type Getter interface {
	Get(
		context.Context,
		Hash,
	) (*Object, error)
}

type GetterFunc added in v0.11.0

type GetterFunc func(
	context.Context,
	Hash,
) (*Object, error)

GetterFunc is an adapter to allow the use of ordinary functions as object.Getter

type Hash

type Hash string

func GetReferences added in v0.11.0

func GetReferences(o *Object) []Hash

func NewHash added in v0.5.0

func NewHash(o *Object) (Hash, error)

func SortHashes added in v0.12.0

func SortHashes(a []Hash) []Hash

SortHashes sorts a slice of Hashes in increasing order, and also returns it. The return part is mostly for allowing this to be used as a helper method in tests.

func (Hash) IsEmpty added in v0.5.0

func (h Hash) IsEmpty() bool

func (Hash) String added in v0.5.0

func (h Hash) String() string

type HashSlice added in v0.12.0

type HashSlice []Hash

func (HashSlice) Len added in v0.12.0

func (p HashSlice) Len() int

func (HashSlice) Less added in v0.12.0

func (p HashSlice) Less(i, j int) bool

func (HashSlice) Sort added in v0.12.0

func (p HashSlice) Sort()

func (HashSlice) Swap added in v0.12.0

func (p HashSlice) Swap(i, j int)

type Mapped added in v0.14.4

type Mapped interface {
	ToObjectMap() map[string]interface{}
}

type Metadata added in v0.11.0

type Metadata struct {
	Owner     crypto.PublicKey `json:"owner:s,omitempty" nimona:"owner:s,omitempty"`
	Datetime  string           `json:"datetime:s,omitempty" nimona:"datetime:s,omitempty"`
	Parents   []Hash           `json:"parents:as,omitempty" nimona:"parents:as,omitempty"`
	Policy    Policy           `json:"policy:m,omitempty" nimona:"policy:m,omitempty"`
	Stream    Hash             `json:"stream:s,omitempty" nimona:"stream:s,omitempty"`
	Signature Signature        `json:"_signature:m,omitempty" nimona:"_signature:m,omitempty"`
}

Metadata for object

type NormalizeConfig added in v0.14.4

type NormalizeConfig struct {
	ObjectToMap bool
}

type Object

type Object struct {
	Type     string                 `json:"type:s,omitempty" nimona:"type:s,omitempty"`
	Metadata Metadata               `json:"metadata:m,omitempty" nimona:"metadata:m,omitempty"`
	Data     map[string]interface{} `json:"data:m,omitempty" nimona:"data:m,omitempty"`
}

func Copy

func Copy(s *Object) *Object

func Encode added in v0.12.0

func Encode(v interface{}) (*Object, error)

func FromMap

func FromMap(m map[string]interface{}) *Object

func LoadReferences added in v0.11.0

func LoadReferences(
	ctx context.Context,
	objectHash Hash,
	getter GetterFunc,
) (*Object, error)

LoadReferences will look for references in the given object, request the referred objects using the getter, and will replace the references with the actual object before returning the complete

func ReadAll added in v0.11.0

func ReadAll(r Reader) ([]*Object, error)

ReadAll is a helper method that

func (*Object) Hash

func (o *Object) Hash() Hash

func (Object) ToMap

func (o Object) ToMap() map[string]interface{}

type ParsedType added in v0.11.0

type ParsedType struct {
	PrimaryType string
	Namespace   string
	Object      string
}

func ParseType added in v0.11.0

func ParseType(objectType string) ParsedType

type Policy

type Policy struct {
	Subjects  []string `json:"subjects:as,omitempty" nimona:"subjects:as,omitempty"`
	Resources []string `json:"resources:as,omitempty" nimona:"resources:as,omitempty"`
	Actions   []string `json:"actions:as,omitempty" nimona:"actions:as,omitempty"`
	Effect    string   `json:"effect:s,omitempty" nimona:"effect:s,omitempty"`
}

Policy for object metadata

type ReadCloser added in v0.11.0

type ReadCloser interface {
	Read() (*Object, error)
	Close()
}

func FetchWithReferences added in v0.11.0

func FetchWithReferences(
	ctx context.Context,
	getter GetterFunc,
	objectHash Hash,
) (ReadCloser, error)

FetchWithReferences will look for references in the given object, request the primary object and all referred objects using the getter, and will return them in a lazy loaded result.

func NewReadCloser added in v0.11.0

func NewReadCloser(
	ctx context.Context,
	objects <-chan *Object,
	errs <-chan error,
	closer chan<- struct{},
) ReadCloser

func NewReadCloserFromObjects added in v0.11.0

func NewReadCloserFromObjects(objects []*Object) ReadCloser

NewReadCloserFromObjects is mainly used for testing and mocks that return a Reader, or ReadCloser.

type Reader added in v0.11.0

type Reader interface {
	Read() (*Object, error)
}

type Request added in v0.11.0

type Request struct {
	Metadata   Metadata `nimona:"metadata:m,omitempty"`
	RequestID  string   `nimona:"requestID:s,omitempty"`
	ObjectHash Hash     `nimona:"objectHash:r,omitempty"`
}

func (*Request) FromObject added in v0.11.0

func (e *Request) FromObject(o *Object) error

func (Request) ToObject added in v0.11.0

func (e Request) ToObject() *Object

func (Request) ToObjectMap added in v0.14.4

func (e Request) ToObjectMap() map[string]interface{}

func (*Request) Type added in v0.12.0

func (e *Request) Type() string

type Response added in v0.11.0

type Response struct {
	Metadata  Metadata `nimona:"metadata:m,omitempty"`
	RequestID string   `nimona:"requestID:s,omitempty"`
	Object    *Object  `nimona:"object:o,omitempty"`
}

func (*Response) FromObject added in v0.11.0

func (e *Response) FromObject(o *Object) error

func (Response) ToObject added in v0.11.0

func (e Response) ToObject() *Object

func (Response) ToObjectMap added in v0.14.4

func (e Response) ToObjectMap() map[string]interface{}

func (*Response) Type added in v0.12.0

func (e *Response) Type() string

type Signature added in v0.5.0

type Signature struct {
	Signer      crypto.PublicKey `nimona:"signer:s,omitempty"`
	Alg         string           `nimona:"alg:s,omitempty"`
	X           []byte           `nimona:"x:d,omitempty"`
	Certificate *Certificate     `nimona:"certificate:m,omitempty"`
}

func NewSignature added in v0.5.0

func NewSignature(
	k crypto.PrivateKey,
	o *Object,
) (Signature, error)

NewSignature returns a signature given some bytes and a private key

func (Signature) IsEmpty added in v0.5.0

func (s Signature) IsEmpty() bool

type TypeHint

type TypeHint string

TypeHint are the hints of a member's type

const (
	HintUndefined TypeHint = ""
	HintArray     TypeHint = "a"
	HintBool      TypeHint = "b"
	HintData      TypeHint = "d"
	HintFloat     TypeHint = "f"
	HintInt       TypeHint = "i"
	HintMap       TypeHint = "m"
	HintNil       TypeHint = "n"
	HintObject    TypeHint = "o"
	HintRef       TypeHint = "r"
	HintString    TypeHint = "s"
	HintUint      TypeHint = "u"
)

func GetTypeHint

func GetTypeHint(t string) TypeHint

GetTypeHint returns a TypeHint from a string

func (TypeHint) String

func (t TypeHint) String() string

String implements the Stringer interface

type Typed added in v0.12.0

type Typed interface {
	Type() string
}

Jump to

Keyboard shortcuts

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