Documentation ¶
Overview ¶
Package repository implements a restic repository on top of a backend.
Index ¶
- Constants
- Variables
- func FilesInParallel(repo backend.Lister, t backend.Type, n uint, f ParallelWorkFunc) error
- type Blob
- type Blobs
- type Config
- type Index
- func (idx *Index) Count(t pack.BlobType) (n uint)
- func (idx *Index) Dump(w io.Writer) error
- func (idx *Index) Each(done chan struct{}) <-chan PackedBlob
- func (idx *Index) Encode(w io.Writer) error
- func (idx *Index) Has(id backend.ID) bool
- func (idx *Index) Lookup(id backend.ID) (packID *backend.ID, tpe pack.BlobType, offset, length uint, err error)
- func (idx *Index) LookupSize(id backend.ID) (cleartextLength uint, err error)
- func (idx *Index) Merge(other *Index)
- func (idx *Index) Remove(packID backend.ID)
- func (idx *Index) Store(t pack.BlobType, id backend.ID, pack *backend.ID, offset, length uint)
- type JSONUnpackedLoader
- type JSONUnpackedSaver
- type Key
- type PackedBlob
- type ParallelWorkFunc
- type Repository
- func (r *Repository) Backend() backend.Backend
- func (r *Repository) Close() error
- func (r *Repository) Count(t backend.Type) (n uint)
- func (r *Repository) Decrypt(ciphertext []byte) ([]byte, error)
- func (r *Repository) Delete() error
- func (r *Repository) Encrypt(ciphertext, plaintext []byte) ([]byte, error)
- func (r *Repository) Find(t backend.Type, prefix string) (string, error)
- func (r *Repository) Flush() error
- func (r *Repository) Index() *Index
- func (r *Repository) Init(password string) error
- func (r *Repository) Key() *crypto.Key
- func (r *Repository) KeyName() string
- func (r *Repository) List(t backend.Type, done <-chan struct{}) <-chan backend.ID
- func (r *Repository) LoadAndDecrypt(t backend.Type, id backend.ID) ([]byte, error)
- func (r *Repository) LoadBlob(t pack.BlobType, id backend.ID, plaintextBuf []byte) ([]byte, error)
- func (r *Repository) LoadIndex() error
- func (r *Repository) LoadJSONPack(t pack.BlobType, id backend.ID, item interface{}) error
- func (r *Repository) LoadJSONUnpacked(t backend.Type, id backend.ID, item interface{}) error
- func (r *Repository) LookupBlobSize(id backend.ID) (uint, error)
- func (r *Repository) PrefixLength(t backend.Type) (int, error)
- func (r *Repository) SaveAndEncrypt(t pack.BlobType, data []byte, id *backend.ID) (backend.ID, error)
- func (r *Repository) SaveFrom(t pack.BlobType, id *backend.ID, length uint, rd io.Reader) error
- func (r *Repository) SaveIndex() (backend.ID, error)
- func (r *Repository) SaveJSON(t pack.BlobType, item interface{}) (backend.ID, error)
- func (r *Repository) SaveJSONUnpacked(t backend.Type, item interface{}) (backend.ID, error)
- func (r *Repository) SearchKey(password string) error
- func (r *Repository) SetIndex(i *Index)
Constants ¶
const RepoVersion = 1
RepoVersion is the version that is written to the config when a repository is newly created with Init().
Variables ¶
var ( // ErrNoKeyFound is returned when no key for the repository could be decrypted. ErrNoKeyFound = errors.New("no key could be found") )
Functions ¶
func FilesInParallel ¶
FilesInParallel runs n workers of f in parallel, on the IDs that repo.List(t) yield. If f returns an error, the process is aborted and the first error is returned.
Types ¶
type Blob ¶
type Blob struct { ID *backend.ID `json:"id,omitempty"` Size uint64 `json:"size,omitempty"` Storage *backend.ID `json:"sid,omitempty"` // encrypted ID StorageSize uint64 `json:"ssize,omitempty"` // encrypted Size }
type Config ¶
type Config struct { Version uint `json:"version"` ID string `json:"id"` ChunkerPolynomial chunker.Pol `json:"chunker_polynomial"` }
Config contains the configuration for a repository.
func CreateConfig ¶
func CreateConfig(r JSONUnpackedSaver) (Config, error)
CreateConfig creates a config file with a randomly selected polynomial and ID and saves the config in the repository.
func LoadConfig ¶
func LoadConfig(r JSONUnpackedLoader) (Config, error)
LoadConfig returns loads, checks and returns the config for a repository.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index holds a lookup table for id -> pack.
func DecodeIndex ¶
DecodeIndex loads and unserializes an index from rd.
func LoadIndex ¶
func LoadIndex(repo *Repository, id string) (*Index, error)
LoadIndex loads the index id from backend and returns it.
func (*Index) Each ¶
func (idx *Index) Each(done chan struct{}) <-chan PackedBlob
Each returns a channel that yields all blobs known to the index. If done is closed, the background goroutine terminates. This blocks any modification of the index.
func (*Index) Encode ¶
Encode writes the JSON serialization of the index to the writer w. This serialization only contains new blobs added via idx.Store(), not old ones introduced via DecodeIndex().
func (*Index) Lookup ¶
func (idx *Index) Lookup(id backend.ID) (packID *backend.ID, tpe pack.BlobType, offset, length uint, err error)
Lookup returns the pack for the id.
func (*Index) LookupSize ¶
LookupSize returns the length of the cleartext content behind the given id
type JSONUnpackedLoader ¶
JSONUnpackedLoader loads unpacked JSON.
type JSONUnpackedSaver ¶
type JSONUnpackedSaver interface {
SaveJSONUnpacked(backend.Type, interface{}) (backend.ID, error)
}
JSONUnpackedSaver saves unpacked JSON.
type Key ¶
type Key struct { Created time.Time `json:"created"` Username string `json:"username"` Hostname string `json:"hostname"` KDF string `json:"kdf"` N int `json:"N"` R int `json:"r"` P int `json:"p"` Salt []byte `json:"salt"` Data []byte `json:"data"` // contains filtered or unexported fields }
Key represents an encrypted master key for a repository.
func LoadKey ¶
func LoadKey(s *Repository, name string) (*Key, error)
LoadKey loads a key from the backend.
func OpenKey ¶
func OpenKey(s *Repository, name string, password string) (*Key, error)
OpenKey tries do decrypt the key specified by name with the given password.
type PackedBlob ¶
PackedBlob is a blob already saved within a pack.
type ParallelWorkFunc ¶
ParallelWorkFunc gets one file ID to work on. If an error is returned, processing stops. If done is closed, the function should return.
type Repository ¶
type Repository struct { Config Config // contains filtered or unexported fields }
Repository is used to access a repository in a backend.
func (*Repository) Backend ¶
func (r *Repository) Backend() backend.Backend
Backend returns the backend for the repository.
func (*Repository) Close ¶
func (r *Repository) Close() error
Close closes the repository by closing the backend.
func (*Repository) Count ¶
func (r *Repository) Count(t backend.Type) (n uint)
Count returns the number of blobs of a given type in the backend.
func (*Repository) Decrypt ¶
func (r *Repository) Decrypt(ciphertext []byte) ([]byte, error)
Decrypt authenticates and decrypts ciphertext and returns the plaintext.
func (*Repository) Delete ¶
func (r *Repository) Delete() error
Delete calls backend.Delete() if implemented, and returns an error otherwise.
func (*Repository) Encrypt ¶
func (r *Repository) Encrypt(ciphertext, plaintext []byte) ([]byte, error)
Encrypt encrypts and authenticates the plaintext and saves the result in ciphertext.
func (*Repository) Find ¶
Find loads the list of all blobs of type t and searches for names which start with prefix. If none is found, nil and ErrNoIDPrefixFound is returned. If more than one is found, nil and ErrMultipleIDMatches is returned.
func (*Repository) Index ¶
func (r *Repository) Index() *Index
Index returns the currently loaded Index.
func (*Repository) Init ¶
func (r *Repository) Init(password string) error
Init creates a new master key with the supplied password, initializes and saves the repository config.
func (*Repository) KeyName ¶
func (r *Repository) KeyName() string
KeyName returns the name of the current key in the backend.
func (*Repository) List ¶
func (r *Repository) List(t backend.Type, done <-chan struct{}) <-chan backend.ID
List returns a channel that yields all IDs of type t in the backend.
func (*Repository) LoadAndDecrypt ¶
LoadAndDecrypt loads and decrypts data identified by t and id from the backend.
func (*Repository) LoadBlob ¶
LoadBlob tries to load and decrypt content identified by t and id from a pack from the backend, the result is stored in plaintextBuf, which must be large enough to hold the complete blob.
func (*Repository) LoadIndex ¶
func (r *Repository) LoadIndex() error
LoadIndex loads all index files from the backend in parallel and merges them with the current index. The first error that occurred is returned.
func (*Repository) LoadJSONPack ¶
LoadJSONPack calls LoadBlob() to load a blob from the backend, decrypt the data and afterwards call json.Unmarshal on the item.
func (*Repository) LoadJSONUnpacked ¶
LoadJSONUnpacked decrypts the data and afterwards calls json.Unmarshal on the item.
func (*Repository) LookupBlobSize ¶
func (r *Repository) LookupBlobSize(id backend.ID) (uint, error)
LookupBlobSize returns the size of blob id.
func (*Repository) PrefixLength ¶
func (r *Repository) PrefixLength(t backend.Type) (int, error)
PrefixLength returns the number of bytes required so that all prefixes of all IDs of type t are unique.
func (*Repository) SaveAndEncrypt ¶
func (r *Repository) SaveAndEncrypt(t pack.BlobType, data []byte, id *backend.ID) (backend.ID, error)
SaveAndEncrypt encrypts data and stores it to the backend as type t. If data is small enough, it will be packed together with other small blobs.
func (*Repository) SaveFrom ¶
SaveFrom encrypts data read from rd and stores it in a pack in the backend as type t.
func (*Repository) SaveIndex ¶
func (r *Repository) SaveIndex() (backend.ID, error)
SaveIndex saves all new packs in the index in the backend, returned is the storage ID.
func (*Repository) SaveJSON ¶
SaveJSON serialises item as JSON and encrypts and saves it in a pack in the backend as type t.
func (*Repository) SaveJSONUnpacked ¶
SaveJSONUnpacked serialises item as JSON and encrypts and saves it in the backend as type t, without a pack. It returns the storage hash.
func (*Repository) SearchKey ¶
func (r *Repository) SearchKey(password string) error
SearchKey finds a key with the supplied password, afterwards the config is read and parsed.
func (*Repository) SetIndex ¶
func (r *Repository) SetIndex(i *Index)
SetIndex instructs the repository to use the given index.