gotorgop

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SIGN_ED25519 = inet256.SignAlgo_Ed25519
	SIGN_MLDSA87 = "mldsa87"
)
View Source
const (
	KEM_MLKEM1024 = "mlkem1024"
)

Variables

This section is empty.

Functions

func AppendOp

func AppendOp(out []byte, op Op) []byte

AppendOp appends the op to the output. It calls marshal on the op, and prefixes it with the op header.

func DeriveSign

func DeriveSign(seed [32]byte) (sign.PublicKey, sign.PrivateKey)

func MarshalIDMap

func MarshalIDMap(out []byte, leaves map[inet256.ID][]byte) []byte

func MarshalKEMPrivateKey

func MarshalKEMPrivateKey(out []byte, tag string, privKey kem.PrivateKey) []byte

func MarshalKEMPublicKey

func MarshalKEMPublicKey(out []byte, tag string, kem kem.PublicKey) []byte

MarshalKEMPublicKey marshals a KEM public key with a scheme tag.

func PKI

func PKI() inet256.PKI

func ParseKEMPrivateKey

func ParseKEMPrivateKey(data []byte) (kem.PrivateKey, error)

func ParseKEMPublicKey

func ParseKEMPublicKey(data []byte) (kem.PublicKey, error)

ParseKEMPublicKey unmarshals a KEM public key with a scheme tag.

func PostRule

func PostRule(ctx context.Context, s stores.RW, r *Rule) (blobcache.CID, error)

func UnmarshalIDMap

func UnmarshalIDMap(data []byte, dst map[inet256.ID][]byte) error

Types

type AddMember

type AddMember struct {
	Group        GroupID
	Member       Member
	EncryptedKEM []byte
}

func (AddMember) Code

func (op AddMember) Code() Code

func (AddMember) Marshal

func (op AddMember) Marshal(out []byte) []byte

func (*AddMember) Unmarshal

func (op *AddMember) Unmarshal(data []byte) error

func (AddMember) Validate

func (op AddMember) Validate(ctx context.Context, prev State, diff Diff, approvers IDSet) error

type AddRule

type AddRule struct {
	Rule Rule
}

func (AddRule) Code

func (op AddRule) Code() Code

func (AddRule) Marshal

func (op AddRule) Marshal(out []byte) []byte

func (*AddRule) Unmarshal

func (op *AddRule) Unmarshal(data []byte) error

func (AddRule) Validate

func (op AddRule) Validate(ctx context.Context, prev State, diff Diff, approvers IDSet) error

type AddVolume

type AddVolume struct {
	Volume blobcache.OID
}

func (AddVolume) Code

func (op AddVolume) Code() Code

func (AddVolume) Marshal

func (op AddVolume) Marshal(out []byte) []byte

func (*AddVolume) Unmarshal

func (op *AddVolume) Unmarshal(data []byte) error

func (AddVolume) Validate

func (op AddVolume) Validate(ctx context.Context, prev State, diff Diff, approvers IDSet) error

type ChangeSet

type ChangeSet struct {
	Ops  []Op
	Sigs map[inet256.ID][]byte
}

ChangeSet is a set of operations signed together.

func (ChangeSet) Code

func (op ChangeSet) Code() Code

func (ChangeSet) Marshal

func (op ChangeSet) Marshal(out []byte) []byte

func (ChangeSet) OpData

func (op ChangeSet) OpData(out []byte) []byte

OpData is the portion of the change set that contains the operations. This is what is signed. The other portion is the sig map.

func (*ChangeSet) Sign

func (op *ChangeSet) Sign(pk inet256.PrivateKey)

Sign signs the change set with the private key and adds the signature to the sigs map.

func (*ChangeSet) Unmarshal

func (cs *ChangeSet) Unmarshal(data []byte) error

func (ChangeSet) Validate

func (cs ChangeSet) Validate(ctx context.Context, prev State, diff Diff, approvers IDSet) error

type Code

type Code uint8
const (
	Code_UNKNOWN Code = iota

	Code_ChangeSet

	Code_CreateGroup
	Code_CreateIDUnit
	Code_AddMember
	Code_RemoveMember

	Code_AddRule
	Code_DropRule

	Code_AddVolume
	Code_DropVolume
	Code_PutEntry
	Code_DeleteEntry
)

