storage

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CanaryKey is the reserved key for the master-password validation record.
	CanaryKey = "__psst_canary__"
	// HintKey is the reserved key for the optional plain-text password hint.
	HintKey = "__psst_hint__"
)

Variables

This section is empty.

Functions

func DBPath

func DBPath() (string, error)

DBPath returns the canonical path to the database file (~/.persist/data.db).

Types

type Entry

type Entry struct {
	ID        int64
	Key       string
	Value     []byte
	IsSecure  bool
	Salt      []byte
	Nonce     []byte
	CreatedAt time.Time
}

Entry represents one row in the entries table.

type Store

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

Store wraps an open SQLite database.

func Open

func Open() (*Store, error)

Open opens (or creates) the SQLite database at the default path, applies migrations, and returns a ready-to-use Store.

func OpenAt

func OpenAt(path string) (*Store, error)

OpenAt opens (or creates) a SQLite database at the given path. Intended for use in tests where a temporary directory is preferred over ~/.persist.

func (*Store) Close

func (s *Store) Close() error

Close releases the database connection.

func (*Store) Delete

func (s *Store) Delete(key string) error

Delete removes an entry. Returns an error if the key does not exist or is a reserved key.

func (*Store) Get

func (s *Store) Get(key string) (*Entry, error)

Get retrieves an entry by key, excluding reserved keys.

func (*Store) GetCanary

func (s *Store) GetCanary() (*Entry, error)

GetCanary retrieves the canary record.

func (*Store) GetHint

func (s *Store) GetHint() (string, error)

GetHint returns the stored hint text, or ("", nil) if none was set.

func (*Store) IsInitialized

func (s *Store) IsInitialized() (bool, error)

IsInitialized returns true when the canary record exists, indicating that psst init has been completed.

func (*Store) List

func (s *Store) List() ([]Entry, error)

List returns all user entries in reverse-chronological order, never including reserved keys.

func (*Store) Save

func (s *Store) Save(key string, value []byte, force bool) error

Save writes a plain-text entry. Returns an error if the key already exists and force is false.

func (*Store) SaveCanary

func (s *Store) SaveCanary(value, salt, nonce []byte) error

SaveCanary stores the encrypted canary record, replacing any prior entry.

func (*Store) SaveHint

func (s *Store) SaveHint(hint string) error

SaveHint stores a plain-text password hint, replacing any prior hint.

func (*Store) SaveSecure

func (s *Store) SaveSecure(key string, value, salt, nonce []byte, force bool) error

SaveSecure writes an encrypted entry. Returns an error if the key already exists and force is false.

Jump to

Keyboard shortcuts

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