object

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2020 License: MIT Imports: 13 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 Traverse added in v0.10.0

func Traverse(v Value, f func(string, Value) bool)

func Verify added in v0.5.0

func Verify(o Object) error

Verify object

Types

type Bool added in v0.10.0

type Bool bool

func (Bool) Hash added in v0.10.0

func (v Bool) Hash() Hash

func (Bool) IsBool added in v0.10.0

func (v Bool) IsBool() bool

func (Bool) IsBytes added in v0.10.0

func (v Bool) IsBytes() bool

func (Bool) IsFloat added in v0.10.0

func (v Bool) IsFloat() bool

func (Bool) IsInt added in v0.10.0

func (v Bool) IsInt() bool

func (Bool) IsList added in v0.10.0

func (v Bool) IsList() bool

func (Bool) IsMap added in v0.10.0

func (v Bool) IsMap() bool

func (Bool) IsRef added in v0.10.0

func (v Bool) IsRef() bool

func (Bool) IsString added in v0.10.0

func (v Bool) IsString() bool

func (Bool) PrimitiveHinted added in v0.10.0

func (v Bool) PrimitiveHinted() interface{}

type Bytes added in v0.10.0

type Bytes []byte

func (Bytes) Hash added in v0.10.0

func (v Bytes) Hash() Hash

func (Bytes) IsBool added in v0.10.0

func (v Bytes) IsBool() bool

func (Bytes) IsBytes added in v0.10.0

func (v Bytes) IsBytes() bool

func (Bytes) IsFloat added in v0.10.0

func (v Bytes) IsFloat() bool

func (Bytes) IsInt added in v0.10.0

func (v Bytes) IsInt() bool

func (Bytes) IsList added in v0.10.0

func (v Bytes) IsList() bool

func (Bytes) IsMap added in v0.10.0

func (v Bytes) IsMap() bool

func (Bytes) IsRef added in v0.10.0

func (v Bytes) IsRef() bool

func (Bytes) IsString added in v0.10.0

func (v Bytes) IsString() bool

func (Bytes) PrimitiveHinted added in v0.10.0

func (v Bytes) PrimitiveHinted() interface{}

type Float added in v0.10.0

type Float float64

func (Float) Hash added in v0.10.0

func (v Float) Hash() Hash

func (Float) IsBool added in v0.10.0

func (v Float) IsBool() bool

func (Float) IsBytes added in v0.10.0

func (v Float) IsBytes() bool

func (Float) IsFloat added in v0.10.0

func (v Float) IsFloat() bool

func (Float) IsInt added in v0.10.0

func (v Float) IsInt() bool

func (Float) IsList added in v0.10.0

func (v Float) IsList() bool

func (Float) IsMap added in v0.10.0

func (v Float) IsMap() bool

func (Float) IsRef added in v0.10.0

func (v Float) IsRef() bool

func (Float) IsString added in v0.10.0

func (v Float) IsString() bool

func (Float) PrimitiveHinted added in v0.10.0

func (v Float) PrimitiveHinted() interface{}

type Hash

type Hash string

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 Int added in v0.10.0

type Int int64

func (Int) Hash added in v0.10.0

func (v Int) Hash() Hash

func (Int) IsBool added in v0.10.0

func (v Int) IsBool() bool

func (Int) IsBytes added in v0.10.0

func (v Int) IsBytes() bool

func (Int) IsFloat added in v0.10.0

func (v Int) IsFloat() bool

func (Int) IsInt added in v0.10.0

func (v Int) IsInt() bool

func (Int) IsList added in v0.10.0

func (v Int) IsList() bool

func (Int) IsMap added in v0.10.0

func (v Int) IsMap() bool

func (Int) IsRef added in v0.10.0

func (v Int) IsRef() bool

func (Int) IsString added in v0.10.0

func (v Int) IsString() bool

func (Int) PrimitiveHinted added in v0.10.0

func (v Int) PrimitiveHinted() interface{}

type List added in v0.10.0

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

func (List) Append added in v0.10.0

func (l List) Append(v Value) List

func (List) Hash added in v0.10.0

func (v List) Hash() Hash

func (List) IsBool added in v0.10.0

func (v List) IsBool() bool

func (List) IsBytes added in v0.10.0

func (v List) IsBytes() bool

func (List) IsFloat added in v0.10.0

func (v List) IsFloat() bool

func (List) IsInt added in v0.10.0

func (v List) IsInt() bool