type CreateGroup

type CreateGroup struct {
	Group Group
}

CreateGroup creates a group. It has to be

func (CreateGroup) Code

func (op CreateGroup) Code() Code

func (CreateGroup) Marshal

func (op CreateGroup) Marshal(out []byte) []byte

func (*CreateGroup) Unmarshal

func (op *CreateGroup) Unmarshal(data []byte) error

func (CreateGroup) Validate

func (op CreateGroup) Validate(ctx context.Context, prev State, diff Diff, approvers IDSet) error

type CreateIDUnit

type CreateIDUnit struct {
	Unit IdentityUnit
}

CreateIDUnit creates a new leaf, or fails if the leaf already exists.

func (CreateIDUnit) Code

func (op CreateIDUnit) Code() Code

func (CreateIDUnit) Marshal

func (op CreateIDUnit) Marshal(out []byte) []byte

func (*CreateIDUnit) Unmarshal

func (op *CreateIDUnit) Unmarshal(data []byte) error

func (CreateIDUnit) Validate

func (op CreateIDUnit) Validate(ctx context.Context, prev State, diff Diff, approvers IDSet) error

type DeleteBranchEntry

type DeleteBranchEntry struct {
	Name string
}

DeleteEntry deletes a Branch entry.

func (DeleteBranchEntry) Code

func (op DeleteBranchEntry) Code() Code

func (DeleteBranchEntry) Marshal

func (op DeleteBranchEntry) Marshal(out []byte) []byte

func (*DeleteBranchEntry) Unmarshal

func (op *DeleteBranchEntry) Unmarshal(data []byte) error

func (DeleteBranchEntry) Validate

func (op DeleteBranchEntry) Validate(ctx context.Context, prev State, diff Diff, approvers IDSet) error

type Diff

type Diff interface {
	ForEachRule(ctx context.Context, fn func(rule Rule) error) error
	ForEachVolumeEntry(ctx context.Context, fn func(entry VolumeEntry) error) error
	ForEachBranchEntry(ctx context.Context, fn func(entry VolumeAlias) error) error
}

Diff is things that have changed between two system states.

type DropRule

type DropRule struct {
	RuleID RuleID
}

func (DropRule) Code

func (op DropRule) Code() Code

func (DropRule) Marshal

func (op DropRule) Marshal(out []byte) []byte

func (*DropRule) Unmarshal

func (op *DropRule) Unmarshal(data []byte) error

func (DropRule) Validate

func (op DropRule) Validate(ctx context.Context, prev State, diff Diff, approvers IDSet) error

type DropVolume

type DropVolume struct {
	Volume blobcache.OID
}

func (DropVolume) Code

func (op DropVolume) Code() Code

func (DropVolume) Marshal

func (op DropVolume) Marshal(out []byte) []byte

func (*DropVolume) Unmarshal

func (op *DropVolume) Unmarshal(data []byte) error

func (DropVolume) Validate

func (op DropVolume) Validate(ctx context.Context, prev State, diff Diff, approvers IDSet) error

type Group

type Group struct {
	// ID uniquely identifies the group.
	// It is stored in the key,
	ID GroupID

	// Nonce is random additional data used to compute the GroupID
	Nonce [16]byte
	// KEM is used to send messages to the group.
	// The private key is stored encrypted in each Membership entry.
	KEM kem.PublicKey
	// Owners are the identities that can add and remove members from the group.
	// Owners must also be members of the group.
	Owners IDSet
}

func ParseGroup

func ParseGroup(key, value []byte) (*Group, error)

func (*Group) Key

func (g *Group) Key(out []byte) []byte

func (*Group) Value

func (g *Group) Value(out []byte) []byte

type GroupID

type GroupID = blobcache.CID

Name uniquely identifies the group, it is the primary key of the Groups table.

func ComputeGroupID

func ComputeGroupID(nonce [16]byte, initOwners IDSet) GroupID

