config

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const ServiceTag = "sietch-vault-sync"

ServiceTag is used in mDNS advertisements to discover peers

Variables

This section is empty.

Functions

func IsPassphraseProtected

func IsPassphraseProtected(vaultPath string) (bool, error)

func SaveVaultConfig

func SaveVaultConfig(vaultRoot string, config *VaultConfig) error

SaveVaultConfig saves the vault configuration This is a shorthand for backward compatibility

Types

type AESConfig

type AESConfig struct {
	Key      string
	Mode     string `yaml:"mode,omitempty"`      // GCM or CBC
	KDF      string `yaml:"kdf,omitempty"`       // scrypt or pbkdf2
	Salt     string `yaml:"salt,omitempty"`      // Base64 encoded salt
	ScryptN  int    `yaml:"scrypt_n,omitempty"`  // scrypt N parameter
	ScryptR  int    `yaml:"scrypt_r,omitempty"`  // scrypt r parameter
	ScryptP  int    `yaml:"scrypt_p,omitempty"`  // scrypt p parameter
	PBKDF2I  int    `yaml:"pbkdf2_i,omitempty"`  // PBKDF2 iterations
	Nonce    string `yaml:"nonce,omitempty"`     // For GCM/CTR modes
	IV       string `yaml:"iv,omitempty"`        // For CBC mode
	KeyCheck string `yaml:"key_check,omitempty"` // Hash to verify key
}

AESConfig contains AES-specific encryption settings

func BuildDefaultAESConfig

func BuildDefaultAESConfig() *AESConfig

BuildDefaultAESConfig creates a default AES configuration

type ChaChaConfig

type ChaChaConfig struct {
	Key      string `yaml:"key,omitempty"`       // Base64 encoded key
	Mode     string `yaml:"mode,omitempty"`      // Currently only "poly1305" (authenticated encryption)
	KDF      string `yaml:"kdf,omitempty"`       // Key derivation function (scrypt or pbkdf2)
	Salt     string `yaml:"salt,omitempty"`      // Base64 encoded salt for KDF
	ScryptN  int    `yaml:"scrypt_n,omitempty"`  // scrypt N parameter
	ScryptR  int    `yaml:"scrypt_r,omitempty"`  // scrypt r parameter
	ScryptP  int    `yaml:"scrypt_p,omitempty"`  // scrypt p parameter
	PBKDF2I  int    `yaml:"pbkdf2_i,omitempty"`  // PBKDF2 iterations
	Nonce    string `yaml:"nonce,omitempty"`     // For future use if needed
	KeyCheck string `yaml:"key_check,omitempty"` // Hash to verify key
}

ChaChaConfig contains ChaCha20-specific encryption settings

func BuildDefaultChaChaConfig

func BuildDefaultChaChaConfig() *ChaChaConfig

BuildDefaultChaChaConfig creates a default ChaCha20 configuration

type ChunkRef

type ChunkRef struct {
	Hash            string `yaml:"hash"`                       // Hash of chunk content (pre-encryption)
	EncryptedHash   string `yaml:"encrypted_hash,omitempty"`   // Hash of encrypted chunk (filename in storage)
	Size            int64  `yaml:"size"`                       // Size of plaintext chunk
	CompressedSize  int64  `yaml:"compressed_size,omitempty"`  // Size after compression but before encryption
	EncryptedSize   int64  `yaml:"encrypted_size,omitempty"`   // Size after encryption
	Index           int    `yaml:"index"`                      // Position in the file
	Deduplicated    bool   `yaml:"deduplicated,omitempty"`     // Whether this chunk was deduplicated
	Compressed      bool   `yaml:"compressed,omitempty"`       // Whether this chunk was compressed
	CompressionType string `yaml:"compression_type,omitempty"` // Compression algorithm used (e.g., "gzip", "zstd", "none")
	IV              string `yaml:"iv,omitempty"`               // Per-chunk IV if used
	Integrity       string `yaml:"integrity,omitempty"`        // Integrity check value (e.g., HMAC)
}

ChunkRef references a chunk in the vault

type ChunkingConfig

type ChunkingConfig struct {
	Strategy      string `yaml:"strategy"`
	ChunkSize     string `yaml:"chunk_size"`
	HashAlgorithm string `yaml:"hash_algorithm"`
}

ChunkingConfig contains settings for file chunking

type DeduplicationConfig

type DeduplicationConfig struct {
	Enabled      bool   `yaml:"enabled"`        // Enable/disable deduplication
	Strategy     string `yaml:"strategy"`       // "content" for content-based deduplication
	MinChunkSize string `yaml:"min_chunk_size"` // Minimum chunk size for deduplication
	MaxChunkSize string `yaml:"max_chunk_size"` // Maximum chunk size for deduplication
	GCThreshold  int    `yaml:"gc_threshold"`   // Unreferenced chunk count before GC suggestion
	IndexEnabled bool   `yaml:"index_enabled"`  // Enable chunk index for faster lookups

}

