Documentation ¶
Index ¶
- Constants
- Variables
- func Decode(o *Object, v Typed) error
- func MetadataToMap(m *Metadata) map[string]interface{}
- func Normalize(i interface{}, c *NormalizeConfig) (map[string]interface{}, error)
- func NormalizeData(i interface{}) ([]byte, error)
- func SignatureToMap(s *Signature) map[string]interface{}
- func Traverse(v interface{}, f func(string, interface{}) bool)
- func UnloadReferences(ctx context.Context, obj *Object) (result *Object, unloaded []*Object, err error)
- func Verify(o *Object) error
- type Certificate
- type CertificateRequest
- type Getter
- type GetterFunc
- type Hash
- type HashSlice
- type Mapped
- type Metadata
- type NormalizeConfig
- type Object
- type ParsedType
- type Policy
- type ReadCloser
- type Reader
- type Request
- type Response
- type Signature
- type TypeHint
- type Typed
Constants ¶
const ( ErrInvalidSigner = errors.Error("signer is does not match owner") ErrMissingSignature = errors.Error("missing signature") ErrCouldNotVerify = errors.Error("could not verify signature") )
const (
// AlgorithmObjectHash for creating ObjectHash+ES256 based signatures
AlgorithmObjectHash = "OH_ES256"
)
const (
EmptyHash = Hash("")
)
const (
ErrReaderDone = errors.Error("reader done")
)
const (
ErrSourceNotSupported = errors.Error("encoding source not supported")
)
Variables ¶
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") )
var (
ErrTimeout = errors.New("timeout")
)
Functions ¶
func MetadataToMap ¶ added in v0.14.2
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 SignatureToMap ¶ added in v0.14.2
func UnloadReferences ¶ added in v0.11.0
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 GetterFunc ¶ added in v0.11.0
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 SortHashes ¶ added in v0.12.0
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.
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 LoadReferences ¶ added in v0.11.0
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
type ParsedType ¶ added in v0.11.0
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
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 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 (Request) ToObjectMap ¶ added in v0.14.4
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 (Response) ToObjectMap ¶ added in v0.14.4
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
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" )