storage

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

The Storage package is what handles all the DB operations, beginning by creating and migrating it to Insertions and Deletes.

Secrets.go is where the operations with the DB resides.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(encoded string, key []byte) (string, error)

Decrypt function receives a encrypted string and a master key, it will try to decrypt it, but if master key is not the same that was used on encryption, the decription will fail.

func Encrypt

func Encrypt(plain_text string, key []byte) (string, error)

Encrypt function accept plain_text and the master key hash, the later will be used as salt on the encryption, therefore the only key that can decrypt it is the one that encrypted on the first place.

func HashMasterKey

func HashMasterKey(mk string) []byte

HashMasterKey will hash the master key with sha256, it also add a salt to it.

Types

type DB

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

DB struct, only field is the connection with the actual DB.

func New

func New(path string) (*DB, error)

New function opens your DB connection and migrate if needed, it returns a initialized DB struct and a db method for migrating.

func (*DB) AddMasterKey

func (db *DB) AddMasterKey(key string) (int64, error)

AddMasterKey hash the argument passed and insert it into the 'config' table, returns it's id if no error.

func (*DB) Close

func (db *DB) Close() error

Close method is for closing the connection with the DB.

func (*DB) Delete

func (db *DB) Delete(id int) error

Delete method deletes a row based on the id of that is passed.

func (*DB) GetByName

func (db *DB) GetByName(name string) (*Secret, error)

GetByName method accepts a string and then query it against the DB, if the name is found the method returns a instantiated Secret of it.

func (*DB) GetHashedMasterKey

func (db *DB) GetHashedMasterKey() (*Secret, error)

GetHashedMasterKey method get's the master key.

func (*DB) Insert

func (db *DB) Insert(name, key string, mk []byte) (int64, error)

Insert method accepts a name, a key, and a hashed Master Key, returns a int64 that is the id of the new row and can return a error aswell, the method is to register a new secret within the DB.

func (*DB) List

func (db *DB) List() ([]Secret, error)

List method returns a slice of instantiate Secrets, it goes trough every secret on DB saving then.

func (*DB) MasterKeyExists

func (db *DB) MasterKeyExists() (bool, error)

MasterKeyExists verify if Master Key exists.

func (*DB) Update added in v1.0.0

func (db *DB) Update(id_to_change int, new_secret Secret, mk []byte) error

Update function method accepts a id of the row that will be changed, a Secret Struct with the new content and the master key in order to encrypt key if needed, return error if any.

type Secret

type Secret struct {
	ID         int
	Name       string
	Key        string
	Key_Length int
}

Secret struct, they are equal to what the rows of the DB save.

Jump to

Keyboard shortcuts

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