DeduplicationConfig contains settings for chunk deduplication

type Discovery

type Discovery interface {
	// Start initiates the discovery process
	Start(context.Context) error

	// Stop halts the discovery process
	Stop() error

	// DiscoveredPeers returns channel of found peers
	DiscoveredPeers() <-chan peer.AddrInfo
}

type DiscoveryFactory

type DiscoveryFactory interface {
	CreateMDNS(host.Host) (Discovery, error)
	CreateDHT(context.Context, host.Host, []multiaddr.Multiaddr) (Discovery, error)
}

type EncryptionConfig

type EncryptionConfig struct {
	Type                string        `yaml:"type"`
	KeyPath             string        `yaml:"key_path"`
	KeyHash             string        `yaml:"key_hash,omitempty"` // Fingerprint of the key
	PassphraseProtected bool          `yaml:"passphrase_protected"`
	KeyFile             bool          `yaml:"key_file,omitempty"`        // Whether key comes from file
	KeyFilePath         string        `yaml:"key_file_path,omitempty"`   // Path to key file
	RandomKey           bool          `yaml:"random_key,omitempty"`      // Whether key was randomly generated
	KeyBackupPath       string        `yaml:"key_backup_path,omitempty"` // Where key is backed up
	AESConfig           *AESConfig    `yaml:"aes_config,omitempty"`      // AES specific settings
	GPGConfig           *GPGConfig    `yaml:"gpg_config,omitempty"`      // GPG specific settings
	ChaChaConfig        *ChaChaConfig `yaml:"chacha_config,omitempty"`   // ChaCha20 specific settings
}

EncryptionConfig contains encryption settings

type FileEncryptionInfo

type FileEncryptionInfo struct {
	Type         string `yaml:"type,omitempty"`          // Can override vault encryption type
	KeyReference string `yaml:"key_reference,omitempty"` // References which key was used (vault_master or custom)
	IV           string `yaml:"iv,omitempty"`            // Initialization vector if applicable
	Nonce        string `yaml:"nonce,omitempty"`         // Nonce for GCM mode
}

FileEncryptionInfo contains per-file encryption details (if different from vault default)

type FileManifest

type FileManifest struct {
	FilePath     string              `yaml:"file"`
	Size         int64               `yaml:"size"`
	ModTime      string              `yaml:"mtime"`
	Chunks       []ChunkRef          `yaml:"chunks"`
	Destination  string              `yaml:"destination"`
	Tags         []string            `yaml:"tags,omitempty"`          // File-specific tags
	Encryption   *FileEncryptionInfo `yaml:"encryption,omitempty"`    // Per-file encryption settings
	ContentHash  string              `yaml:"content_hash,omitempty"`  // Hash of entire file content
	MerkleRoot   string              `yaml:"merkle_root,omitempty"`   // Root hash of chunk Merkle tree
	AddedAt      time.Time           `yaml:"added_at"`                // When file was added to vault
	LastSynced   time.Time           `yaml:"last_synced,omitempty"`   // Last successful sync time
	LastVerified time.Time           `yaml:"last_verified,omitempty"` // Last verification time
}

FileManifest represents the metadata for a stored file

type GPGConfig

type GPGConfig struct {
	KeyID      string `yaml:"key_id,omitempty"`      // GPG key ID
	Recipient  string `yaml:"recipient,omitempty"`   // Recipient for encryption
	PublicKey  string `yaml:"public_key,omitempty"`  // Path to public key
	PrivateKey string `yaml:"private_key,omitempty"` // Path to private key
	KeyServer  string `yaml:"key_server,omitempty"`  // Key server URL
}

GPGConfig contains GPG-specific encryption settings

func BuildDefaultGPGConfig

func BuildDefaultGPGConfig() *GPGConfig

BuildDefaultGPGConfig creates a default GPG configuration

type KeyConfig

type KeyConfig struct {
	KeyHash      string        `yaml:"key_hash,omitempty"`
	Salt         string        `yaml:"salt,omitempty"`
	AESConfig    *AESConfig    `yaml:"aes_config,omitempty"`
	ChaChaConfig *ChaChaConfig `yaml:"chacha_config,omitempty"`
	GPGConfig    *GPGConfig    `yaml:"gpg_config,omitempty"`
}

KeyConfig is the internal structure returned by key generation functions

type Manager

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

Manager handles operations on a Sietch vault

func NewManager

func NewManager(vaultRoot string) (*Manager, error)

NewManager creates a new vault manager

func (*Manager) ChunkExists

func (m *Manager) ChunkExists(hash string) (bool, error)

ChunkExists checks if a chunk exists in the vault

func (*Manager) GetChunk

