internal

package
v0.0.0-...-88af2bc Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GeneratePassword

func GeneratePassword(length, noUpperCase, noLowerCase, noNumber, noSpecials int, ignore string) string

if length is less then noUpperCase + noLowerCase + noNumber + noSpecials length will be ignored

Types

type IO

type IO interface {
	Credentials() (string, string, error)
	Password() (string, error)
	SimpleText(txt string) (string, error)
	SetNewPassword(eval func(pass string) int) (string, error)
}

func NewIO

func NewIO() IO

NewIO returns a pointer to a cmdIO implemnting the IO interface

type PasswordManager

type PasswordManager interface {
	// required pre-condition: is false new vault needs be created
	Init(clIO IO) error
	IsInit() (bool, error)
	// wrapper to read and write to the file
	Read() ([]byte, error)
	Write(data []byte) error
	Serialize(data map[string]string) ([]byte, error)
	// wrapper function to perform a backup of the vault
	// befor proceeding with a function (like writing a new vault)
	Backup(after func() error) (func() error, error)
	EvaluatePassword(password string) int
	Encrypt(key string, vault []byte) ([]byte, error)
	Decrypt(key string, vault []byte) (map[string]string, error)
	GetPath() string
}

PasswordManager is the interface to act with the vault

func NewPasswordManager

func NewPasswordManager(path string) PasswordManager

NewPasswordManager returns a pointer to a Vault implementing the PasswordManager interface

type Vault

type Vault struct {
	Path string
}

func (Vault) Backup

func (v Vault) Backup(after func() error) (func() error, error)

Backup takes a backup of the current file then executes the passed function. If function returns nil the backup file gets deleted

func (*Vault) Decrypt

func (v *Vault) Decrypt(key string, file []byte) (map[string]string, error)

Decrypt takes a key and a byte slice and decrypts the AES encrypted byte slice

func (*Vault) Encrypt

func (v *Vault) Encrypt(key string, vault []byte) ([]byte, error)

Encrypt takes a key and a byte slice and performs a AES encryption on the slcie

func (Vault) EvaluatePassword

func (v Vault) EvaluatePassword(password string) int

EvaluatePassword evaluates the strength of a password (range between 0-100)

func (Vault) GetPath

func (v Vault) GetPath() string

GetPath returns the path of the vault file

func (Vault) Init

func (v Vault) Init(clIO IO) error

Init initializes the vault file for the first time

func (Vault) IsInit

func (v Vault) IsInit() (bool, error)

IsInit controls if there is already a vault file created

func (Vault) Read

func (v Vault) Read() ([]byte, error)

Read reads the content from the vault file

func (Vault) Serialize

func (v Vault) Serialize(data map[string]string) ([]byte, error)

Serialize marshals the vault to a byte slice in order for it be written to a file

func (Vault) Write

func (v Vault) Write(data []byte) error

Write wrties the byte slice to in the vault file

Jump to

Keyboard shortcuts

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