simulator

package
v0.0.0-...-9d6bfa7 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: BSD-2-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MetadataURL = "https://jku.github.io/tuf-demo/metadata"
	TargetsURL  = "https://jku.github.io/tuf-demo/targets"

	MetadataDir  string
	RootBytes    []byte
	PastDateTime time.Time
	Sim          *RepositorySimulator

	LocalDir string
	DumpDir  string
)

Functions

func GetRootBytes

func GetRootBytes(localMetadataDir string) ([]byte, error)

func InitLocalEnv

func InitLocalEnv() error

func RepositoryCleanup

func RepositoryCleanup(tmpDir string)

Types

type FTMetadata

type FTMetadata struct {
	Name  string
	Value int
}

type FTTargets

type FTTargets struct {
	Name  string
	Value *string
}

type FetchTracker

type FetchTracker struct {
	Metadata []FTMetadata
	Targets  []FTTargets
}

FetchTracker contains actual target data and the related target metadata

type RepositorySimulator

type RepositorySimulator struct {
	fetcher.Fetcher
	MDDelegates                    map[string]metadata.Metadata[metadata.TargetsType]
	SignedRoots                    [][]byte
	Signers                        map[string]map[string]*signature.Signer
	TargetFiles                    map[string]RepositoryTarget
	ComputeMetafileHashesAndLength bool
	PrefixTargetsWithHash          bool
	DumpDir                        string
	DumpVersion                    int64
	FetchTracker                   FetchTracker
	SafeExpiry                     time.Time
	MDTargets                      *metadata.Metadata[metadata.TargetsType]
	MDSnapshot                     *metadata.Metadata[metadata.SnapshotType]
	MDTimestamp                    *metadata.Metadata[metadata.TimestampType]
	MDRoot                         *metadata.Metadata[metadata.RootType]
	LocalDir                       string
}

RepositorySimulator simulates a repository that can be used for testing

func InitMetadataDir

func InitMetadataDir() (*RepositorySimulator, string, string, error)

func NewRepository

func NewRepository() *RepositorySimulator

New initializes a RepositorySimulator

func (*RepositorySimulator) AddDelegation

func (rs *RepositorySimulator) AddDelegation(delegatorName string, role metadata.DelegatedRole, targets metadata.TargetsType)

AddDelegation adds delegated target role to the repository

func (*RepositorySimulator) AddSigner

func (rs *RepositorySimulator) AddSigner(role string, keyID string, signer signature.Signer)

func (*RepositorySimulator) AddSuccinctRoles

func (rs *RepositorySimulator) AddSuccinctRoles(delegatorName string, bitLength int, namePrefix string)

AddSuccinctRoles adds succinct roles info to a delegator with name "delegatorName".

Note that for each delegated role represented by succinct roles an empty Targets instance is created

func (*RepositorySimulator) AddTarget

func (rs *RepositorySimulator) AddTarget(role string, data []byte, path string)

AddTarget creates a target from data and adds it to the TargetFiles.

func (*RepositorySimulator) AllTargets

func (rs *RepositorySimulator) AllTargets() <-chan metadata.TargetsType

AllTargets allows receiving role name and signed portion of targets one by one

func (*RepositorySimulator) DownloadFile

func (rs *RepositorySimulator) DownloadFile(urlPath string, maxLength int64, timeout time.Duration) ([]byte, error)

func (*RepositorySimulator) FetchMetadata

func (rs *RepositorySimulator) FetchMetadata(role string, version *int) ([]byte, error)

FetchMetadata returns signed metadata for 'role', using 'version' if it is given. If version is None, non-versioned metadata is being requested

func (*RepositorySimulator) FetchTarget

func (rs *RepositorySimulator) FetchTarget(targetPath string, targetHash string) ([]byte, error)

FetchTarget returns data for 'targetPath', checking 'targetHash' if it is given. If hash is None, then consistentSnapshot is not used

func (*RepositorySimulator) PublishRoot

func (rs *RepositorySimulator) PublishRoot()

PublishRoot signs and stores a new serialized version of root

func (*RepositorySimulator) Root

func (*RepositorySimulator) RotateKeys

func (rs *RepositorySimulator) RotateKeys(role string)

RotateKeys removes all keys for role, then add threshold of new keys

func (*RepositorySimulator) Snapshot

func (rs *RepositorySimulator) Snapshot() metadata.SnapshotType

func (*RepositorySimulator) Targets

func (*RepositorySimulator) Timestamp

func (rs *RepositorySimulator) Timestamp() metadata.TimestampType

func (*RepositorySimulator) UpdateSnapshot

func (rs *RepositorySimulator) UpdateSnapshot()

UpdateSnapshot updates snapshot, assigns targets versions and updates timestamp

func (*RepositorySimulator) UpdateTimestamp

func (rs *RepositorySimulator) UpdateTimestamp()

UpdateTimestamp updates timestamp and assign snapshot version to snapshot meta version

func (*RepositorySimulator) Write

func (rs *RepositorySimulator) Write()

This is a debugging tool: dumping repository state before running Updater refresh may be useful while debugging a test.

type RepositoryTarget

type RepositoryTarget struct {
	Data       []byte
	TargetFile *metadata.TargetFiles
}

RepositoryTarget contains actual target data and the related target metadata

Jump to

Keyboard shortcuts

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