utils

package
v0.0.0-...-3b700e2 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2015 License: BSD-3-Clause Imports: 17 Imported by: 14

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.

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 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 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 Upload

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

Upload does a simple JSON upload to a URL

func ValidateTarget

func ValidateTarget(r io.Reader, m *data.FileMeta) error

ValidateTarget ensures that the data read from reader matches the known metadata

Types

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

Jump to

Keyboard shortcuts

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