signature

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: Apache-2.0 Imports: 11 Imported by: 4

Documentation

Overview

Package signature implements the interfaces, types, and utility functions that can be used by Guest and Host implementations of Scale Signatures.

Index

Constants

View Source
const MasterTestingSchema = `` /* 5119-byte string literal not displayed */
View Source
const (
	V1AlphaVersion = "v1alpha"
)

Variables

View Source
var (
	ValidLabel    = regexp.MustCompile(`^[A-Za-z0-9]*$`)
	InvalidString = regexp.MustCompile(`[^A-Za-z0-9-.]`)
)
View Source
var (
	TitleCaser = cases.Title(language.Und, cases.NoLower)
)

Functions

func ValidPrimitiveType

func ValidPrimitiveType(t string) bool

Types

type BoolArraySchema

type BoolArraySchema struct {
	Name        string `hcl:"name,label"`
	InitialSize uint32 `hcl:"initial_size,attr"`
	Accessor    bool   `hcl:"accessor,optional"`
}

func (*BoolArraySchema) Validate

func (s *BoolArraySchema) Validate(model *ModelSchema) error

type BoolSchema

type BoolSchema struct {
	Name     string `hcl:"name,label"`
	Default  bool   `hcl:"default,attr"`
	Accessor bool   `hcl:"accessor,optional"`
}

func (*BoolSchema) Validate

func (s *BoolSchema) Validate(model *ModelSchema) error

type BytesArraySchema

type BytesArraySchema struct {
	Name        string `hcl:"name,label"`
	InitialSize uint32 `hcl:"initial_size,attr"`
	Accessor    bool   `hcl:"accessor,optional"`
}

func (*BytesArraySchema) Validate

func (s *BytesArraySchema) Validate(model *ModelSchema) error

type BytesSchema

type BytesSchema struct {
	Name        string `hcl:"name,label"`
	InitialSize uint32 `hcl:"initial_size,attr"`
	Accessor    bool   `hcl:"accessor,optional"`
}

func (*BytesSchema) Validate

func (s *BytesSchema) Validate(model *ModelSchema) error

type EnumArraySchema

type EnumArraySchema struct {
	Name        string `hcl:"name,label"`
	Reference   string `hcl:"reference,attr"`
	InitialSize uint32 `hcl:"initial_size,attr"`
	Accessor    bool   `hcl:"accessor,optional"`
}

func (*EnumArraySchema) Validate

func (s *EnumArraySchema) Validate(model *ModelSchema) error

type EnumMapSchema

type EnumMapSchema struct {
	Name      string `hcl:"name,label"`
	Reference string `hcl:"reference,attr"`
	Value     string `hcl:"value,attr"`
	Accessor  bool   `hcl:"accessor,optional"`
}

func (*EnumMapSchema) Validate

func (s *EnumMapSchema) Validate(model *ModelSchema) error

type EnumReferenceSchema

type EnumReferenceSchema struct {
	Name      string `hcl:"name,label"`
	Default   string `hcl:"default,attr"`
	Reference string `hcl:"reference,attr"`
	Accessor  bool   `hcl:"accessor,optional"`
}

func (*EnumReferenceSchema) Validate

func (s *EnumReferenceSchema) Validate(model *ModelSchema, enums []*EnumSchema) error

type EnumSchema

type EnumSchema struct {
	Name   string   `hcl:"name,label"`
	Values []string `hcl:"values,attr"`
}

func (*EnumSchema) Normalize

func (s *EnumSchema) Normalize()

func (*EnumSchema) Validate

func (s *EnumSchema) Validate(knownEnums map[string]struct{}) error

type ModelReferenceArraySchema

type ModelReferenceArraySchema struct {
	Name        string `hcl:"name,label"`
	Reference   string `hcl:"reference,attr"`
	InitialSize uint32 `hcl:"initial_size,attr"`
	Accessor    bool   `hcl:"accessor,optional"`
}

func (*ModelReferenceArraySchema) Validate

func (m *ModelReferenceArraySchema) Validate(model *ModelSchema) error

type ModelReferenceMapSchema

type ModelReferenceMapSchema struct {
	Name      string `hcl:"name,label"`
	Reference string `hcl:"reference,attr"`
	Value     string `hcl:"value,attr"`
	Accessor  bool   `hcl:"accessor,optional"`
}

func (*ModelReferenceMapSchema) Validate

func (m *ModelReferenceMapSchema) Validate(model *ModelSchema) error

type ModelReferenceSchema

type ModelReferenceSchema struct {
	Name      string `hcl:"name,label"`
	Reference string `hcl:"reference,attr"`
	Accessor  bool   `hcl:"accessor,optional"`
}

func (*ModelReferenceSchema) Validate

func (m *ModelReferenceSchema) Validate(model *ModelSchema) error