func (List) IsList added in v0.10.0

func (v List) IsList() bool

func (List) IsMap added in v0.10.0

func (v List) IsMap() bool

func (List) IsRef added in v0.10.0

func (v List) IsRef() bool

func (List) IsString added in v0.10.0

func (v List) IsString() bool

func (List) Iterate added in v0.10.0

func (l List) Iterate(f func(v Value) bool)

func (List) Length added in v0.10.0

func (l List) Length() (n int)

func (List) PrimitiveHinted added in v0.10.0

func (l List) PrimitiveHinted() interface{}

type Map added in v0.10.0

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

func (Map) Hash added in v0.10.0

func (v Map) Hash() Hash

func (Map) IsBool added in v0.10.0

func (v Map) IsBool() bool

func (Map) IsBytes added in v0.10.0

func (v Map) IsBytes() bool

func (Map) IsEmpty added in v0.10.0

func (m Map) IsEmpty() bool

func (Map) IsFloat added in v0.10.0

func (v Map) IsFloat() bool

func (Map) IsInt added in v0.10.0

func (v Map) IsInt() bool

func (Map) IsList added in v0.10.0

func (v Map) IsList() bool

func (Map) IsMap added in v0.10.0

func (v Map) IsMap() bool

func (Map) IsRef added in v0.10.0

func (v Map) IsRef() bool

func (Map) IsString added in v0.10.0

func (v Map) IsString() bool

func (Map) Iterate added in v0.10.0

func (m Map) Iterate(f func(k string, v Value) bool)

func (Map) PrimitiveHinted added in v0.10.0

func (m Map) PrimitiveHinted() interface{}

func (Map) Set added in v0.10.0

func (m Map) Set(k string, v Value) Map

func (Map) Value added in v0.10.0

func (m Map) Value(k string) Value

type Object

type Object 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) Hash

func (o Object) Hash() Hash

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() 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 Ref added in v0.10.0

type Ref Hash

func (Ref) Hash added in v0.10.0

func (v Ref) Hash() Hash

refs don't get re-hashed

func (Ref) IsBool added in v0.10.0

func (v Ref) IsBool() bool

func (Ref) IsBytes added in v0.10.0

func (v Ref) IsBytes() bool

func (Ref) IsFloat added in v0.10.0

func (v Ref) IsFloat() bool

func (Ref) IsInt added in v0.10.0

func (v Ref) IsInt() bool

func (Ref) IsList added in v0.10.0

func (v Ref) IsList() bool

func (Ref) IsMap added in v0.10.0

func (v Ref) IsMap() bool

func (Ref) IsRef added in v0.10.0

func (v Ref) IsRef() bool

func (Ref) IsString added in v0.10.0

func (v Ref) IsString() bool

func (Ref) PrimitiveHinted added in v0.10.0

func (v Ref) PrimitiveHinted() interface{}

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 String added in v0.10.0

type String string

func (String) Hash added in v0.10.0

func (v String) Hash() Hash

func (String) IsBool added in v0.10.0

func (v String) IsBool() bool

func (String) IsBytes added in v0.10.0

func (v String) IsBytes() bool

func (String) IsFloat added in v0.10.0

func (v String) IsFloat() bool

func (String) IsInt added in v0.10.0

func (v String) IsInt() bool

func (String) IsList added in v0.10.0

func (v String) IsList() bool

func (String) IsMap added in v0.10.0

func (v String) IsMap() bool

func (String) IsRef added in v0.10.0

func (v String) IsRef() bool

func (String) IsString added in v0.10.0

func (v String) IsString() bool

func (String) PrimitiveHinted added in v0.10.0

func (v String) PrimitiveHinted() interface{}

type TypeHint

type TypeHint string

TypeHint are the hints of a member's type

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

func DeduceTypeHint

func DeduceTypeHint(o interface{}) TypeHint

DeduceTypeHint returns a TypeHint from a given value

func (TypeHint) String

func (t TypeHint) String() string

String implements the Stringer interface

type Value added in v0.10.0

type Value interface {
	PrimitiveHinted() interface{}
	Hash() Hash

	IsList() bool
	IsMap() bool
	IsBool() bool
	IsString() bool
	IsRef() bool
	IsInt() bool
	IsFloat() bool
	IsBytes() bool
	// contains filtered or unexported methods
}

func AnyToValue added in v0.10.0

func AnyToValue(k string, a interface{}) Value

nolint: gocritic

Jump to

Keyboard shortcuts

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