mirror of
https://github.com/kopia/kopia.git
synced 2026-03-14 12:16:46 -04:00
44 lines
940 B
Go
44 lines
940 B
Go
package vault
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/kopia/kopia/blob"
|
|
"github.com/kopia/kopia/repo"
|
|
)
|
|
|
|
const (
|
|
minUniqueIDLength = 32
|
|
)
|
|
|
|
// Format describes the format of a Vault.
|
|
// Contents of this structure are serialized in plain text in the Vault storage.
|
|
type Format struct {
|
|
Version string `json:"version"`
|
|
UniqueID []byte `json:"uniqueID"`
|
|
Encryption string `json:"encryption"`
|
|
Checksum string `json:"checksum"`
|
|
}
|
|
|
|
func (f *Format) ensureUniqueID() error {
|
|
if f.UniqueID == nil {
|
|
f.UniqueID = make([]byte, minUniqueIDLength)
|
|
if _, err := io.ReadFull(rand.Reader, f.UniqueID); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if len(f.UniqueID) < minUniqueIDLength {
|
|
return fmt.Errorf("UniqueID too short, must be at least %v bytes", minUniqueIDLength)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type RepositoryConfig struct {
|
|
Storage blob.StorageConfiguration `json:"storage"`
|
|
Format *repo.Format `json:"repository"`
|
|
}
|