type ModelSchema

type ModelSchema struct {
	Name        string `hcl:"name,label"`
	Description string `hcl:"description,optional"`

	Models      []*ModelReferenceSchema      `hcl:"model,block"`
	ModelArrays []*ModelReferenceArraySchema `hcl:"model_array,block"`

	Strings      []*StringSchema      `hcl:"string,block"`
	StringArrays []*StringArraySchema `hcl:"string_array,block"`
	StringMaps   []*StringMapSchema   `hcl:"string_map,block"`

	Bools      []*BoolSchema      `hcl:"bool,block"`
	BoolArrays []*BoolArraySchema `hcl:"bool_array,block"`

	Bytes       []*BytesSchema      `hcl:"bytes,block"`
	BytesArrays []*BytesArraySchema `hcl:"bytes_array,block"`

	Enums      []*EnumReferenceSchema `hcl:"enum,block"`
	EnumArrays []*EnumArraySchema     `hcl:"enum_array,block"`
	EnumMaps   []*EnumMapSchema       `hcl:"enum_map,block"`

	Int32s      []*NumberSchema[int32]      `hcl:"int32,block"`
	Int32Arrays []*NumberArraySchema[int32] `hcl:"int32_array,block"`
	Int32Maps   []*NumberMapSchema[int32]   `hcl:"int32_map,block"`

	Int64s      []*NumberSchema[int64]      `hcl:"int64,block"`
	Int64Arrays []*NumberArraySchema[int64] `hcl:"int64_array,block"`
	Int64Maps   []*NumberMapSchema[int64]   `hcl:"int64_map,block"`

	Uint32s      []*NumberSchema[uint32]      `hcl:"uint32,block"`
	Uint32Arrays []*NumberArraySchema[uint32] `hcl:"uint32_array,block"`
	Uint32Maps   []*NumberMapSchema[uint32]   `hcl:"uint32_map,block"`

	Uint64s      []*NumberSchema[uint64]      `hcl:"uint64,block"`
	Uint64Arrays []*NumberArraySchema[uint64] `hcl:"uint64_array,block"`
	Uint64Maps   []*NumberMapSchema[uint64]   `hcl:"uint64_map,block"`

	Float32s      []*NumberSchema[float32]      `hcl:"float32,block"`
	Float32Arrays []*NumberArraySchema[float32] `hcl:"float32_array,block"`

	Float64s      []*NumberSchema[float64]      `hcl:"float64,block"`
	Float64Arrays []*NumberArraySchema[float64] `hcl:"float64_array,block"`
}

func (*ModelSchema) Normalize

func (m *ModelSchema) Normalize()

func (*ModelSchema) Validate

func (m *ModelSchema) Validate(knownModels map[string]struct{}, enums []*EnumSchema) error

type Number

type Number interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64
}

type NumberArraySchema

type NumberArraySchema[T Number] struct {
	Name           string                         `hcl:"name,label"`
	InitialSize    uint32                         `hcl:"initial_size,attr"`
	Accessor       *bool                          `hcl:"accessor,optional"`
	LimitValidator *NumberLimitValidatorSchema[T] `hcl:"limit_validator,block"`
}

func (*NumberArraySchema[T]) Validate

func (s *NumberArraySchema[T]) Validate(model *ModelSchema) error

type NumberLimitValidatorSchema

type NumberLimitValidatorSchema[T Number] struct {
	Maximum *T `hcl:"max,optional"`
	Minimum *T `hcl:"min,optional"`
}

type NumberMapSchema

type NumberMapSchema[T Number] struct {
	Name           string                         `hcl:"name,label"`
	Value          string                         `hcl:"value,attr"`
	Accessor       *bool                          `hcl:"accessor,optional"`
	LimitValidator *NumberLimitValidatorSchema[T] `hcl:"limit_validator,block"`
}

func (*NumberMapSchema[T]) Validate

func (s *NumberMapSchema[T]) Validate(model *ModelSchema) error

type NumberSchema

type NumberSchema[T Number] struct {
	Name           string                         `hcl:"name,label"`
	Default        T                              `hcl:"default,attr"`
	Accessor       *bool                          `hcl:"accessor,optional"`
	LimitValidator *NumberLimitValidatorSchema[T] `hcl:"limit_validator,block"`
}

func (*NumberSchema[T]) Validate

func (s *NumberSchema[T]) Validate(model *ModelSchema) error

type Schema

type Schema struct {
	Version string         `hcl:"version,attr"`
	Context string         `hcl:"context,attr"`
	Enums   []*EnumSchema  `hcl:"enum,block"`
	Models  []*ModelSchema `hcl:"model,block"`
	// contains filtered or unexported fields
}

Schema is the top-level structure of a Scale Signature schema

func ReadSchema

