db

package
v0.0.0-...-c2ccda8 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDifferentMACSum = errors.New("mac sum don't match")

ErrDifferentMACSum is returned if the mac sum of the file doesn't match the computed mac sum. This means that the file has been corrupted, be very careful, someone might be trying to attack

View Source
var ErrInvalidPadding = errors.New("invalid padding")

ErrInvalidPadding is returned if the padding of the plaintext during decryption doesn't match the expected format. This isn't a good sign, and may reveal to be an attack (see padding oracle)

Functions

func JoinRootPath

func JoinRootPath(root, unsafePath string) string

JoinRootPath joins 2 paths, but guarantees that it will not go higher than root

Types

type Cryptor

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

Cryptor is a simple API which writes and read encrypted files using the password given to the constructor

func NewCryptor

func NewCryptor(encryptionKey, macKey []byte) (*Cryptor, error)

NewCryptor creates a new cryptor which saves/loads encrypted files using the mackey and the enckey

func (*Cryptor) Decrypt

func (c *Cryptor) Decrypt(content []byte) ([]byte, error)

func (*Cryptor) Encrypt

func (c *Cryptor) Encrypt(plaintext []byte) ([]byte, error)

func (*Cryptor) Load

func (c *Cryptor) Load(filename string) ([]byte, error)

Load opens <filename>, decrypts its content, and returns it

func (*Cryptor) Save

func (c *Cryptor) Save(filename string, plaintext []byte) error

Save encrypts plaintext and saves it to filename

type User

type User struct {
	// root is the user's own folder (see api.go)
	ID    int
	Email string
	// contains filtered or unexported fields
}

UserDB is the folder containing all the user's data. Everything in their is encrypted using his password

func NewUser

func NewUser(id int, email, root string) *User

func (*User) Load

func (u *User) Load(filename string) ([]byte, error)

func (*User) Login

func (u *User) Login(password []byte) error

Login can return keysmanager.ErrWrongPassword, keysmanager.ErrPrivCorrupted, ErrAlreadyLoaded (internal) or err

func (*User) Save

func (u *User) Save(filename string, plaintext []byte) error

func (*User) SignUp

func (u *User) SignUp(password []byte) error

Jump to

Keyboard shortcuts

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