ComputeGroupID computes the ID of a group from a nonce and initial owners. This value must be unique across all groups in the namespace. The GroupID does not change over the lifetime of the group, even though the owners might.

func ParseGroupID

func ParseGroupID(x []byte) (GroupID, error)

type IDSet

type IDSet []inet256.ID

IDSet is a set of inet256.ID It has a deterministic wire format.

func (*IDSet) Add

func (s *IDSet) Add(id inet256.ID)

func (*IDSet) Contains

func (s *IDSet) Contains(id inet256.ID) bool

func (*IDSet) Len

func (s *IDSet) Len() int

func (IDSet) Marshal

func (s IDSet) Marshal(out []byte) []byte

func (*IDSet) Remove

func (s *IDSet) Remove(id inet256.ID)

func (*IDSet) Unmarshal

func (s *IDSet) Unmarshal(data []byte) error

type IdentityUnit

type IdentityUnit struct {
	// ID is part of the key.
	ID inet256.ID

	// PublicKey is the public signing key.
	SigPublicKey inet256.PublicKey
	// KEMPublicKey is the public KEM key.
	// This will have been authenticated by the leaf's.
	KEMPublicKey kem.PublicKey
}

IdentityUnit contains information about a specific signing key. It is an entry in the Units table.

func NewIDUnit

func NewIDUnit(pubKey inet256.PublicKey, kemPub kem.PublicKey) IdentityUnit

NewIDUnit creates a new IdentityUnit with a new KEM key pair.

func ParseIDUnit

func ParseIDUnit(key, value []byte) (*IdentityUnit, error)

func (*IdentityUnit) GenerateKEM

func (il *IdentityUnit) GenerateKEM(sigPriv inet256.PrivateKey) kem.PrivateKey

func (IdentityUnit) Key

func (il IdentityUnit) Key(out []byte) []byte

Key returns the key portion of the GotKV entry in the Leaves table.

func (*IdentityUnit) Value

func (il *IdentityUnit) Value(out []byte) []byte

Value returns the value portion of the GotKV entry in the Leaves table.

type Member

type Member struct {
	// Unit is a single identity unit.
	Unit *inet256.ID
	// Group is a reference to another group by that group's ID.
	Group *GroupID
}

Member is a member of a group.

func MemberGroup

func MemberGroup(id GroupID) Member

func MemberUnit

func MemberUnit(id inet256.ID) Member

func (Member) Marshal

func (m Member) Marshal(out []byte) []byte

func (*Member) Unmarshal

func (m *Member) Unmarshal(data []byte) error

type ObjectType

type ObjectType string
const (
	ObjectType_GROUP  ObjectType = "group"
	ObjectType_BRANCH ObjectType = "branch"
	ObjectType_RULE   ObjectType = "rule"
)

type Op

type Op interface {
	// Marshal marshales the op body.  The header is not included.
	Marshal(out []byte) []byte
	// Unmarshal unmarshals the op body, which does not include the header.
	Unmarshal(data []byte) error
	// Code returns the op code.
	Code() Code

	Validate(ctx context.Context, prev State, diff Diff, approvers IDSet) error
	// contains filtered or unexported methods
}

Op is a single operation on the ledger. Ops are batched into Deltas, which represent an atomic state transition of the ledger.

func ReadOp

func ReadOp(data []byte) (Op, []byte, error)

ReadOp reads an op from the data. It starts by reading the 4 byte OpHeader, and then uses that to parse the rest of the op. It returns the op, and the rest of the data, not part of the op

type OpHeader

type OpHeader [4]byte

func NewOpHeader

func NewOpHeader(code Code, payloadLen int) (ret OpHeader)

func (OpHeader) Code

func (h OpHeader) Code() Code

func (OpHeader) PayloadLen

func (h OpHeader) PayloadLen() int

type PutBranchEntry

type PutBranchEntry struct {
	Name   string
	Volume blobcache.OID
}

PutBranchEntry creates or overwrites a Branch entry.

func (PutBranchEntry) Code

func (op PutBranchEntry) Code() Code

func (PutBranchEntry) Marshal

func (op PutBranchEntry) Marshal(out []byte) []byte

func (*PutBranchEntry) Unmarshal