func (m *Manager) GetChunk(hash string) ([]byte, error)

GetChunk retrieves a chunk by its hash

func (*Manager) GetConfig

func (m *Manager) GetConfig() (*VaultConfig, error)

GetConfig loads and returns the vault configuration

func (*Manager) GetManifest

func (m *Manager) GetManifest() (*Manifest, error)

GetManifest returns the vault manifest

func (*Manager) GetManifestEntries

func (m *Manager) GetManifestEntries() ([]*ManifestEntry, error)

GetManifestEntries returns all manifest entries with their paths

func (*Manager) RebuildReferences

func (m *Manager) RebuildReferences() error

RebuildReferences rebuilds file references from manifests

func (*Manager) SaveConfig

func (m *Manager) SaveConfig(config *VaultConfig) error

SaveConfig writes the vault configuration to disk

func (*Manager) StoreChunk

func (m *Manager) StoreChunk(hash string, data []byte) error

StoreChunk stores a chunk in the vault

func (*Manager) VaultRoot

func (m *Manager) VaultRoot() string

VaultRoot returns the root directory of the vault.

type Manifest

type Manifest struct {
	Files []FileManifest `json:"files"`
}

Manifest represents the content of a vault

type ManifestEntry

type ManifestEntry struct {
	Path     string
	Manifest FileManifest
}

ManifestEntry represents a manifest file with its path

type MetadataConfig

type MetadataConfig struct {
	Author string   `yaml:"author"`
	Tags   []string `yaml:"tags"`
}

MetadataConfig contains user metadata

type RSAConfig

type RSAConfig struct {
	KeySize        int           `yaml:"key_size"`
	PublicKeyPath  string        `yaml:"public_key_path,omitempty"`
	PrivateKeyPath string        `yaml:"private_key_path,omitempty"`
	Fingerprint    string        `yaml:"fingerprint,omitempty"`
	TrustedPeers   []TrustedPeer `yaml:"trusted_peers,omitempty"`
}

RSAConfig contains RSA key configuration for sync operations

type SyncConfig

type SyncConfig struct {
	Mode         string     `yaml:"mode"`
	KnownPeers   []string   `yaml:"known_peers,omitempty"`
	RSA          *RSAConfig `yaml:"rsa,omitempty"`
	Enabled      bool       `yaml:"enabled"`
	AutoSync     bool       `yaml:"auto_sync,omitempty"`
	SyncInterval string     `yaml:"sync_interval,omitempty"`
}

SyncConfig contains synchronization settings

type TrustedPeer

type TrustedPeer struct {
	ID           string    `yaml:"id"`
	Name         string    `yaml:"name,omitempty"`
	PublicKey    string    `yaml:"public_key"`
	Fingerprint  string    `yaml:"fingerprint"`
	TrustedSince time.Time `yaml:"trusted_since"`
}

TrustedPeer stores information about a trusted peer

type VaultConfig

type VaultConfig struct {
	Name          string    `yaml:"name"`
	VaultID       string    `yaml:"vault_id"`
	CreatedAt     time.Time `yaml:"created_at"`
	SchemaVersion int       `yaml:"schema_version"`

	Encryption    EncryptionConfig    `yaml:"encryption"`
	Chunking      ChunkingConfig      `yaml:"chunking"`
	Compression   string              `yaml:"compression"`
	Deduplication DeduplicationConfig `yaml:"deduplication"`
	Sync          SyncConfig          `yaml:"sync"`
	Metadata      MetadataConfig      `yaml:"metadata"`
}

VaultConfig represents the structure for vault.yaml

func BuildDefaultVaultConfig

func BuildDefaultVaultConfig(vaultID, vaultName, keyPath string) VaultConfig

func BuildVaultConfig

func BuildVaultConfig(
	vaultID, vaultName, author, keyType, keyPath string,
	passPhraseProtected bool,
	chunkingStrategy, chunkSize, hashAlgorithm, compression string,
	syncMode string,
	tags []string,
	keyConfig *KeyConfig,
) VaultConfig

BuildVaultConfig creates a complete vault configuration with all necessary fields

func BuildVaultConfigWithDeduplication

func BuildVaultConfigWithDeduplication(
	vaultID, vaultName, author, keyType, keyPath string,
	passPhraseProtected bool,
	chunkingStrategy, chunkSize, hashAlgorithm, compression string,
	syncMode string,
	tags []string,
	keyConfig *KeyConfig,

	enableDedup bool, dedupStrategy, dedupMinSize, dedupMaxSize string,
	dedupGCThreshold int, dedupIndexEnabled bool,
) VaultConfig

BuildVaultConfigWithDeduplication creates a complete vault configuration with deduplication settings

func LoadVaultConfig

func LoadVaultConfig(vaultPath string) (*VaultConfig, error)

Jump to

Keyboard shortcuts

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