runes

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2023 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// ChunkSize is chunk size in bytes
	ChunkSize = 64
	// OutputSize is size of SHA256 checksum in bytes.
	OutputSize = 32
	// Magic256 is the magic for SHA256
	Magic256 = "sha\x03"
)

Variables

View Source
var (
	// ErrTooLongSecret represents an error where secret was too long
	ErrTooLongSecret = errors.New("too long secret")
	// ErrTooShortSecret represents an error where secret was too short
	ErrTooShortSecret = errors.New("too short secret")
	// ErrUnauthorizedRune represents an error where rune was not authorized
	ErrUnauthorizedRune = errors.New("unauthorized rune")
)
View Source
var (
	// ErrInvalidRune represents the error when rune could not be parsed
	ErrInvalidRune = errors.New("invalid rune")
)
View Source
var KnownConditions = []string{"!", "=", "/", "^", "$", "~", "<", ">", "}", "{", "#"}

KnownConditions are the currently known conditions

Functions

This section is empty.

Types

type Alternative

type Alternative struct {
	Field string
	Cond  string
	Value any
}

Alternative struct

func MakeAlternative

func MakeAlternative(field string, cond string, value any, allowIDField bool) (*Alternative, error)

MakeAlternative returns a new Alternative

func MakeAlternativeFromString

func MakeAlternativeFromString(str string, allowIDField bool) (*Alternative, string, error)

MakeAlternativeFromString returns a new alternativee from a string

func (*Alternative) Evaluate

func (a *Alternative) Evaluate(vals map[string]any) (bool, string)

Evaluate evaluates the alternative

func (*Alternative) IsUniqueID

func (a *Alternative) IsUniqueID() bool

IsUniqueID - is this alternative the unique id

func (*Alternative) String

func (a *Alternative) String() string

String returns a string representation

type Marshaller

type Marshaller interface {
	UnmarshalBinary([]byte) error
	MarshalBinary() ([]byte, error)
}

Marshaller is the interface for marshalling

type MasterRune

type MasterRune struct {
	SeedSecret []byte
	Rune
}

MasterRune struct

func MakeMasterRune

func MakeMasterRune(seedsecret []byte, uniqueid, version any, restrictions []Restriction) (*MasterRune, error)

MakeMasterRune creates a new master rune

func MustMakeMasterRune

func MustMakeMasterRune(seedsecret []byte) MasterRune

MustMakeMasterRune is a helper constructor for creating a master rune

func (*MasterRune) Check

func (r *MasterRune) Check(rune *Rune, vals map[string]any) error

Check checks rune

func (*MasterRune) IsRuneAuthorized

func (r *MasterRune) IsRuneAuthorized(other *Rune) bool

IsRuneAuthorized check whether rune is authorized

type MidState

type MidState struct {
	H   [8]uint32
	Len uint64
}

MidState struct

func (*MidState) GetSum

func (state *MidState) GetSum() [OutputSize]byte

GetSum gets SHA-256 hash

type ObtainValue

type ObtainValue func() any

ObtainValue is the signature of a function to get current value

type Restriction

type Restriction struct {
	Alternatives []Alternative
}

Restriction struct

func MakeRestriction

func MakeRestriction(alternatives []Alternative) (*Restriction, error)

MakeRestriction from alternatives

func MakeRestrictionFromString

func MakeRestrictionFromString(str string, allowIDField bool) (*Restriction, string, error)

MakeRestrictionFromString returns a new restriction from a string

func MakeRestrictionsFromString

func MakeRestrictionsFromString(str string) ([]Restriction, error)

MakeRestrictionsFromString creates restrictionn from string representation

func MustMakeRestrictionsFromString

func MustMakeRestrictionsFromString(str string) []Restriction

MustMakeRestrictionsFromString creates restrictionn from string representation

func UniqueID

func UniqueID(uniqueID any, version any) (*Restriction, error)

UniqueID is a helper method to create an unique id restriction

func (*Restriction) Evaluate

func (r *Restriction) Evaluate(vals map[string]any) (bool, string)

Evaluate evaluates the restriction

func (*Restriction) String

func (r *Restriction) String() string

String returns a string representation

type Rune

type Rune struct {
	Sha256       *Sha256
	Restrictions []Restriction
}

Rune struct

func FromAuthCode

func FromAuthCode(authcode []byte, restrictions []Restriction) (*Rune, error)

FromAuthCode create a new rune from auth code

func FromBase64

func FromBase64(str string) (*Rune, error)

FromBase64 returns a new rune from base64 encoded string representation

func FromString

func FromString(str string) (*Rune, error)

FromString returns a new rune from string representation

func MakeRune

func MakeRune(authbase []byte, uniqueid, version any, restrictions []Restriction) (*Rune, error)

MakeRune creates a new rune

func MustGetFromBase64

func MustGetFromBase64(str string) Rune

MustGetFromBase64 returns a new rune from base64 representation

func MustGetFromString

func MustGetFromString(str string) Rune

MustGetFromString returns a new rune from string representation

func (*Rune) AddRestriction

func (r *Rune) AddRestriction(restriction Restriction) error

AddRestriction adds a new restriction

func (*Rune) Check

func (r *Rune) Check(vals map[string]any) error

Check checks rune

func (*Rune) Evaluate

func (r *Rune) Evaluate(vals map[string]any) (bool, string)

Evaluate evaluates the rune

func (*Rune) GetAuthCode

func (r *Rune) GetAuthCode() []byte

GetAuthCode gets the auth code

func (*Rune) GetRestricted

func (r *Rune) GetRestricted(restrictions ...Restriction) (*Rune, error)

GetRestricted obtains a restricted rune

func (*Rune) GetUniqueID

func (r *Rune) GetUniqueID() int

GetUniqueID gets the uniqueID of a rune or -1

func (*Rune) GetVersion

func (r *Rune) GetVersion() int

GetVersion gets the version of a rune or default (0)

func (*Rune) MustGetRestrictedFromString

func (r *Rune) MustGetRestrictedFromString(str string) Rune

MustGetRestrictedFromString obtains a restricted rune

func (*Rune) String

func (r *Rune) String() string

String returns a string representation of rune

func (*Rune) ToBase64

func (r *Rune) ToBase64() string

ToBase64 returns the base64 encoded representation of rune

func (*Rune) ToBase64Internal

func (r *Rune) ToBase64Internal(trim bool) string

ToBase64Internal returns the base64 encoded representation of rune

type Sha256

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

Sha256 struct

func NewSha256

func NewSha256() *Sha256

NewSha256 - construct new instance

func (*Sha256) AddPadding

func (s *Sha256) AddPadding() error

AddPadding adds necessary padding at the end of a chunk

func (*Sha256) GetLen

func (s *Sha256) GetLen() uint64

GetLen gets the internal length

func (*Sha256) GetMidState

func (s *Sha256) GetMidState() *MidState

GetMidState - get the internal state

func (*Sha256) GetSum

func (s *Sha256) GetSum() [OutputSize]byte

GetSum returns the SHA-256 hash

func (*Sha256) Reset

func (s *Sha256) Reset()

Reset - reset instance

func (*Sha256) SetLen

func (s *Sha256) SetLen(len uint64)

SetLen sets the internal length

func (*Sha256) SetMidState

func (s *Sha256) SetMidState(state *MidState) error

SetMidState - updates internal state

func (*Sha256) Write

func (s *Sha256) Write(p []byte) (nn int, err error)

Write - add bytes

Jump to

Keyboard shortcuts

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