func (op *PutBranchEntry) Unmarshal(data []byte) error

func (PutBranchEntry) Validate

func (op PutBranchEntry) Validate(ctx context.Context, prev State, diff Diff, approvers IDSet) error

type RemoveMember

type RemoveMember struct {
	Group  GroupID
	Member Member
}

func (RemoveMember) Code

func (op RemoveMember) Code() Code

func (RemoveMember) Marshal

func (op RemoveMember) Marshal(out []byte) []byte

func (*RemoveMember) Unmarshal

func (op *RemoveMember) Unmarshal(data []byte) error

func (RemoveMember) Validate

func (op RemoveMember) Validate(ctx context.Context, prev State, diff Diff, approvers IDSet) error

type Rule

type Rule struct {
	// Subject is the name of the group that this rule applies to.
	Subject GroupID
	// Action is the action granted by this rule.
	Verb Verb
	// ObjectType is the type of the object that this rule applies to.
	ObjectType ObjectType
	// Names is a regular expression that matches the names of the objects that this rule applies to.
	Names *regexp.Regexp
}

func (Rule) ID

func (r Rule) ID() RuleID

func (Rule) Marshal

func (r Rule) Marshal(out []byte) []byte

func (Rule) Matches

func (r Rule) Matches(subject GroupID, verb Verb, objType ObjectType, objName string) bool

func (*Rule) Unmarshal

func (r *Rule) Unmarshal(data []byte) error

type RuleID

type RuleID = blobcache.CID

type Secret

type Secret [32]byte

func (Secret) DeriveKEM

func (s Secret) DeriveKEM() (kem.PublicKey, kem.PrivateKey)

func (Secret) DeriveSym

func (s Secret) DeriveSym() [32]byte

func (Secret) Ratchet

func (s Secret) Ratchet(n int) Secret

type State

type State interface {
	CanDo(ctx context.Context, actor inet256.ID, verb Verb, objType ObjectType, objName string) (bool, error)
	GetLeaf(ctx context.Context, id inet256.ID) (*IdentityUnit, error)
}

type Verb

type Verb string
const (
	// Verb_LOOK allows a subject to read an object.
	Verb_LOOK Verb = "LOOK"
	// Verb_TOUCH allows a subject to write to an object.
	Verb_TOUCH Verb = "TOUCH"
	// Verb_CREATE allows a subject to create an object with a certain set of names.
	Verb_CREATE Verb = "CREATE"
	// Verb_DROP allows a subject to delete an object with a certain set of names.
	Verb_DROP Verb = "DROP"
	// Verb_ADMIN allows a subject to create rules that reference a set of objects.
	Verb_ADMIN Verb = "ADMIN"
)

type VolumeAlias

type VolumeAlias struct {
	Name string

	Volume blobcache.OID
}

VolumeAlias associates a name with a volume.

func ParseVolumeAlias

func ParseVolumeAlias(key, value []byte) (VolumeAlias, error)

func (VolumeAlias) Key

func (e VolumeAlias) Key(buf []byte) []byte

func (VolumeAlias) Value

func (e VolumeAlias) Value(buf []byte) []byte

type VolumeEntry

type VolumeEntry struct {
	Target blobcache.OID
	Rights blobcache.ActionSet

	// TODO: encrypt different LinkTokens for readers and writers.
	TokenSecret blobcache.LTSecret

	// The hash of the secret shared amongst readers of the volume.
	// The double hash of the secret shared amongst writers of the volume.
	// There should never be more than two of these, or less than one.
	HashOfSecrets [][32]byte

	// Aux is extra data associated with the volume.
	// This will be filled with marks.Info JSON.
	Aux []byte
}

func ParseVolumeEntry

func ParseVolumeEntry(key, value []byte) (*VolumeEntry, error)

func (VolumeEntry) Key

func (e VolumeEntry) Key(buf []byte) []byte

func (VolumeEntry) LinkToken

func (e VolumeEntry) LinkToken() blobcache.LinkToken

func (VolumeEntry) Value

func (e VolumeEntry) Value(buf []byte) []byte

Jump to

Keyboard shortcuts

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