sync

package
v0.137.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(key, ciphertext []byte) ([]byte, error)

Decrypt decrypts data produced by Encrypt.

func DeriveKey

func DeriveKey(passphrase string, salt []byte) []byte

DeriveKey derives a 32-byte key from passphrase + salt using Argon2id.

func Encrypt

func Encrypt(key, plaintext []byte) ([]byte, error)

Encrypt encrypts plaintext using XChaCha20-Poly1305 with a random nonce. Returns nonce || ciphertext.

func GenerateSalt

func GenerateSalt() ([]byte, error)

GenerateSalt returns a random 16-byte salt.

Types

type Conflict

type Conflict struct {
	Path       string `json:"path"`
	LocalHash  string `json:"local_hash"`
	RemoteHash string `json:"remote_hash"`
	Timestamp  int64  `json:"timestamp"`
	Resolution string `json:"resolution"`
}

type DiffOp

type DiffOp string
const (
	OpAdd    DiffOp = "add"
	OpUpdate DiffOp = "update"
	OpDelete DiffOp = "delete"
)

type EncryptedEngine

type EncryptedEngine struct {
	Engine *Engine
	Key    []byte // 32-byte symmetric key (unlocked from KeyStore)
}

EncryptedEngine wraps Engine with E2E encryption.

func (*EncryptedEngine) DecryptFile

func (ee *EncryptedEngine) DecryptFile(ciphertext []byte) ([]byte, error)

DecryptFile decrypts data encrypted by EncryptFile.

func (*EncryptedEngine) DecryptThreadEntries

func (ee *EncryptedEngine) DecryptThreadEntries(entries []*store.ThreadEntry) ([]*store.ThreadEntry, error)

DecryptThreadEntries decrypts entries encrypted by EncryptThreadEntries. Returns new copies; the originals are not modified.

func (*EncryptedEngine) EncryptFile

func (ee *EncryptedEngine) EncryptFile(plaintext []byte) ([]byte, error)

EncryptFile encrypts plaintext file content.

func (*EncryptedEngine) EncryptThreadEntries

func (ee *EncryptedEngine) EncryptThreadEntries(entries []*store.ThreadEntry) ([]*store.ThreadEntry, error)

EncryptThreadEntries encrypts the Summary and UserInput fields of thread entries. Returns new copies; the originals are not modified.

type Engine

type Engine struct {
	MemoryDir string
	WingID    string
	Store     *store.Store
}

func (*Engine) ApplyDiffs

func (e *Engine) ApplyDiffs(diffs []FileDiff, getContent func(path string) ([]byte, error)) error

func (*Engine) BuildLocalManifest

func (e *Engine) BuildLocalManifest() (*Manifest, error)

func (*Engine) ExportThreadEntries

func (e *Engine) ExportThreadEntries(since time.Time) ([]*store.ThreadEntry, error)

func (*Engine) ImportThreadEntries

func (e *Engine) ImportThreadEntries(entries []*store.ThreadEntry) error

func (*Engine) MergeThreadEntries

func (e *Engine) MergeThreadEntries(remote []*store.ThreadEntry) (int, error)

MergeThreadEntries merges remote thread entries into the local store. Deduplicates by (task_id, wing_id, timestamp) triple. Entries without task_id use (wing_id, timestamp, summary) for dedup. Returns count of entries imported.

type FileDiff

type FileDiff struct {
	Path string
	Op   DiffOp
}

func DiffManifests

func DiffManifests(local, remote *Manifest) []FileDiff

DiffManifests compares two manifests by SHA256 hash. Files in remote but not local = add. Files with different hash = update. Files in local but not remote are left alone (additive only, no deletes).

type FileEntry

type FileEntry struct {
	Path    string `json:"path"`
	SHA256  string `json:"sha256"`
	Size    int64  `json:"size"`
	ModTime int64  `json:"mod_time"`
	WingID  string `json:"wing_id"`
}

type KeyFile

type KeyFile struct {
	Salt         []byte `yaml:"salt"`
	EncryptedKey []byte `yaml:"encrypted_key"`
	KeyHash      string `yaml:"key_hash"`
	CreatedAt    int64  `yaml:"created_at"`
}

KeyFile is the on-disk format for the encryption key material.

type KeyStore

type KeyStore struct {
	Dir string // ~/.wingthing/
}

KeyStore manages encryption keys for sync.

func NewKeyStore

func NewKeyStore(dir string) *KeyStore

func (*KeyStore) Init

func (ks *KeyStore) Init(passphrase string) error

Init generates a new random symmetric key, encrypts it with the passphrase, and saves.

func (*KeyStore) IsInitialized

func (ks *KeyStore) IsInitialized() bool

IsInitialized checks if a keyfile exists.

func (*KeyStore) Unlock

func (ks *KeyStore) Unlock(passphrase string) ([]byte, error)

Unlock derives the key from passphrase, decrypts the stored symmetric key, returns it.

type Manifest

type Manifest struct {
	WingID    string      `json:"wing_id"`
	Files     []FileEntry `json:"files"`
	CreatedAt int64       `json:"created_at"`
}

func BuildManifest

func BuildManifest(dir string, wingID string) (*Manifest, error)

func ParseManifest

func ParseManifest(data []byte) (*Manifest, error)

func (*Manifest) MarshalJSON

func (m *Manifest) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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