func ReadSchema(path string) (*Schema, error)

ReadSchema reads a Scale Signature schema from a file at the given path

func (*Schema) Clone

func (s *Schema) Clone() (*Schema, error)

Clone returns a deep copy of the schema

func (*Schema) CloneWithDisabledAccessorsValidatorsAndModifiers

func (s *Schema) CloneWithDisabledAccessorsValidatorsAndModifiers() (*Schema, error)

CloneWithDisabledAccessorsValidatorsAndModifiers returns a clone of the schema with all accessors, validators, and modifiers disabled

func (*Schema) Decode

func (s *Schema) Decode(data []byte) error

Decode decodes the given byte slice into the Schema

Note: This function modifies the Schema in-place and validates/normalizes it as well.

func (*Schema) Encode

func (s *Schema) Encode() ([]byte, error)

Encode encodes the Schema into a byte slice

func (*Schema) HasCaseModifier

func (s *Schema) HasCaseModifier() bool

HasCaseModifier returns true if the schema has a case modifier

func (*Schema) HasLengthValidator

func (s *Schema) HasLengthValidator() bool

HasLengthValidator returns true if the schema has a length validator

func (*Schema) HasLimitValidator

func (s *Schema) HasLimitValidator() bool

HasLimitValidator returns true if the schema has a limit validator

func (*Schema) HasRegexValidator

func (s *Schema) HasRegexValidator() bool

HasRegexValidator returns true if the schema has a regex validator

func (*Schema) Hash

func (s *Schema) Hash() ([]byte, error)

Hash returns the SHA256 hash of the schema

func (*Schema) SetHasCaseModifier added in v0.4.6

func (s *Schema) SetHasCaseModifier(value bool)

SetHasCaseModifier sets the hasCaseModifier flag

func (*Schema) SetHasLengthValidator added in v0.4.6

func (s *Schema) SetHasLengthValidator(value bool)

SetHasLengthValidator sets the hasLengthValidator flag

func (*Schema) SetHasLimitValidator added in v0.4.6

func (s *Schema) SetHasLimitValidator(value bool)

SetHasLimitValidator sets the hasLimitValidator flag

func (*Schema) SetHasRegexValidator added in v0.4.6

func (s *Schema) SetHasRegexValidator(value bool)

SetHasRegexValidator sets the hasRegexValidator flag

type StringArraySchema

type StringArraySchema struct {
	Name            string                       `hcl:"name,label"`
	InitialSize     uint32                       `hcl:"initial_size,attr"`
	Accessor        *bool                        `hcl:"accessor,optional"`
	RegexValidator  *StringRegexValidatorSchema  `hcl:"regex_validator,block"`
	LengthValidator *StringLengthValidatorSchema `hcl:"length_validator,block"`
	CaseModifier    *StringCaseModifierSchema    `hcl:"caseModifier,block"`
}

func (*StringArraySchema) Validate

func (s *StringArraySchema) Validate(model *ModelSchema) error

type StringCaseModifierSchema

type StringCaseModifierSchema struct {
	Kind string `hcl:"kind,attr"`
}

type StringLengthValidatorSchema

type StringLengthValidatorSchema struct {
	Minimum *uint `hcl:"min,optional"`
	Maximum *uint `hcl:"max,optional"`
}

type StringMapSchema

type StringMapSchema struct {
	Name            string                       `hcl:"name,label"`
	Value           string                       `hcl:"value,attr"`
	Accessor        *bool                        `hcl:"accessor,optional"`
	RegexValidator  *StringRegexValidatorSchema  `hcl:"regex_validator,block"`
	LengthValidator *StringLengthValidatorSchema `hcl:"length_validator,block"`
	CaseModifier    *StringCaseModifierSchema    `hcl:"caseModifier,block"`
}

func (*StringMapSchema) Validate

func (s *StringMapSchema) Validate(model *ModelSchema) error

type StringRegexValidatorSchema

type StringRegexValidatorSchema struct {
	Expression string `hcl:"expression,attr"`
}

type StringSchema

type StringSchema struct {
	Name            string                       `hcl:"name,label"`
	Default         string                       `hcl:"default,attr"`
	Accessor        *bool                        `hcl:"accessor,optional"`
	RegexValidator  *StringRegexValidatorSchema  `hcl:"regex_validator,block"`
	LengthValidator *StringLengthValidatorSchema `hcl:"length_validator,block"`
	CaseModifier    *StringCaseModifierSchema    `hcl:"case_modifier,block"`
}

func (*StringSchema) Validate

func (s *StringSchema) Validate(model *ModelSchema) error

Directories

Path Synopsis
Package converter generates a polyglot-encoded buffer from a signature schema and a data payload
Package converter generates a polyglot-encoded buffer from a signature schema and a data payload

Jump to

Keyboard shortcuts

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