vsafedb

package
v0.0.0-...-c6def04 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package vsafedb handles storing instances in the vsafe app to persistent storage.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Indicates that the id does not exist in the database.
	ErrNoSuchId = errors.New("vsafedb: No such Id.")
	// Indicates concurrent modification
	ErrConcurrentModification = errors.New("vsafedb: Concurrent Modification")
)

Functions

func AddEntry

func AddEntry(
	store AddEntryRunner,
	t db.Transaction,
	key *vsafe.Key,
	entry *vsafe.Entry) (newId int64, err error)

AddEntry adds a new entry to persistent storage so that sensitive fields are encrypted in persistent storage.

func ChangePassword

func ChangePassword(
	store SafeUpdateUserRunner,
	t db.Transaction,
	id int64,
	oldPass, newPass string) (*vsafe.User, error)

ChangePassword changes the password of a user in persistent storage. t, the transaction, must be non nil.

func Entries

func Entries(
	store EntriesByOwnerRunner,
	keyId int64,
	query string,
	catId int64) ([]*vsafe.Entry, error)

Entries returns a new slice containing entries encrypted with keyId and matching query and orders them by Id. It does not decrypt the sensitive fields within the fetched entries. query is searched for within url, title, and description of each entry ignoring case to determine whether or not there is a match. Whitespace within query and entry fields are normalized to a single space before matching happens. The empty string matches all entries.

If catId is non-zero, returned entries must belong to corresponding category in addition to matching query.

func EntryById

func EntryById(
	store EntryByIdRunner,
	t db.Transaction,
	id int64,
	key *vsafe.Key,
	entry *vsafe.Entry) (err error)

EntryById retrieves an entry by its id from persistent storage while handling decryption of sensitive fields. If the Id of the provided key does not match the Owner field of fetched entry, that is the current user does not own the entry being fetched, EntryById returns ErrNoSuchId.

func RemoveCategory

func RemoveCategory(
	store SafeRemoveCategoryRunner,
	t db.Transaction,
	id, owner int64) (oldName string, err error)

RemoveCategory removes a category by id and owner. t must be non-nil.

func Reverse

func Reverse(entries []*vsafe.Entry)

Reverse reverses entries in place.

func SortByTitle

func SortByTitle(entries []*vsafe.Entry)

SortByTitle sorts entries by title in place ignoring case.

func UpdateCategory

func UpdateCategory(
	store SafeUpdateCategoryRunner,
	t db.Transaction,
	id, owner int64,
	newName string) (oldName string, err error)

UpdateCategory updates a category name by id and owner. t must be non-nil.

func UpdateEntry

func UpdateEntry(
	store UpdateEntryRunner,
	t db.Transaction,
	key *vsafe.Key,
	entry *vsafe.Entry) (err error)

UpdateEntry updates an entry in persistent storage so that sensitive fields remain encrypted in persistent storage. Beware: UpdateEntry does not protect against concurrent modification nor does it protect against users clobbering an entry they do not own.

func UpdateEntryWithEtag

func UpdateEntryWithEtag(
	store SafeUpdateEntryRunner,
	t db.Transaction,
	id int64,
	tag uint64,
	key *vsafe.Key,
	update vsafe.EntryUpdater) error

UpdateEntryWithEtag updates an entry in persistent storage in a way that detects concurrent modification. It also prevents users from modifying entries they do not own by returning ErrNoSuchId. t, the transaction, must be non nil.

Types

type AddCategoryRunner

type AddCategoryRunner interface {
	// AddCategory adds a new category to persistent storage
	AddCategory(t db.Transaction, category *vsafe.Category) error
}

type AddEntryRunner

type AddEntryRunner interface {
	// AddEntry adds a new entry to persistent storage.
	AddEntry(t db.Transaction, entry *vsafe.Entry) error
}

type AddUserRunner

type AddUserRunner interface {
	// AddUser adds a new user to persistent storage.
	AddUser(t db.Transaction, user *vsafe.User) error
}

