storage

package
v0.0.0-...-45a6ba4 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTokenLength = 6

DefaultTokenLength defines what is the default length of the generated token. Most services are using 6 characters.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Name   string
	Token  string
	Prefix string
	Length uint
}

Account represents a TOTP account.

type BackendError

type BackendError struct {
	Message string
}

BackendError is an error to tell the user something went wrong processing the backend storage.

func (BackendError) Error

func (e BackendError) Error() string

type FileBackend

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

FileBackend structure represents the credential storage.

func NewFileStorage

func NewFileStorage() *FileBackend

NewFileStorage creates a new File Backend Storage.

func (*FileBackend) AddNamespace

func (s *FileBackend) AddNamespace(ns *Namespace) (*Namespace, error)

AddNamespace adds a namespace to the namespace list if it's not already there.

func (*FileBackend) Decrypt

func (s *FileBackend) Decrypt() error

Decrypt tries to decrypt the storage.

func (*FileBackend) DeleteNamespace

func (s *FileBackend) DeleteNamespace(namespace *Namespace)

DeleteNamespace removes a specific namespace from the fileStorage.

func (*FileBackend) FindNamespace

func (s *FileBackend) FindNamespace(name string) (*Namespace, error)

FindNamespace returns with a namespace if the namespace does not exist error is not nil.

func (*FileBackend) ListNamespaces

func (s *FileBackend) ListNamespaces() []*Namespace

ListNamespaces returns with all the namespaces defined in the storage.

func (*FileBackend) Prepare

func (s *FileBackend) Prepare() error

Prepare tries to load the credentials file and tries to decrypt it.

func (*FileBackend) Save

func (s *FileBackend) Save() error

Save tries to encrypt and save the storage.

func (*FileBackend) SetPassword

func (s *FileBackend) SetPassword(password string)

SetPassword sets the password for the file storage.

type Namespace

type Namespace struct {
	Name     string
	Accounts []*Account
}

Namespace represents a Namespace "category".

func (*Namespace) DeleteAccount

func (n *Namespace) DeleteAccount(account *Account)

DeleteAccount removes a specific Account from the Namespace.

func (*Namespace) FindAccount

func (n *Namespace) FindAccount(name string) (*Account, error)

FindAccount returns with an account under a specific Namespace if the account does not exist error is not nil.

type NotFoundError

type NotFoundError struct {
	Type string
	Name string
}

NotFoundError is an error to tell the user the requested entity is not there.

func (NotFoundError) Error

func (e NotFoundError) Error() string

type Storage

type Storage interface {
	SetPassword(password string)
	Prepare() error
	Decrypt() error

	FindNamespace(namespace string) (*Namespace, error)
	DeleteNamespace(namespace *Namespace)
	AddNamespace(namespace *Namespace) (*Namespace, error)
	ListNamespaces() []*Namespace

	Save() error
}

Storage is an interface that describes a storage backend.

Jump to

Keyboard shortcuts

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