object

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2020 License: MIT Imports: 15 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// AlgorithmObjectHash for creating ObjectHash+ES256 based signatures
	AlgorithmObjectHash = "OH_ES256"
)
View Source
const (
	// ErrCouldNotVerify is returned when the signature doesn't matches the
	// given key
	ErrCouldNotVerify = errors.Error("could not verify signature")
)

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")
)

Functions

func Dump

func Dump(o Object, skipKeys ...string) string

Dump returns the object as pretty-printed json

func Normalize added in v0.5.0

func Normalize(i interface{}) (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 Verify added in v0.5.0

func Verify(o Object) error

Verify object

Types

type Certificate added in v0.5.0

type Certificate struct {
	Stream     Hash
	Parents    []Hash
	Owners     []crypto.PublicKey
	Policy     Policy
	Signatures []Signature
	Subject    crypto.PublicKey
	Created    string
	Expires    string
	// contains filtered or unexported fields
}

func NewCertificate added in v0.5.0

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

func NewSelfSignedCertificate added in v0.5.0

func NewSelfSignedCertificate(k crypto.PrivateKey) *Certificate

func (*Certificate) FromObject added in v0.5.0

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

func (Certificate) GetSchema added in v0.5.0

func (e Certificate) GetSchema() *SchemaObject

func (Certificate) GetType added in v0.5.0

func (e Certificate) GetType() string

func (Certificate) ToObject added in v0.5.0

func (e Certificate) ToObject() Object

type Hash

type Hash string

func HashFromBytes added in v0.5.0

func HashFromBytes(b []byte) Hash

func NewHash added in v0.5.0

func NewHash(o Object) Hash

New consistently hashes a map. It is based on Ben Laurie's object hash, but using the same type hints as TJSON instead. TODO add redaction

func (Hash) Bytes added in v0.5.0

func (h Hash) Bytes() []byte

func (Hash) IsEmpty added in v0.5.0

func (h Hash) IsEmpty() bool

func (Hash) IsEqual added in v0.5.0

func (h Hash) IsEqual(c Hash) bool

func (Hash) String added in v0.5.0

func (h Hash) String() string

type Object

type Object immutable.Map

Object for everything f12n

func FromMap

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

FromMap returns an object from a map

func (Object) AddSignature added in v0.5.1

func (o Object) AddSignature(vs ...Signature) Object

func (Object) Get added in v0.4.0

func (o Object) Get(k string) interface{}

Get -

func (Object) GetOwners added in v0.5.0

func (o Object) GetOwners() []crypto.PublicKey

func (Object) GetParents

func (o Object) GetParents() []Hash

func (Object) GetPolicy

func (o Object) GetPolicy() Policy

func (Object) GetSignatures added in v0.5.1

func (o Object) GetSignatures() []Signature

func (Object) GetStream added in v0.5.0

func (o Object) GetStream() Hash

func (Object) GetType

func (o Object) GetType() string

func (Object) IsEmpty added in v0.5.0

func (o Object) IsEmpty() bool

IsEmpty returns whether the object is empty

func (Object) Raw added in v0.5.0

func (o Object) Raw() immutable.Map

func (Object) Set added in v0.4.0

func (o Object) Set(k string, v interface{}) Object

Set -

func (Object) SetOwners added in v0.5.0

func (o Object) SetOwners(owners []crypto.PublicKey) Object

func (Object) SetParents

func (o Object) SetParents(hashes []Hash) Object

func (Object) SetPolicy

func (o Object) SetPolicy(policy Policy) Object

func (Object) SetStream added in v0.5.0

func (o Object) SetStream(v Hash) Object

func (Object) SetType

func (o Object) SetType(v string) Object

func (Object) ToMap

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

ToMap returns the object as a map

func (Object) ToObject

func (o Object) ToObject() Object

ToObject returns the same object, this is a helper method for codegen

type Policy

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

Policy for object

func (Policy) IsEmpty added in v0.5.0

func (v Policy) IsEmpty() bool

type SchemaObject added in v0.5.0

type SchemaObject struct {
	Stream     Hash
	Parents    []Hash
	Owners     []crypto.PublicKey
	Policy     Policy
	Signatures []Signature
	Properties []*SchemaProperty
	// contains filtered or unexported fields
}

func (*SchemaObject) FromObject added in v0.5.0

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

func (SchemaObject) GetType added in v0.5.0

func (e SchemaObject) GetType() string

func (SchemaObject) ToObject added in v0.5.0

func (e SchemaObject) ToObject() Object

type SchemaProperty added in v0.5.0

type SchemaProperty struct {
	Stream     Hash
	Parents    []Hash
	Owners     []crypto.PublicKey
	Policy     Policy
	Signatures []Signature
	Name       string
	Type       string
	Hint       string
	IsRepeated bool
	IsOptional bool
	Properties []*SchemaProperty
	// contains filtered or unexported fields
}

func (*SchemaProperty) FromObject added in v0.5.0

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

func (SchemaProperty) GetType added in v0.5.0

func (e SchemaProperty) GetType() string

func (SchemaProperty) ToObject added in v0.5.0

func (e SchemaProperty) ToObject() Object

type Signature added in v0.5.0

type Signature struct {
	Signer crypto.PublicKey `json:"signer:s,omitempty" mapstructure:"signer:s,omitempty"`
	Alg    string           `json:"alg:s,omitempty" mapstructure:"alg:s,omitempty"`
	X      []byte           `json:"x:d,omitempty" mapstructure:"x:d,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 (v Signature) IsEmpty() bool

func (Signature) ToMap added in v0.5.0

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

type TypeHint

type TypeHint string

TypeHint are the hints of a member's type

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

func DeduceTypeHint

func DeduceTypeHint(o interface{}) TypeHint

DeduceTypeHint returns a TypeHint from a given value

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

Jump to

Keyboard shortcuts

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