utils

package
v0.3.0-RC6 Latest Latest
Warning

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

Go to latest
Published: May 10, 2016 License: Apache-2.0, BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrWrongLength = errors.New("wrong length")

ErrWrongLength indicates the length was different to that expected

Functions

func CanonicalKeyID

func CanonicalKeyID(k data.PublicKey) (string, error)

CanonicalKeyID returns the ID of the public bytes version of a TUF key. On regular RSA/ECDSA TUF keys, this is just the key ID. On X509 RSA/ECDSA TUF keys, this is the key ID of the public key part of the key in the leaf cert

func ConsistentName

func ConsistentName(role string, hashSha256 []byte) string

ConsistentName generates the appropriate HTTP URL path for the role, based on whether the repo is marked as consistent. The RemoteStore is responsible for adding file extensions.

func DoHash

func DoHash(alg string, d []byte) []byte

DoHash returns the digest of d using the hashing algorithm named in alg

func Download

func Download(url url.URL) (*http.Response, error)

Download does a simple download from a URL

func FileExists

func FileExists(path string) bool

FileExists returns true if a file (or dir) exists at the given path, false otherwise

func FileMetaEqual

func FileMetaEqual(actual data.FileMeta, expected data.FileMeta) error

FileMetaEqual checks whether 2 FileMeta objects are consistent with eachother

func FindRoleIndex

func FindRoleIndex(rs []*data.Role, name string) int

FindRoleIndex returns the index of the role named <name> or -1 if no matching role is found.

func HashedPaths

func HashedPaths(path string, hashes data.Hashes) []string

HashedPaths prefixes the filename with the known hashes for the file, returning a list of possible consistent paths.

func NormalizeTarget

func NormalizeTarget(path string) string

NormalizeTarget adds a slash, if required, to the front of a target path

func RemoveUnusedKeys

func RemoveUnusedKeys(t *data.SignedTargets)

RemoveUnusedKeys determines which keys in the slice of IDs are no longer used in the given targets file and removes them from the delegated keys map

func StrSliceContains

func StrSliceContains(ss []string, s string) bool

StrSliceContains checks if the given string appears in the slice

func StrSliceContainsI

func StrSliceContainsI(ss []string, s string) bool

StrSliceContainsI checks if the given string appears in the slice in a case insensitive manner

func StrSliceRemove

func StrSliceRemove(ss []string, s string) []string

StrSliceRemove removes the the given string from the slice, returning a new slice

func UnusedDelegationKeys

func UnusedDelegationKeys(t data.SignedTargets) []string

UnusedDelegationKeys prunes a list of keys, returning those that are no longer in use for a given targets file

func Upload

func Upload(url string, body io.Reader) (*http.Response, error)

Upload does a simple JSON upload to a URL

Types

type ErrBadTypeCast

type ErrBadTypeCast struct{}

ErrBadTypeCast is used by PopX functions when the item cannot be typed to X

func (ErrBadTypeCast) Error

func (err ErrBadTypeCast) Error() string

type ErrEmptyStack

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

ErrEmptyStack is used when an action that requires some content is invoked and the stack is empty

func (ErrEmptyStack) Error

func (err ErrEmptyStack) Error() string

type ErrNoCommonHash

type ErrNoCommonHash struct {
	Expected data.Hashes
	Actual   data.Hashes
}

ErrNoCommonHash indicates the metadata did not provide any hashes this client recognizes

func (ErrNoCommonHash) Error

func (e ErrNoCommonHash) Error() string

Error implements error interface

type ErrUnknownHashAlgorithm

type ErrUnknownHashAlgorithm struct {
	Name string
}

ErrUnknownHashAlgorithm - client was ashed to use a hash algorithm it is not familiar with

func (ErrUnknownHashAlgorithm) Error

func (e ErrUnknownHashAlgorithm) Error() string

Error implements error interface

type ErrWrongHash

type ErrWrongHash struct {
	Type     string
	Expected []byte
	Actual   []byte
}

ErrWrongHash indicates the hash was different to that expected

func (ErrWrongHash) Error

func (e ErrWrongHash) Error() string

Error implements error interface

type NoopCloser

type NoopCloser struct {
	io.Reader
}

NoopCloser is a simple Reader wrapper that does nothing when Close is called

func (*NoopCloser) Close

func (nc *NoopCloser) Close() error

Close does nothing for a NoopCloser

type PassphraseFunc

type PassphraseFunc func(role string, confirm bool) ([]byte, error)

PassphraseFunc type for func that request a passphrase

type RoleList

type RoleList []string

RoleList is a list of roles

func (RoleList) Len

func (r RoleList) Len() int

Len returns the length of the list

func (RoleList) Less

func (r RoleList) Less(i, j int) bool

Less returns true if the item at i should be sorted before the item at j. It's an unstable partial ordering based on the number of segments, separated by "/", in the role name

func (RoleList) Swap

func (r RoleList) Swap(i, j int)

Swap the items at 2 locations in the list

type Stack

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

Stack is a simple type agnostic stack implementation

func NewStack

func NewStack() *Stack

NewStack create a new stack

func (*Stack) Empty

func (s *Stack) Empty() bool

Empty returns true if the stack is empty

func (*Stack) Pop

func (s *Stack) Pop() (interface{}, error)

Pop removes and returns the top item on the stack, or returns ErrEmptyStack if the stack has no content

func (*Stack) PopString

func (s *Stack) PopString() (string, error)

PopString attempts to cast the top item on the stack to the string type. If this succeeds, it removes and returns the top item. If the item is not of the string type, ErrBadTypeCast is returned. If the stack is empty, ErrEmptyStack is returned

func (*Stack) Push

func (s *Stack) Push(item interface{})

Push adds an item to the top of the stack.

Jump to

Keyboard shortcuts

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