type CategoriesByOwnerRunner

type CategoriesByOwnerRunner interface {
	// CategoriesByOwner retrieves all categories with a particular owner
	// from persistent storage ordered by category name.
	CategoriesByOwner(
		t db.Transaction, owner int64) ([]vsafe.Category, error)
}

type CategoryByIdRunner

type CategoryByIdRunner interface {
	// CategoryById retrieves category with given id.
	CategoryById(t db.Transaction, id int64, category *vsafe.Category) error
}

type EntriesByOwnerRunner

type EntriesByOwnerRunner interface {
	// EntriesByOwner retrieves all entries with a particular owner from
	// persistent storage ordered by Id.
	EntriesByOwner(
		t db.Transaction, owner int64, consumer consume2.Consumer[vsafe.Entry]) error
}

type EntryByIdRunner

type EntryByIdRunner interface {
	// EntryById retrieves an entry by id from persistent storage.
	EntryById(t db.Transaction, id int64, entry *vsafe.Entry) error
}

type RemoveCategoryRunner

type RemoveCategoryRunner interface {
	// RemoveCategory removes a category with given id from
	// persistent storage.
	RemoveCategory(t db.Transaction, id int64) error
}

type RemoveEntryRunner

type RemoveEntryRunner interface {
	// RemoveEntry removes an entry with given id and owner from persistent
	// storage.
	RemoveEntry(t db.Transaction, id, owner int64) error
}

type RemoveUserRunner

type RemoveUserRunner interface {
	// RemoveUser removes a user by name from persistent storage.
	RemoveUser(t db.Transaction, name string) error
}

type SafeRemoveCategoryRunner

type SafeRemoveCategoryRunner interface {
	CategoryByIdRunner
	RemoveCategoryRunner
}

type SafeUpdateCategoryRunner

type SafeUpdateCategoryRunner interface {
	CategoryByIdRunner
	UpdateCategoryRunner
}

type SafeUpdateEntryRunner

type SafeUpdateEntryRunner interface {
	UpdateEntryRunner
	EntryByIdRunner
}

type SafeUpdateUserRunner

type SafeUpdateUserRunner interface {
	UpdateUserRunner
	UserByIdRunner
}

type UpdateCategoryRunner

type UpdateCategoryRunner interface {
	// UpdateCategory updates a category.
	UpdateCategory(t db.Transaction, category *vsafe.Category) error
}

type UpdateEntryRunner

type UpdateEntryRunner interface {
	// UpdateEntry updates an entry in persistent storage.
	UpdateEntry(t db.Transaction, entry *vsafe.Entry) error
}

type UpdateUserRunner

type UpdateUserRunner interface {
	// UpdateUser modifies a user in persistent storage.
	UpdateUser(t db.Transaction, user *vsafe.User) error
}

type UserByIdRunner

type UserByIdRunner interface {
	// UserById retrieves a user by id from persistent storage.
	UserById(t db.Transaction, id int64, user *vsafe.User) error
}

type UserByNameRunner

type UserByNameRunner interface {
	// UserByName retrieves a user by name from persistent storage.
	UserByName(t db.Transaction, name string, user *vsafe.User) error
}

type UsersRunner

type UsersRunner interface {
	// Users retrieves all users from persistent storage ordered by name.
	Users(t db.Transaction, consumer consume2.Consumer[vsafe.User]) error
}

Directories

Path Synopsis
Package fixture provides test suites to test implementations of the datastore interfaces in the vsafedb package.
Package fixture provides test suites to test implementations of the datastore interfaces in the vsafedb package.
Package for_sqlite provides a sqlite implementation of interfaces in vsafedb package.
Package for_sqlite provides a sqlite implementation of interfaces in vsafedb package.
Package sqlite_setup sets up a sqlite database for vsafe app
Package sqlite_setup sets up a sqlite database for vsafe app

Jump to

Keyboard shortcuts

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